Skip to content

Commit

Permalink
Fix: Pet 정보 수정 시 오류 수정
Browse files Browse the repository at this point in the history
Fix: Pet 정보 수정 시 오류 수정
  • Loading branch information
seoyeonjin authored Jan 20, 2025
2 parents d0de716 + 35ff952 commit 46b4d1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/cocos/cocos/api/pet/service/PetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public void addPet(final PetCreateRequest petCreateRequest, final Long memberId)
}

private void validatePetDiseases(List<Long> diseaseIds) {
List<Long> validDiseaseIds = petDiseaseRepository.findAllById(diseaseIds).stream()
.map(PetDisease::getId)
List<Long> validDiseaseIds = diseaseRepository.findByIdIn(diseaseIds).stream()
.map(Disease::getId)
.toList();

List<Long> invalidDiseaseIds = diseaseIds.stream()
Expand All @@ -93,8 +93,8 @@ private void validatePetDiseases(List<Long> diseaseIds) {
}

private void validatePetSymptoms(List<Long> symptomIds) {
List<Long> validSymptomIds = petSymptomRepository.findAllById(symptomIds).stream()
.map(PetSymptom::getId)
List<Long> validSymptomIds = symptomRepository.findByIdIn(symptomIds).stream()
.map(Symptom::getId)
.toList();

List<Long> invalidSymptomIds = symptomIds.stream()
Expand Down Expand Up @@ -128,8 +128,10 @@ public void updatePet(final PetUpdateRequest petUpdateRequest, final Long petId,
if (!pet.getMemberId().equals(memberId)) {
throw new CocosException(FailMessage.FORBIDDEN_PET_UPDATE);
}
if (!breedRepository.existsById(petUpdateRequest.breedId())) {
throw new CocosException(FailMessage.NOT_FOUND_BREED);
if (petUpdateRequest.breedId() != null) {
if (!breedRepository.existsById(petUpdateRequest.breedId())) {
throw new CocosException(FailMessage.NOT_FOUND_BREED);
}
}
pet.updateFields(petUpdateRequest.name(), petUpdateRequest.gender(), petUpdateRequest.age(), petUpdateRequest.breedId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
public interface DiseaseRepository extends JpaRepository<Disease, Long> {

List<Disease> findAllByBodyId(final Long bodyId);
List<Disease> findByIdIn(final List<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
public interface SymptomRepository extends JpaRepository<Symptom, Long> {

List<Symptom> findAllByBodyId(final Long BodyId);
List<Symptom> findByIdIn(final List<Long> ids);
}

0 comments on commit 46b4d1f

Please sign in to comment.