From da9c52eda1bf09382d9acc48a190075a33c241c7 Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Thu, 28 Dec 2023 02:52:15 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[FIX]=EC=95=A1=EC=85=98=20=ED=94=8C?= =?UTF-8?q?=EB=9E=9C=20=EC=99=84=EB=A3=8C=ED=95=98=EA=B8=B0API=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actionplan/service/Impl/ActionPlanServiceImpl.java | 9 +++++++++ .../growthookserver/api/member/domain/Member.java | 5 +++++ .../growthookserver/common/response/ErrorStatus.java | 1 + 3 files changed, 15 insertions(+) diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java index 040c879..e7a771e 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java @@ -8,8 +8,11 @@ import com.example.growthookserver.api.actionplan.dto.response.FinishedActionPlanGetResponseDto; import com.example.growthookserver.api.actionplan.repository.ActionPlanRepository; import com.example.growthookserver.api.actionplan.service.ActionPlanService; +import com.example.growthookserver.api.member.domain.Member; import com.example.growthookserver.api.seed.domain.Seed; import com.example.growthookserver.api.seed.repository.SeedRepository; +import com.example.growthookserver.common.exception.BadRequestException; +import com.example.growthookserver.common.response.ErrorStatus; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -70,7 +73,13 @@ public void deleteActionPlan(Long actionPlanId) { @Transactional public void completeActionPlan(Long actionPlanId) { ActionPlan existinActionPlan = actionPlanRepository.findActionPlanByIdOrThrow(actionPlanId); + if(existinActionPlan.getIsFinished()) { + throw new BadRequestException(ErrorStatus.ALREADY_COMPLETE_ACTIONPLAN.getMessage()); + } existinActionPlan.completeActionPlan(true); + + Member member = existinActionPlan.getSeed().getCave().getMember(); + member.incrementGatheredSsuk(); } @Override diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/member/domain/Member.java b/growthookServer/src/main/java/com/example/growthookserver/api/member/domain/Member.java index b49c3e6..7d567eb 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/member/domain/Member.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/member/domain/Member.java @@ -51,4 +51,9 @@ public Member(String nickname, String email, SocialPlatform socialPlatform, Bool this.usedSsuk = usedSsuk; this.gatheredSsuk = gatheredSsuk; } + + @Builder + public void incrementGatheredSsuk() { + this.gatheredSsuk = (this.gatheredSsuk == null ? 0 : this.gatheredSsuk) + 1; + } } diff --git a/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java b/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java index d4f13eb..835502e 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java +++ b/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java @@ -16,6 +16,7 @@ public enum ErrorStatus { NO_TOKEN("토큰을 넣어주세요."), INVALID_MEMBER("유효하지 않은 유저입니다."), ANOTHER_ACCESS_TOKEN("지원하지 않는 소셜 플랫폼입니다."), + ALREADY_COMPLETE_ACTIONPLAN("이미 완료된 액션 플랜입니다."), /** * 401 UNAUTHORIZED From 23cf1847a79636406f1fd2b1b2a2b009be56f8e1 Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Fri, 29 Dec 2023 03:33:46 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[FIX]=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actionplan/service/Impl/ActionPlanServiceImpl.java | 10 +++------- .../api/seed/dto/response/SeedAlarmGetResponseDto.java | 1 - .../api/seed/service/Impl/SeedServiceImpl.java | 7 ++----- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java index e7a771e..f1c540e 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/Impl/ActionPlanServiceImpl.java @@ -37,13 +37,9 @@ public void createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanC List contents = actionPlanCreateRequestDto.getContents(); - for(String content : contents) { - ActionPlan actionPlan = ActionPlan.builder() - .content(content) - .seed(seed) - .build(); - actionPlanRepository.save(actionPlan); - } + contents.stream() + .map(content -> ActionPlan.builder().content(content).seed(seed).build()) + .forEach(actionPlanRepository::save); } @Override diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedAlarmGetResponseDto.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedAlarmGetResponseDto.java index b252c41..aa5322d 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedAlarmGetResponseDto.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedAlarmGetResponseDto.java @@ -10,5 +10,4 @@ @AllArgsConstructor(staticName = "of") public class SeedAlarmGetResponseDto { private int seedCount; - private int daysRemaining; } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java index 7902525..2d990e7 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java @@ -88,15 +88,12 @@ public SeedAlarmGetResponseDto getSeedAlarm(Long memberId) { List seeds = seedRepository.findByCave_MemberIdAndLockDateBetween(memberId, now, threeDaysLater); if(seeds.isEmpty()) { - return SeedAlarmGetResponseDto.of(0,0); + return SeedAlarmGetResponseDto.of(0); } int seedCount = seeds.size(); - Seed earliestSeed = findEarliestSeed(seeds); - int daysRemaining = calculateDaysRemaining(now, earliestSeed.getLockDate()); - - return SeedAlarmGetResponseDto.of(seedCount, daysRemaining); + return SeedAlarmGetResponseDto.of(seedCount); } private Seed findEarliestSeed(List seeds) { From 5911636818765c3153a4a84652c163072d49ec21 Mon Sep 17 00:00:00 2001 From: Hong0329 Date: Thu, 4 Jan 2024 16:14:35 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[TEST]CI=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- growthookServer/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/growthookServer/.gitignore b/growthookServer/.gitignore index b89ff5c..a0ce3cb 100644 --- a/growthookServer/.gitignore +++ b/growthookServer/.gitignore @@ -38,4 +38,4 @@ out/ resources ../.DS_Store -.DS_Store \ No newline at end of file +.DS_Store From 5969d62f2c9783752a9c46026cadaa97cf636be4 Mon Sep 17 00:00:00 2001 From: Hong0329 <97835512+Hong0329@users.noreply.github.com> Date: Fri, 5 Jan 2024 03:35:11 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[FIX]=EC=95=88=EC=93=B0=EB=8A=94=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/seed/service/Impl/SeedServiceImpl.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java index 2d990e7..e63755d 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/Impl/SeedServiceImpl.java @@ -95,14 +95,4 @@ public SeedAlarmGetResponseDto getSeedAlarm(Long memberId) { return SeedAlarmGetResponseDto.of(seedCount); } - - private Seed findEarliestSeed(List seeds) { - return seeds.stream() - .min(Comparator.comparing(Seed::getLockDate)) - .orElse(null); - } - - private int calculateDaysRemaining(LocalDate now, LocalDate localDate) { - return (int) ChronoUnit.DAYS.between(now, localDate); - } }