Skip to content

Commit

Permalink
feat: 스팟 상세 조회
Browse files Browse the repository at this point in the history
스팟 올린 유저 프로필, 좋아요, 방문자 수

#35
  • Loading branch information
do-dop committed Jul 4, 2024
1 parent d0bbd20 commit b61d555
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Spot, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit b61d555

Please sign in to comment.