Skip to content

Commit

Permalink
feat: 반려견 사진 등록시 기본 이미지 제공 기능 (#280)
Browse files Browse the repository at this point in the history
* feat: 기본이미지 등록 추가

* feat: DTO 내 이미지 필드의 `@NotBlank` 옵션 추가
  • Loading branch information
iamjooon2 authored Aug 16, 2023
1 parent af69151 commit 0b56435
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions backend/src/main/java/zipgo/pet/application/PetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@RequiredArgsConstructor
public class PetService {

private static final String DEFAULT_PET_IMAGE = "https://image.zipgo.pet/dev/pet-image/dog_icon.svg";

private final PetRepository petRepository;
private final MemberRepository memberRepository;
private final BreedsRepository breedsRepository;
Expand All @@ -31,8 +33,16 @@ public Long createPet(Long memberId, CreatePetRequest request) {
PetSize petSize = petSizeRepository.getByName(request.petSize());
Breeds breeds = breedsRepository.getByNameAndPetSizeId(request.breed(), petSize.getId());

Pet pet = petRepository.save(request.toEntity(owner, breeds));
return pet.getId();
Pet pet = request.toEntity(owner, breeds);
updateDefaultImage(pet);

return petRepository.save(pet).getId();
}

private void updateDefaultImage(Pet pet) {
if ("".equals(pet.getImageUrl())) {
pet.updateImageUrl(DEFAULT_PET_IMAGE);
}
}

public void updatePet(Long memberId, Long petId, UpdatePetRequest request) {
Expand All @@ -49,6 +59,7 @@ public void updatePet(Long memberId, Long petId, UpdatePetRequest request) {
private void update(UpdatePetRequest request, Pet pet, Breeds breeds) {
pet.updateName(request.name());
pet.updateImageUrl(request.image());
updateDefaultImage(pet);
pet.updateBreeds(breeds);
pet.updateBirthYear(request.calculateBirthYear());
pet.updateWeight(request.weight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ public ResponseEntity<BreedsResponses> readBreeds() {
return ResponseEntity.ok(BreedsResponses.from(breeds));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public record CreatePetRequest (
@NotBlank(message = "Null 또는 공백이 포함될 수 없습니다. 올바른 값인지 확인해주세요.")
String gender,

@NotBlank(message = "Null 또는 공백이 포함될 수 없습니다. 올바른 값인지 확인해주세요.")
String image,

@Max(20)
Expand All @@ -38,6 +39,7 @@ public Pet toEntity(Member owner, Breeds breeds) {
return Pet.builder()
.birthYear(Year.of(birthYear))
.owner(owner)
.imageUrl(image)
.name(name)
.gender(Gender.from(gender))
.breeds(breeds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public record UpdatePetRequest(
@NotBlank(message = "Null 또는 공백이 포함될 수 없습니다. 올바른 값인지 확인해주세요.")
String gender,

@NotBlank(message = "Null 또는 공백이 포함될 수 없습니다. 올바른 값인지 확인해주세요.")
String image,

@Max(20)
Expand Down

0 comments on commit 0b56435

Please sign in to comment.