Skip to content

Commit

Permalink
Merge pull request #38 from UMC-HACKATHON-SnapSpot/feat/#35
Browse files Browse the repository at this point in the history
feat: 스팟 상세 조회
  • Loading branch information
do-dop authored Jul 4, 2024
2 parents 00cddd8 + 76a87ab commit 81a0c9a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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("스팟 업로드 성공.");
Expand All @@ -31,14 +29,20 @@ 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
) {
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("스팟 조회에 실패하였습니다.");
}
Expand All @@ -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,
Expand All @@ -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("스팟 수정에 실패하였습니다.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface SpotRepository extends JpaRepository<Spot, Long> {
List<Spot> findAllByUser(User user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 81a0c9a

Please sign in to comment.