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

Fix: Pet 정보 수정 시 오류 수정 #95

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2;

이 로직 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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p2;

여기도요!

.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);
}
Loading