Skip to content

Commit

Permalink
펫 입양완료 API 추가
Browse files Browse the repository at this point in the history
펫 입양완료 API 추가
  • Loading branch information
xGreenNarae authored Oct 11, 2023
2 parents 479994c + 123afc3 commit e23da6b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,14 @@ public Response<PetDto> getPetDetail(@PathVariable final int petId) {
return Response.success(petReadService.getPetDetail(petId));
}

// Pet 입양 완료 상태 등록
@PostMapping("/adoption/{petId}")
@Authorized(AccountRole.SHELTER)
public Response<Void> updatePetAdopted(final Account account,
@PathVariable final int petId) {
petWriteService.updatePetAdopted(account, petId);
return Response.success();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum AdoptionStatus {
YES,
NO
NO,
UNABLE
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public void updateVideo(final String videoUrl) {
this.profileShortFormUrl = videoUrl;
}

public void setAdopted() {
this.adoptionStatus = AdoptionStatus.YES;
this.protectionExpirationDate = null;
}

public void updateInfo(final PetUpdateRequestDto petUpdateRequestDto) {
this.name = petUpdateRequestDto.name();
this.birthDate = PetAgeToBirthDateConverter.ageToBirthDate(petUpdateRequestDto.age());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public UpdatePetSuccessDto updatePet(final Account account,
return new UpdatePetSuccessDto(updatePet.getId());
}

public void updatePetAdopted(final Account account,
final int petId) {
final Pet pet = petRepository.findById(petId)
.orElseThrow(() -> new NotFound404("등록되지 않은 펫입니다."));

petValidator.validatePetUpdateAuthority(account, pet);

// 입양상태를 YES로 변경하고, 보호 만료일을 null로 바꾼다.
pet.setAdopted(); // TODO: 더 이상 보호소와 관련이 없어서.. 연결된 보호소 정보를 제거할 필요 ?
}

// 이미지, 비디오 파일 수정 요청 시 기존 파일 삭제 후 업데이트
private void updateFile(final Pet updatePet, final MultipartFile image,
final MultipartFile video) {
Expand All @@ -96,5 +107,4 @@ private void updateFile(final Pet updatePet, final MultipartFile image,
}



}

0 comments on commit e23da6b

Please sign in to comment.