From bf32bef1daba1f6544a0112f99f22bd2bbefb9f1 Mon Sep 17 00:00:00 2001 From: kwonssshyeon Date: Thu, 19 Sep 2024 23:26:34 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]:=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20?= =?UTF-8?q?=EA=B7=B8=EB=A3=B9=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=B2=B4=ED=81=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zzansuni/challengegroup/domain/Challenge.java | 12 ++++++++++++ .../challengegroup/domain/ChallengeGroup.java | 13 ++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/Challenge.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/Challenge.java index 8033f82..15a9cf4 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/Challenge.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/Challenge.java @@ -9,6 +9,8 @@ import lombok.NoArgsConstructor; import org.haedal.zzansuni.common.domain.BaseTimeEntity; +import java.util.List; + @Entity @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -61,6 +63,16 @@ public Challenge update(ChallengeGroupCommand.UpdateChallenge command) { return this; } + protected boolean updateChallengeIfPresent(List command) { + for (ChallengeGroupCommand.UpdateChallenge updateCommand : command) { + if (this.id.equals(updateCommand.getId())) { + update(updateCommand); + return true; + } + } + return false; + } + /** * 챌린지 그룹 아이디 반환 * FK는 LAZY 여도 이미 영속성 컨텍스트에 존재하므로 추가 조회 없이 바로 접근 가능 diff --git a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/ChallengeGroup.java b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/ChallengeGroup.java index ad74df8..8002dee 100644 --- a/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/ChallengeGroup.java +++ b/zzansuni-api-server/app/src/main/java/org/haedal/zzansuni/challengegroup/domain/ChallengeGroup.java @@ -11,6 +11,8 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -87,15 +89,12 @@ public ChallengeGroup update(ChallengeGroupCommand.Update command) { return this; } - public void updateChallenges(List command) { + private void updateChallenges(List command) { List removeChallenges = new ArrayList<>(); + for (Challenge existingChallenge : this.challenges) { - for (ChallengeGroupCommand.UpdateChallenge updateCommand : command) { - if (existingChallenge.getId().equals(updateCommand.getId())) { - existingChallenge.update(updateCommand); - } else { - removeChallenges.add(existingChallenge); - } + if (!existingChallenge.updateChallengeIfPresent(command)) { + removeChallenges.add(existingChallenge); } } this.challenges.removeAll(removeChallenges);