Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#84] 15일 컨텐츠 컨트롤러 로직 변경 #91

Merged
merged 12 commits into from
May 9, 2024
Merged
2 changes: 1 addition & 1 deletion src/main/java/reborn/backend/global/entity/PetColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum PetColor {
BLACK,
BROWN,
YELLOW,
YELLOWDARK,
GRAY,
WHITE
}
2 changes: 1 addition & 1 deletion src/main/java/reborn/backend/pet/dto/PetRequestDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/java/reborn/backend/pet/dto/PetResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public class RemindController {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2011", description = "충분한 대화 나누기 생성이 완료되었습니다.")
})
@PostMapping("/create")
public ApiResponse<Boolean> create(
public ApiResponse<Integer> 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 = "특정 충분한 대화 나누기를 조회하는 메서드입니다.")
Expand All @@ -65,12 +65,14 @@ public ApiResponse<DetailRemindDto> getDetailRemind(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2003", description = "답변 작성이 완료되었습니다.")
})
@PostMapping("/write/{id}")
@PostMapping("/write")
public ApiResponse<Boolean> 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);
}
Expand All @@ -79,11 +81,13 @@ public ApiResponse<Boolean> write(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2004", description = "쓰다듬기가 완료되었습니다.")
})
@PostMapping("/pat/{id}")
@PostMapping("/pat")
public ApiResponse<Boolean> 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);
}
Expand All @@ -92,11 +96,13 @@ public ApiResponse<Boolean> pat(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2005", description = "밥주기가 완료되었습니다.")
})
@PostMapping("/feed/{id}")
@PostMapping("/feed")
public ApiResponse<Boolean> 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);
}
Expand All @@ -105,11 +111,13 @@ public ApiResponse<Boolean> feed(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2006", description = "산책하기가 완료되었습니다.")
})
@PostMapping("/walk/{id}")
@PostMapping("/walk")
public ApiResponse<Boolean> 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);
}
Expand All @@ -118,11 +126,13 @@ public ApiResponse<Boolean> walk(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2007", description = "간식주기가 완료되었습니다.")
})
@PostMapping("/snack/{id}")
@PostMapping("/snack")
public ApiResponse<Boolean> 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);
}
Expand All @@ -131,11 +141,13 @@ public ApiResponse<Boolean> snack(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REMIND_2008", description = "쓰다듬기로 넘어가기가 완료되었습니다.")
})
@PostMapping("/intro/{id}")
@PostMapping("/intro")
public ApiResponse<Boolean> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
public interface RemindRepository extends JpaRepository<Remind, Long>, JpaSpecificationExecutor<Remind> {
Optional<Remind> findTopByPetOrderByDateDesc(Pet pet);

Optional<Remind> findByPetAndDate(Pet pet, Integer date);

List<Remind> findAllByPetAndDateLessThanOrderByDateDesc(Pet pet, Integer date);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public List<Remind> 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public class RevealController {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2011", description = "나의 감정 들여다보기 생성이 완료되었습니다.")
})
@PostMapping("/create")
public ApiResponse<Boolean> create(
public ApiResponse<Integer> 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 = "특정 나의 감정 들여다보기를 조회하는 메서드입니다.")
Expand All @@ -67,14 +67,16 @@ public ApiResponse<DetailRevealDto> getDetailReveal(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2003", description = "일기 작성이 완료되었습니다.")
})
@PostMapping("/write/{id}")
@PostMapping("/write")
public ApiResponse<Double> 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);
}
Expand All @@ -83,11 +85,13 @@ public ApiResponse<Double> write(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2004", description = "쓰다듬기가 완료되었습니다.")
})
@PostMapping("/pat/{id}")
@PostMapping("/pat")
public ApiResponse<Boolean> 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);
}
Expand All @@ -96,11 +100,13 @@ public ApiResponse<Boolean> pat(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2005", description = "밥주기가 완료되었습니다.")
})
@PostMapping("/feed/{id}")
@PostMapping("/feed")
public ApiResponse<Boolean> 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);
}
Expand All @@ -109,11 +115,13 @@ public ApiResponse<Boolean> feed(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2006", description = "산책하기가 완료되었습니다.")
})
@PostMapping("/walk/{id}")
@PostMapping("/walk")
public ApiResponse<Boolean> 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);
}
Expand All @@ -122,11 +130,13 @@ public ApiResponse<Boolean> walk(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2007", description = "간식주기가 완료되었습니다.")
})
@PostMapping("/snack/{id}")
@PostMapping("/snack")
public ApiResponse<Boolean> 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);
}
Expand All @@ -135,11 +145,13 @@ public ApiResponse<Boolean> snack(
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "REVEAL_2008", description = "쓰다듬기로 넘어가기가 완료되었습니다.")
})
@PostMapping("/intro/{id}")
@PostMapping("/intro")
public ApiResponse<Boolean> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public interface RevealRepository extends JpaRepository<Reveal, Long>, JpaSpecif

List<Reveal> findAllByDate(Integer date);

Optional<Reveal> findByPetAndDate(Pet pet, Integer date);

List<Reveal> findAllByPetAndDateLessThanOrderByDateDesc(Pet pet, Integer date);
}
Loading
Loading