diff --git a/src/main/java/com/umc/hackaton/snapspot/savespot/service/UserFolderService.java b/src/main/java/com/umc/hackaton/snapspot/savespot/service/UserFolderService.java index 1ea3f2b..2fd838b 100644 --- a/src/main/java/com/umc/hackaton/snapspot/savespot/service/UserFolderService.java +++ b/src/main/java/com/umc/hackaton/snapspot/savespot/service/UserFolderService.java @@ -1,6 +1,5 @@ package com.umc.hackaton.snapspot.savespot.service; -import com.umc.hackaton.snapspot.savespot.dto.SpotSaveResponseDto; import com.umc.hackaton.snapspot.savespot.dto.UserFolderRequestDto; import com.umc.hackaton.snapspot.savespot.entity.SpotSave; import com.umc.hackaton.snapspot.savespot.entity.UserFolder; diff --git a/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java b/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java index 249985c..5dce3d8 100644 --- a/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java +++ b/src/main/java/com/umc/hackaton/snapspot/spot/controller/SpotController.java @@ -5,12 +5,10 @@ import com.umc.hackaton.snapspot.spot.service.SpotService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; @RequiredArgsConstructor @RestController @@ -22,7 +20,7 @@ public class SpotController { private final SpotService spotService; @PostMapping - public ResponseEntity upload(@RequestBody SpotRequestDto dto){ + public ResponseEntity upload(@RequestBody SpotRequestDto dto) { try { spotService.upload(dto); return ResponseEntity.ok().body("스팟 업로드 성공."); @@ -31,6 +29,12 @@ public ResponseEntity upload(@RequestBody SpotRequestDto dto){ } } + @GetMapping("/list/{spotId}") + public Spot getSpotById(@PathVariable Long spotId) { + return spotService.getSpotById(spotId); + + } + @GetMapping("/{spotId}") public ResponseEntity showSpot( @PathVariable("spotId") Long spotId @@ -38,7 +42,7 @@ public ResponseEntity showSpot( try { Spot spot = spotService.getSpot(spotId); return ResponseEntity.ok().body(spot); - } catch (Exception e){ + } catch (Exception e) { log.info("스팟 조회에 실패하였습니다.", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("스팟 조회에 실패하였습니다."); } @@ -51,13 +55,12 @@ public ResponseEntity deleteSpot( try { spotService.deleteSpot(spotId); return ResponseEntity.ok().body("success"); - } catch (Exception e){ + } catch (Exception e) { log.info("스팟 삭제에 실패하였습니다.", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("스팟 삭제에 실패하였습니다."); } } - @PatchMapping("/{spotId}") public ResponseEntity patchSpot( @PathVariable("spotId") Long spotId, @@ -66,9 +69,10 @@ public ResponseEntity patchSpot( try { Spot spot = spotService.updateSpot(spotId, dto); return ResponseEntity.ok().body(spot); - } catch (Exception e){ + } catch (Exception e) { log.info("스팟 수정에 실패하였습니다.", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("스팟 수정에 실패하였습니다."); } } + } diff --git a/src/main/java/com/umc/hackaton/snapspot/spot/repository/SpotRepository.java b/src/main/java/com/umc/hackaton/snapspot/spot/repository/SpotRepository.java index 9104f7b..19331fb 100644 --- a/src/main/java/com/umc/hackaton/snapspot/spot/repository/SpotRepository.java +++ b/src/main/java/com/umc/hackaton/snapspot/spot/repository/SpotRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; -import java.util.Optional; public interface SpotRepository extends JpaRepository { List findAllByUser(User user); diff --git a/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java b/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java index dcd5376..bbe8098 100644 --- a/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java +++ b/src/main/java/com/umc/hackaton/snapspot/spot/service/SpotService.java @@ -7,13 +7,11 @@ import com.umc.hackaton.snapspot.spot.dto.SpotDto; import com.umc.hackaton.snapspot.spot.dto.SpotRequestDto; import com.umc.hackaton.snapspot.spot.entity.Spot; -import com.umc.hackaton.snapspot.user.entity.User; import com.umc.hackaton.snapspot.spot.repository.SpotRepository; +import com.umc.hackaton.snapspot.user.entity.User; import com.umc.hackaton.snapspot.user.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -60,6 +58,13 @@ public void upload(SpotRequestDto dto) { } + @Transactional + public Spot getSpotById(Long spotId) { + // spotId를 사용하여 Repository를 통해 Spot을 가져옴 + return spotRepository.findById(spotId) + .orElseThrow(() -> new RuntimeException("Spot not found with id: " + spotId)); + } + public Spot getSpot(Long spotId) { return spotRepository.findById(spotId).orElse(null); }