diff --git a/src/main/java/reborn/backend/global/entity/PetColor.java b/src/main/java/reborn/backend/global/entity/PetColor.java index f497d4f..5803f0e 100644 --- a/src/main/java/reborn/backend/global/entity/PetColor.java +++ b/src/main/java/reborn/backend/global/entity/PetColor.java @@ -3,7 +3,7 @@ public enum PetColor { BLACK, BROWN, - YELLOW, + YELLOWDARK, GRAY, WHITE } diff --git a/src/main/java/reborn/backend/pet/dto/PetRequestDto.java b/src/main/java/reborn/backend/pet/dto/PetRequestDto.java index 8be2d5a..c02df6b 100644 --- a/src/main/java/reborn/backend/pet/dto/PetRequestDto.java +++ b/src/main/java/reborn/backend/pet/dto/PetRequestDto.java @@ -31,7 +31,7 @@ public static class PetReqDto { @Schema(description = "반료동물 종") private String detailPetType; - @Schema(description = "반려동물 색깔(BLACK, BROWN, LIGHTBROWN, GRAY, WHITE") + @Schema(description = "반려동물 색깔(BLACK, BROWN, YELLOWDARK, GRAY, WHITE") private String petColor; } } \ No newline at end of file diff --git a/src/main/java/reborn/backend/pet/dto/PetResponseDto.java b/src/main/java/reborn/backend/pet/dto/PetResponseDto.java index d0ff5d7..709c4d9 100644 --- a/src/main/java/reborn/backend/pet/dto/PetResponseDto.java +++ b/src/main/java/reborn/backend/pet/dto/PetResponseDto.java @@ -56,7 +56,7 @@ public static class DetailPetDto{ @Schema(description = "반료동물 종") private String detailPetType; - @Schema(description = "반려동물 색깔(BLACK, BROWN, YELLOW, GRAY, WHITE") + @Schema(description = "반려동물 색깔(BLACK, BROWN, YELLOWDARK, GRAY, WHITE") private String petColor; } diff --git a/src/main/java/reborn/backend/reborn_15/_2_remind/controller/RemindController.java b/src/main/java/reborn/backend/reborn_15/_2_remind/controller/RemindController.java index af13737..1dcad89 100644 --- a/src/main/java/reborn/backend/reborn_15/_2_remind/controller/RemindController.java +++ b/src/main/java/reborn/backend/reborn_15/_2_remind/controller/RemindController.java @@ -34,17 +34,17 @@ public class RemindController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2011", description = "충분한 대화 나누기 생성이 완료되었습니다.") }) @PostMapping("/create") - public ApiResponse create( + public ApiResponse create( @AuthenticationPrincipal CustomUserDetails customUserDetails ){ User user = userService.findUserByUserName(customUserDetails.getUsername()); Pet pet = petService.findById(user.getContentPetId()); - remindService.createRemind(pet); + Remind remind = remindService.createRemind(pet); petService.updateDate(user.getContentPetId()); - return ApiResponse.onSuccess(SuccessCode.REMIND_CREATED, true); + return ApiResponse.onSuccess(SuccessCode.REMIND_CREATED, remind.getDate()); } @Operation(summary = "특정 충분한 대화 나누기 조회 메서드", description = "특정 충분한 대화 나누기를 조회하는 메서드입니다.") @@ -65,12 +65,14 @@ public ApiResponse getDetailRemind( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2003", description = "답변 작성이 완료되었습니다.") }) - @PostMapping("/write/{id}") + @PostMapping("/write") public ApiResponse write( - @PathVariable(name = "id") Long id, + @AuthenticationPrincipal CustomUserDetails customUserDetails, @RequestBody RemindReqDto remindReqDto ){ - remindService.writeRemind(id, remindReqDto); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + remindService.writeRemind(pet.getRebornDate(), remindReqDto, pet); return ApiResponse.onSuccess(SuccessCode.REMIND_WRITE_COMPLETED, true); } @@ -79,11 +81,13 @@ public ApiResponse write( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2004", description = "쓰다듬기가 완료되었습니다.") }) - @PostMapping("/pat/{id}") + @PostMapping("/pat") public ApiResponse pat( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - remindService.patRemind(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + remindService.patRemind(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMIND_PAT_COMPLETED, true); } @@ -92,11 +96,13 @@ public ApiResponse pat( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2005", description = "밥주기가 완료되었습니다.") }) - @PostMapping("/feed/{id}") + @PostMapping("/feed") public ApiResponse feed( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - remindService.feedRemind(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + remindService.feedRemind(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMIND_FEED_COMPLETED, true); } @@ -105,11 +111,13 @@ public ApiResponse feed( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2006", description = "산책하기가 완료되었습니다.") }) - @PostMapping("/walk/{id}") + @PostMapping("/walk") public ApiResponse walk( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - remindService.walkRemind(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + remindService.walkRemind(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMIND_WALK_COMPLETED, true); } @@ -118,11 +126,13 @@ public ApiResponse walk( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2007", description = "간식주기가 완료되었습니다.") }) - @PostMapping("/snack/{id}") + @PostMapping("/snack") public ApiResponse snack( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - remindService.snackRemind(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + remindService.snackRemind(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMIND_SNACK_COMPLETED, true); } @@ -131,11 +141,13 @@ public ApiResponse snack( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2008", description = "쓰다듬기로 넘어가기가 완료되었습니다.") }) - @PostMapping("/intro/{id}") + @PostMapping("/intro") public ApiResponse intro( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - remindService.introRemind(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + remindService.introRemind(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMIND_INTRO_COMPLETED, true); } diff --git a/src/main/java/reborn/backend/reborn_15/_2_remind/repository/RemindRepository.java b/src/main/java/reborn/backend/reborn_15/_2_remind/repository/RemindRepository.java index eaf5f87..9ee423d 100644 --- a/src/main/java/reborn/backend/reborn_15/_2_remind/repository/RemindRepository.java +++ b/src/main/java/reborn/backend/reborn_15/_2_remind/repository/RemindRepository.java @@ -13,6 +13,8 @@ public interface RemindRepository extends JpaRepository, JpaSpecificationExecutor { Optional findTopByPetOrderByDateDesc(Pet pet); + Optional findByPetAndDate(Pet pet, Integer date); + List findAllByPetAndDateLessThanOrderByDateDesc(Pet pet, Integer date); } \ No newline at end of file diff --git a/src/main/java/reborn/backend/reborn_15/_2_remind/service/RemindService.java b/src/main/java/reborn/backend/reborn_15/_2_remind/service/RemindService.java index d5b028c..3e7bc3e 100644 --- a/src/main/java/reborn/backend/reborn_15/_2_remind/service/RemindService.java +++ b/src/main/java/reborn/backend/reborn_15/_2_remind/service/RemindService.java @@ -43,16 +43,16 @@ public List findAllByPetAndDateLessThanSortedByDate(Pet pet, Integer dat } @Transactional - public void introRemind(Long id) { - Remind remind = remindRepository.findById(id) + public void introRemind(Integer date, Pet pet) { + Remind remind = remindRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMIND_NOT_FOUND)); remind.getPet().setProgressState("PAT"); } @Transactional - public void patRemind(Long id) { - Remind remind = remindRepository.findById(id) + public void patRemind(Integer date, Pet pet) { + Remind remind = remindRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMIND_NOT_FOUND)); remind.setPat(true); @@ -63,8 +63,8 @@ public void patRemind(Long id) { } @Transactional - public void feedRemind(Long id) { - Remind remind = remindRepository.findById(id) + public void feedRemind(Integer date, Pet pet) { + Remind remind = remindRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMIND_NOT_FOUND)); remind.setFeed(true); @@ -75,8 +75,8 @@ public void feedRemind(Long id) { } @Transactional - public void walkRemind(Long id) { - Remind remind = remindRepository.findById(id) + public void walkRemind(Integer date, Pet pet) { + Remind remind = remindRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMIND_NOT_FOUND)); remind.setWalk(true); @@ -87,8 +87,8 @@ public void walkRemind(Long id) { } @Transactional - public void snackRemind(Long id) { - Remind remind = remindRepository.findById(id) + public void snackRemind(Integer date, Pet pet) { + Remind remind = remindRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMIND_NOT_FOUND)); remind.setSnack(true); @@ -99,15 +99,14 @@ public void snackRemind(Long id) { } @Transactional - public Remind writeRemind(Long id, RemindReqDto remindReqDto) { - Remind remind = remindRepository.findById(id) + public void writeRemind(Integer date, RemindReqDto remindReqDto, Pet pet) { + Remind remind = remindRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMIND_NOT_FOUND)); remind.setAnswer(remindReqDto.getAnswer()); remindRepository.save(remind); remind.getPet().setProgressState("FINISH"); - return remind; } @Transactional diff --git a/src/main/java/reborn/backend/reborn_15/_3_reveal/controller/RevealController.java b/src/main/java/reborn/backend/reborn_15/_3_reveal/controller/RevealController.java index 7b8b0ef..4c3f397 100644 --- a/src/main/java/reborn/backend/reborn_15/_3_reveal/controller/RevealController.java +++ b/src/main/java/reborn/backend/reborn_15/_3_reveal/controller/RevealController.java @@ -36,17 +36,17 @@ public class RevealController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2011", description = "나의 감정 들여다보기 생성이 완료되었습니다.") }) @PostMapping("/create") - public ApiResponse create( + public ApiResponse create( @AuthenticationPrincipal CustomUserDetails customUserDetails ){ User user = userService.findUserByUserName(customUserDetails.getUsername()); Pet pet = petService.findById(user.getContentPetId()); - revealService.createReveal(pet); + Reveal reveal = revealService.createReveal(pet); petService.updateDate(user.getContentPetId()); - return ApiResponse.onSuccess(SuccessCode.REVEAL_CREATED, true); + return ApiResponse.onSuccess(SuccessCode.REVEAL_CREATED, reveal.getDate()); } @Operation(summary = "특정 나의 감정 들여다보기 조회 메서드", description = "특정 나의 감정 들여다보기를 조회하는 메서드입니다.") @@ -67,14 +67,16 @@ public ApiResponse getDetailReveal( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2003", description = "일기 작성이 완료되었습니다.") }) - @PostMapping("/write/{id}") + @PostMapping("/write") public ApiResponse write( - @PathVariable(name = "id") Long id, + @AuthenticationPrincipal CustomUserDetails customUserDetails, @RequestBody RevealReqDto revealReqDto ){ - Reveal reveal = revealService.writeReveal(id, revealReqDto); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + revealService.writeReveal(pet.getRebornDate(), revealReqDto, pet); - double emotionPercentage = revealService.calculateEmotionPercentage(reveal.getId()); + double emotionPercentage = revealService.calculateEmotionPercentage(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REVEAL_WRITE_COMPLETED, emotionPercentage); } @@ -83,11 +85,13 @@ public ApiResponse write( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2004", description = "쓰다듬기가 완료되었습니다.") }) - @PostMapping("/pat/{id}") + @PostMapping("/pat") public ApiResponse pat( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - revealService.patReveal(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + revealService.patReveal(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REVEAL_PAT_COMPLETED, true); } @@ -96,11 +100,13 @@ public ApiResponse pat( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2005", description = "밥주기가 완료되었습니다.") }) - @PostMapping("/feed/{id}") + @PostMapping("/feed") public ApiResponse feed( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - revealService.feedReveal(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + revealService.feedReveal(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REVEAL_FEED_COMPLETED, true); } @@ -109,11 +115,13 @@ public ApiResponse feed( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2006", description = "산책하기가 완료되었습니다.") }) - @PostMapping("/walk/{id}") + @PostMapping("/walk") public ApiResponse walk( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - revealService.walkReveal(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + revealService.walkReveal(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REVEAL_WALK_COMPLETED, true); } @@ -122,11 +130,13 @@ public ApiResponse walk( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2007", description = "간식주기가 완료되었습니다.") }) - @PostMapping("/snack/{id}") + @PostMapping("/snack") public ApiResponse snack( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - revealService.snackReveal(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + revealService.snackReveal(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REVEAL_SNACK_COMPLETED, true); } @@ -135,11 +145,13 @@ public ApiResponse snack( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2008", description = "쓰다듬기로 넘어가기가 완료되었습니다.") }) - @PostMapping("/intro/{id}") + @PostMapping("/intro") public ApiResponse intro( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - revealService.introReveal(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + revealService.introReveal(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REVEAL_INTRO_COMPLETED, true); } diff --git a/src/main/java/reborn/backend/reborn_15/_3_reveal/repository/RevealRepository.java b/src/main/java/reborn/backend/reborn_15/_3_reveal/repository/RevealRepository.java index 7706e0c..15c48e0 100644 --- a/src/main/java/reborn/backend/reborn_15/_3_reveal/repository/RevealRepository.java +++ b/src/main/java/reborn/backend/reborn_15/_3_reveal/repository/RevealRepository.java @@ -15,5 +15,7 @@ public interface RevealRepository extends JpaRepository, JpaSpecif List findAllByDate(Integer date); + Optional findByPetAndDate(Pet pet, Integer date); + List findAllByPetAndDateLessThanOrderByDateDesc(Pet pet, Integer date); } diff --git a/src/main/java/reborn/backend/reborn_15/_3_reveal/service/RevealService.java b/src/main/java/reborn/backend/reborn_15/_3_reveal/service/RevealService.java index 23e151e..fe4ed17 100644 --- a/src/main/java/reborn/backend/reborn_15/_3_reveal/service/RevealService.java +++ b/src/main/java/reborn/backend/reborn_15/_3_reveal/service/RevealService.java @@ -46,16 +46,16 @@ public List findAllByPetAndDateLessThanSortedByDate(Pet pet, Integer dat } @Transactional - public void introReveal(Long id) { - Reveal reveal = revealRepository.findById(id) + public void introReveal(Integer date, Pet pet) { + Reveal reveal = revealRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REVEAL_NOT_FOUND)); reveal.getPet().setProgressState("PAT"); } @Transactional - public void patReveal(Long id) { - Reveal reveal = revealRepository.findById(id) + public void patReveal(Integer date, Pet pet) { + Reveal reveal = revealRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REVEAL_NOT_FOUND)); reveal.setPat(true); @@ -66,8 +66,8 @@ public void patReveal(Long id) { } @Transactional - public void feedReveal(Long id) { - Reveal reveal = revealRepository.findById(id) + public void feedReveal(Integer date, Pet pet) { + Reveal reveal = revealRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REVEAL_NOT_FOUND)); reveal.setFeed(true); @@ -78,8 +78,8 @@ public void feedReveal(Long id) { } @Transactional - public void walkReveal(Long id) { - Reveal reveal = revealRepository.findById(id) + public void walkReveal(Integer date, Pet pet) { + Reveal reveal = revealRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REVEAL_NOT_FOUND)); reveal.setWalk(true); @@ -90,8 +90,8 @@ public void walkReveal(Long id) { } @Transactional - public void snackReveal(Long id) { - Reveal reveal = revealRepository.findById(id) + public void snackReveal(Integer date, Pet pet) { + Reveal reveal = revealRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REVEAL_NOT_FOUND)); reveal.setSnack(true); @@ -102,8 +102,8 @@ public void snackReveal(Long id) { } @Transactional - public Reveal writeReveal(Long id, RevealReqDto revealReqDto) { - Reveal reveal = revealRepository.findById(id) + public Reveal writeReveal(Integer date, RevealReqDto revealReqDto, Pet pet) { + Reveal reveal = revealRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REVEAL_NOT_FOUND)); reveal.setDiaryContent(revealReqDto.getDiaryContent()); @@ -124,8 +124,8 @@ public Reveal findById(Long id) { } @Transactional - public Double calculateEmotionPercentage(Long id) { - Reveal reveal = revealRepository.findById(id) + public Double calculateEmotionPercentage(Integer date, Pet pet) { + Reveal reveal = revealRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REVEAL_NOT_FOUND)); List allRevealsByDate = revealRepository.findAllByDate(reveal.getDate()); diff --git a/src/main/java/reborn/backend/reborn_15/_4_remember/controller/RememberController.java b/src/main/java/reborn/backend/reborn_15/_4_remember/controller/RememberController.java index b6f3700..d6e38ae 100644 --- a/src/main/java/reborn/backend/reborn_15/_4_remember/controller/RememberController.java +++ b/src/main/java/reborn/backend/reborn_15/_4_remember/controller/RememberController.java @@ -38,17 +38,17 @@ public class RememberController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2011", description = "건강한 작별 준비하기 생성이 완료되었습니다.") }) @PostMapping("/create") - public ApiResponse create( + public ApiResponse create( @AuthenticationPrincipal CustomUserDetails customUserDetails ){ User user = userService.findUserByUserName(customUserDetails.getUsername()); Pet pet = petService.findById(user.getContentPetId()); - rememberService.createRemember(pet); + Remember remember = rememberService.createRemember(pet); petService.updateDate(user.getContentPetId()); - return ApiResponse.onSuccess(SuccessCode.REMEMBER_CREATED, true); + return ApiResponse.onSuccess(SuccessCode.REMEMBER_CREATED, remember.getDate()); } @Operation(summary = "특정 건강한 작별 준비하기 조회 메서드", description = "특정 건강한 작별 준비하기를 조회하는 메서드입니다.") @@ -69,14 +69,16 @@ public ApiResponse getDetailRemember( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2003", description = "그림일기 작성이 완료되었습니다.") }) - @PostMapping(value = "/write/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @PostMapping(value = "/write", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ApiResponse write( + @AuthenticationPrincipal CustomUserDetails customUserDetails, @RequestPart(value = "remember") MultipartFile file, - @RequestPart("data") SimpleRememberReqDto simpleRememberReqDto, - @PathVariable(name = "id") Long id + @RequestPart("data") SimpleRememberReqDto simpleRememberReqDto ) throws IOException { + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); String dirName = "remember/"; - rememberService.writeRemember(id, simpleRememberReqDto, dirName, file); + rememberService.writeRemember(pet.getRebornDate(), simpleRememberReqDto, dirName, file, pet); return ApiResponse.onSuccess(SuccessCode.REMEMBER_WRITE_COMPLETED, true); } @@ -85,11 +87,13 @@ public ApiResponse write( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2004", description = "쓰다듬기가 완료되었습니다.") }) - @PostMapping("/pat/{id}") + @PostMapping("/pat") public ApiResponse pat( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rememberService.patRemember(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rememberService.patRemember(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMEMBER_PAT_COMPLETED, true); } @@ -98,11 +102,13 @@ public ApiResponse pat( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2005", description = "밥주기가 완료되었습니다.") }) - @PostMapping("/feed/{id}") + @PostMapping("/feed") public ApiResponse feed( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rememberService.feedRemember(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rememberService.feedRemember(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMEMBER_FEED_COMPLETED, true); } @@ -111,11 +117,13 @@ public ApiResponse feed( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2006", description = "산책하기가 완료되었습니다.") }) - @PostMapping("/walk/{id}") + @PostMapping("/walk") public ApiResponse walk( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rememberService.walkRemember(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rememberService.walkRemember(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMEMBER_WALK_COMPLETED, true); } @@ -124,11 +132,13 @@ public ApiResponse walk( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2007", description = "간식주기가 완료되었습니다.") }) - @PostMapping("/snack/{id}") + @PostMapping("/snack") public ApiResponse snack( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rememberService.snackRemember(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rememberService.snackRemember(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMEMBER_SNACK_COMPLETED, true); } @@ -137,11 +147,13 @@ public ApiResponse snack( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2008", description = "정리1가 완료되었습니다.") }) - @PostMapping("/clean/{id}") + @PostMapping("/clean") public ApiResponse clean( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rememberService.clean_Remember(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rememberService.clean_Remember(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMEMBER_CLEAN_COMPLETED, true); } @@ -150,11 +162,13 @@ public ApiResponse clean( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMEMBER_2009", description = "쓰다듬기로 넘어가기가 완료되었습니다.") }) - @PostMapping("/intro/{id}") + @PostMapping("/intro") public ApiResponse intro( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rememberService.introRemember(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rememberService.introRemember(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REMEMBER_INTRO_COMPLETED, true); } diff --git a/src/main/java/reborn/backend/reborn_15/_4_remember/repository/RememberRepository.java b/src/main/java/reborn/backend/reborn_15/_4_remember/repository/RememberRepository.java index 58c5de7..cb3957d 100644 --- a/src/main/java/reborn/backend/reborn_15/_4_remember/repository/RememberRepository.java +++ b/src/main/java/reborn/backend/reborn_15/_4_remember/repository/RememberRepository.java @@ -13,6 +13,8 @@ public interface RememberRepository extends JpaRepository, JpaSpecificationExecutor { Optional findTopByPetOrderByDateDesc(Pet pet); + Optional findByPetAndDate(Pet pet, Integer date); + List findAllByPetAndDateLessThanOrderByDateDesc(Pet pet, Integer date); } diff --git a/src/main/java/reborn/backend/reborn_15/_4_remember/service/RememberService.java b/src/main/java/reborn/backend/reborn_15/_4_remember/service/RememberService.java index 33dff03..212f874 100644 --- a/src/main/java/reborn/backend/reborn_15/_4_remember/service/RememberService.java +++ b/src/main/java/reborn/backend/reborn_15/_4_remember/service/RememberService.java @@ -44,8 +44,8 @@ public Remember createRemember(Pet pet) { @Transactional - public void introRemember(Long id) { - Remember remember = rememberRepository.findById(id) + public void introRemember(Integer date, Pet pet) { + Remember remember = rememberRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMEMBER_NOT_FOUND)); remember.getPet().setProgressState("PAT"); @@ -58,8 +58,8 @@ public List findAllByPetAndDateLessThanSortedByDate(Pet pet, Integer d } @Transactional - public void patRemember(Long id) { - Remember remember = rememberRepository.findById(id) + public void patRemember(Integer date, Pet pet) { + Remember remember = rememberRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMEMBER_NOT_FOUND)); remember.setPat(true); @@ -70,8 +70,8 @@ public void patRemember(Long id) { } @Transactional - public void feedRemember(Long id) { - Remember remember = rememberRepository.findById(id) + public void feedRemember(Integer date, Pet pet) { + Remember remember = rememberRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMEMBER_NOT_FOUND)); remember.setFeed(true); @@ -82,8 +82,8 @@ public void feedRemember(Long id) { } @Transactional - public void walkRemember(Long id) { - Remember remember = rememberRepository.findById(id) + public void walkRemember(Integer date, Pet pet) { + Remember remember = rememberRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMEMBER_NOT_FOUND)); remember.setWalk(true); @@ -94,8 +94,8 @@ public void walkRemember(Long id) { } @Transactional - public void snackRemember(Long id) { - Remember remember = rememberRepository.findById(id) + public void snackRemember(Integer date, Pet pet) { + Remember remember = rememberRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMEMBER_NOT_FOUND)); remember.setSnack(true); @@ -106,8 +106,8 @@ public void snackRemember(Long id) { } @Transactional - public void clean_Remember(Long id) { - Remember remember = rememberRepository.findById(id) + public void clean_Remember(Integer date, Pet pet) { + Remember remember = rememberRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMEMBER_NOT_FOUND)); remember.setClean(true); @@ -118,8 +118,8 @@ public void clean_Remember(Long id) { } @Transactional - public void writeRemember(Long id, SimpleRememberReqDto simpleRememberReqDto, String dirName, MultipartFile file) throws IOException { - Remember remember = rememberRepository.findById(id) + public void writeRemember(Integer date, SimpleRememberReqDto simpleRememberReqDto, String dirName, MultipartFile file, Pet pet) throws IOException { + Remember remember = rememberRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REMEMBER_NOT_FOUND)); String uploadFileUrl = null; diff --git a/src/main/java/reborn/backend/reborn_15/_5_reborn/controller/RebornController.java b/src/main/java/reborn/backend/reborn_15/_5_reborn/controller/RebornController.java index 14b915d..09fea4d 100644 --- a/src/main/java/reborn/backend/reborn_15/_5_reborn/controller/RebornController.java +++ b/src/main/java/reborn/backend/reborn_15/_5_reborn/controller/RebornController.java @@ -35,17 +35,17 @@ public class RebornController { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2011", description = "건강한 작별하기 생성이 완료되었습니다.") }) @PostMapping("/create") - public ApiResponse create( + public ApiResponse create( @AuthenticationPrincipal CustomUserDetails customUserDetails ){ User user = userService.findUserByUserName(customUserDetails.getUsername()); Pet pet = petService.findById(user.getContentPetId()); - rebornService.createReborn(pet); + Reborn reborn = rebornService.createReborn(pet); petService.updateDate(user.getContentPetId()); - return ApiResponse.onSuccess(SuccessCode.REBORN_CREATED, true); + return ApiResponse.onSuccess(SuccessCode.REBORN_CREATED, reborn.getDate()); } @Operation(summary = "특정 건강한 작별하기 조회 메서드", description = "특정 건강한 작별하기를 조회하는 메서드입니다.") @@ -66,12 +66,14 @@ public ApiResponse getDetailReBORN( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2003", description = "작별인사 작성이 완료되었습니다.") }) - @PostMapping("/write/{id}") + @PostMapping("/write") public ApiResponse write( - @PathVariable(name = "id") Long id, + @AuthenticationPrincipal CustomUserDetails customUserDetails, @RequestBody ContentRebornReqDto rebornReqDto ){ - rebornService.writeReborn(id, rebornReqDto); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rebornService.writeReborn(pet.getRebornDate(), rebornReqDto, pet); return ApiResponse.onSuccess(SuccessCode.REBORN_WRITE_COMPLETED, true); } @@ -80,12 +82,14 @@ public ApiResponse write( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2009", description = "리본 선택이 완료되었습니다.") }) - @PostMapping("/set/{id}") + @PostMapping("/set") public ApiResponse setReborn( - @PathVariable(name = "id") Long id, + @AuthenticationPrincipal CustomUserDetails customUserDetails, @RequestBody RebornRebornReqDto rebornReqDto ){ - rebornService.setReborn(id, rebornReqDto); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rebornService.setReborn(pet.getRebornDate(), rebornReqDto, pet); return ApiResponse.onSuccess(SuccessCode.REBORN_SET_REBORN_COMPLETED, true); } @@ -94,11 +98,14 @@ public ApiResponse setReborn( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2004", description = "쓰다듬기가 완료되었습니다.") }) - @PostMapping("/pat/{id}") + @PostMapping("/pat") public ApiResponse pat( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rebornService.patReborn(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rebornService.patReborn(pet.getRebornDate(), pet); + return ApiResponse.onSuccess(SuccessCode.REBORN_PAT_COMPLETED, true); } @@ -106,11 +113,13 @@ public ApiResponse pat( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2005", description = "밥주기가 완료되었습니다.") }) - @PostMapping("/feed/{id}") + @PostMapping("/feed") public ApiResponse feed( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rebornService.feedReborn(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rebornService.feedReborn(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REBORN_FEED_COMPLETED, true); } @@ -119,11 +128,14 @@ public ApiResponse feed( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2006", description = "씻겨주기가 완료되었습니다.") }) - @PostMapping("/wash/{id}") + @PostMapping("/wash") public ApiResponse wash( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rebornService.washReborn(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rebornService.washReborn(pet.getRebornDate(), pet); + return ApiResponse.onSuccess(SuccessCode.REBORN_WASH_COMPLETED, true); } @@ -131,11 +143,14 @@ public ApiResponse wash( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2007", description = "옷 입혀주기가 완료되었습니다.") }) - @PostMapping("/clothe/{id}") + @PostMapping("/clothe") public ApiResponse clothe( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rebornService.clotheReborn(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rebornService.clotheReborn(pet.getRebornDate(), pet); + return ApiResponse.onSuccess(SuccessCode.REBORN_CLOTHE_COMPLETED, true); } @@ -143,7 +158,7 @@ public ApiResponse clothe( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2008", description = "15일 콘텐츠가 완료되었습니다.") }) - @PostMapping("finish/{id}") + @PostMapping("finish") public ApiResponse finish( @AuthenticationPrincipal CustomUserDetails customUserDetails ){ @@ -161,11 +176,13 @@ public ApiResponse finish( @ApiResponses(value = { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REBORN_2010", description = "쓰다듬기로 넘어가기가 완료되었습니다.") }) - @PostMapping("/intro/{id}") + @PostMapping("/intro") public ApiResponse intro( - @PathVariable(name = "id") Long id + @AuthenticationPrincipal CustomUserDetails customUserDetails ){ - rebornService.introReborn(id); + User user = userService.findUserByUserName(customUserDetails.getUsername()); + Pet pet = petService.findById(user.getContentPetId()); + rebornService.introReborn(pet.getRebornDate(), pet); return ApiResponse.onSuccess(SuccessCode.REBORN_INTRO_COMPLETED, true); } diff --git a/src/main/java/reborn/backend/reborn_15/_5_reborn/repository/RebornRepository.java b/src/main/java/reborn/backend/reborn_15/_5_reborn/repository/RebornRepository.java index b72441f..1f5a28d 100644 --- a/src/main/java/reborn/backend/reborn_15/_5_reborn/repository/RebornRepository.java +++ b/src/main/java/reborn/backend/reborn_15/_5_reborn/repository/RebornRepository.java @@ -13,5 +13,7 @@ public interface RebornRepository extends JpaRepository, JpaSpecificationExecutor { Optional findTopByPetOrderByDateDesc(Pet pet); + Optional findByPetAndDate(Pet pet, Integer date); + List findAllByPetAndDateLessThanOrderByDateDesc(Pet pet, Integer date); } diff --git a/src/main/java/reborn/backend/reborn_15/_5_reborn/service/RebornService.java b/src/main/java/reborn/backend/reborn_15/_5_reborn/service/RebornService.java index 464ae03..0950e18 100644 --- a/src/main/java/reborn/backend/reborn_15/_5_reborn/service/RebornService.java +++ b/src/main/java/reborn/backend/reborn_15/_5_reborn/service/RebornService.java @@ -40,21 +40,21 @@ public Reborn createReborn(Pet pet) { } @Transactional - public void introReborn(Long id) { - Reborn reborn = rebornRepository.findById(id) - .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); - - reborn.getPet().setProgressState("PAT"); + public List findAllByPetAndDateLessThanSortedByDate(Pet pet, Integer date) { + return rebornRepository.findAllByPetAndDateLessThanOrderByDateDesc(pet, date); } @Transactional - public List findAllByPetAndDateLessThanSortedByDate(Pet pet, Integer date) { - return rebornRepository.findAllByPetAndDateLessThanOrderByDateDesc(pet, date); + public void introReborn(Integer date, Pet pet) { + Reborn reborn = rebornRepository.findByPetAndDate(pet, date) + .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); + + reborn.getPet().setProgressState("PAT"); } @Transactional - public void patReborn(Long id) { - Reborn reborn = rebornRepository.findById(id) + public void patReborn(Integer date, Pet pet) { + Reborn reborn = rebornRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); reborn.setPat(true); @@ -65,8 +65,8 @@ public void patReborn(Long id) { } @Transactional - public void feedReborn(Long id) { - Reborn reborn = rebornRepository.findById(id) + public void feedReborn(Integer date, Pet pet) { + Reborn reborn = rebornRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); reborn.setFeed(true); @@ -77,8 +77,8 @@ public void feedReborn(Long id) { } @Transactional - public void washReborn(Long id) { - Reborn reborn = rebornRepository.findById(id) + public void washReborn(Integer date, Pet pet) { + Reborn reborn = rebornRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); reborn.setWash(true); @@ -89,8 +89,8 @@ public void washReborn(Long id) { } @Transactional - public void clotheReborn(Long id) { - Reborn reborn = rebornRepository.findById(id) + public void clotheReborn(Integer date, Pet pet) { + Reborn reborn = rebornRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); reborn.setClothe(true); @@ -101,8 +101,8 @@ public void clotheReborn(Long id) { } @Transactional - public void writeReborn(Long id, ContentRebornReqDto rebornReqDto) { - Reborn reborn = rebornRepository.findById(id) + public void writeReborn(Integer date, ContentRebornReqDto rebornReqDto, Pet pet) { + Reborn reborn = rebornRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); reborn.setRebornContent(rebornReqDto.getRebornContent()); @@ -113,8 +113,8 @@ public void writeReborn(Long id, ContentRebornReqDto rebornReqDto) { } @Transactional - public void setReborn(Long id, RebornRebornReqDto rebornReqDto) { - Reborn reborn = rebornRepository.findById(id) + public void setReborn(Integer date, RebornRebornReqDto rebornReqDto, Pet pet) { + Reborn reborn = rebornRepository.findByPetAndDate(pet, date) .orElseThrow(() -> GeneralException.of(ErrorCode.REBORN_NOT_FOUND)); reborn.setRebornType(RebornType.valueOf(rebornReqDto.getRebornType()));