From b61d555183c7ef830a53c780a91b9a581cbcda8f Mon Sep 17 00:00:00 2001 From: do-dop Date: Fri, 5 Jul 2024 04:57:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8A=A4=ED=8C=9F=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 스팟 올린 유저 프로필, 좋아요, 방문자 수 #35 --- .../snapspot/spot/controller/SpotController.java | 11 +++++++---- .../snapspot/spot/repository/SpotRepository.java | 5 ++++- .../hackaton/snapspot/spot/service/SpotService.java | 7 +++++++ 3 files changed, 18 insertions(+), 5 deletions(-) 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 b0f394f..6b01243 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 @@ -1,15 +1,13 @@ package com.umc.hackaton.snapspot.spot.controller; import com.umc.hackaton.snapspot.spot.dto.SpotRequestDto; +import com.umc.hackaton.snapspot.spot.entity.Spot; import com.umc.hackaton.snapspot.spot.service.SpotService; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RequiredArgsConstructor @RestController @@ -28,4 +26,9 @@ public ResponseEntity upload(@RequestBody SpotRequestDto dto){ return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("스팟 업로드에 실패하였습니다."); } } + + @GetMapping("/list/{spotId}") + public Spot getSpotById(@PathVariable Long spotId) { + return spotService.getSpotById(spotId); + } } 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 0079df6..623ed74 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 @@ -2,8 +2,11 @@ import com.umc.hackaton.snapspot.spot.entity.Spot; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; -import java.util.Optional; +import java.util.List; public interface SpotRepository extends JpaRepository { + } 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 dc87610..0589dc8 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 @@ -33,4 +33,11 @@ public void upload(SpotRequestDto dto) { spotRepository.save(spotDto.toEntity()); } + + @Transactional + public Spot getSpotById(Long spotId) { + // spotId를 사용하여 Repository를 통해 Spot을 가져옴 + return spotRepository.findById(spotId) + .orElseThrow(() -> new RuntimeException("Spot not found with id: " + spotId)); + } }