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 diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/controller/ActionPlanController.java b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/controller/ActionPlanController.java index d8e0805..ddc1694 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/controller/ActionPlanController.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/controller/ActionPlanController.java @@ -2,7 +2,6 @@ import com.example.growthookserver.api.actionplan.dto.request.ActionPlanCreateRequestDto; import com.example.growthookserver.api.actionplan.dto.request.ActionPlanUpdateRequestDto; -import com.example.growthookserver.api.actionplan.dto.response.ActionPlanCreateResponseDto; import com.example.growthookserver.api.actionplan.dto.response.ActionPlanGetResponseDto; import com.example.growthookserver.api.actionplan.dto.response.DoingActionPlanGetResponseDto; import com.example.growthookserver.api.actionplan.dto.response.FinishedActionPlanGetResponseDto; @@ -27,8 +26,9 @@ public class ActionPlanController { @PostMapping("seed/{seedId}/actionPlan") @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "ActionPlanPost",description = "액션 플랜 생성 API입니다.") - public ApiResponse createActionPlan(@PathVariable("seedId")Long seedId, @Valid @RequestBody ActionPlanCreateRequestDto actionPlanCreateRequestDto) { - return ApiResponse.success(SuccessStatus.POST_ACTIONPLAN_SUCCESS, actionPlanService.createActionPlan(seedId, actionPlanCreateRequestDto)); + public ApiResponse createActionPlan(@PathVariable("seedId")Long seedId, @Valid @RequestBody ActionPlanCreateRequestDto actionPlanCreateRequestDto) { + actionPlanService.createActionPlan(seedId, actionPlanCreateRequestDto); + return ApiResponse.success(SuccessStatus.POST_ACTIONPLAN_SUCCESS.getStatusCode(), SuccessStatus.POST_ACTIONPLAN_SUCCESS.getMessage()); } @GetMapping("seed/{seedId}/actionPlan") diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/dto/request/ActionPlanCreateRequestDto.java b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/dto/request/ActionPlanCreateRequestDto.java index b6e321a..3e3429c 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/dto/request/ActionPlanCreateRequestDto.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/dto/request/ActionPlanCreateRequestDto.java @@ -1,17 +1,19 @@ package com.example.growthookserver.api.actionplan.dto.request; -import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor public class ActionPlanCreateRequestDto { - @NotBlank + @NotNull @Size(max = 40) - private String content; + private List contents; } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/ActionPlanService.java b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/ActionPlanService.java index f6b8898..d4f71a5 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/ActionPlanService.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/service/ActionPlanService.java @@ -2,7 +2,6 @@ import com.example.growthookserver.api.actionplan.dto.request.ActionPlanCreateRequestDto; import com.example.growthookserver.api.actionplan.dto.request.ActionPlanUpdateRequestDto; -import com.example.growthookserver.api.actionplan.dto.response.ActionPlanCreateResponseDto; import com.example.growthookserver.api.actionplan.dto.response.ActionPlanGetResponseDto; import com.example.growthookserver.api.actionplan.dto.response.DoingActionPlanGetResponseDto; import com.example.growthookserver.api.actionplan.dto.response.FinishedActionPlanGetResponseDto; @@ -11,7 +10,7 @@ public interface ActionPlanService { //* 액션플랜 생성 - ActionPlanCreateResponseDto createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto); + void createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto); //* 씨앗 별 액션 플랜 조회 List getActionPlan(Long seedId); 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 5aa24e9..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 @@ -3,14 +3,16 @@ import com.example.growthookserver.api.actionplan.domain.ActionPlan; import com.example.growthookserver.api.actionplan.dto.request.ActionPlanCreateRequestDto; import com.example.growthookserver.api.actionplan.dto.request.ActionPlanUpdateRequestDto; -import com.example.growthookserver.api.actionplan.dto.response.ActionPlanCreateResponseDto; import com.example.growthookserver.api.actionplan.dto.response.ActionPlanGetResponseDto; import com.example.growthookserver.api.actionplan.dto.response.DoingActionPlanGetResponseDto; 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; @@ -30,14 +32,14 @@ public class ActionPlanServiceImpl implements ActionPlanService { @Override @Transactional - public ActionPlanCreateResponseDto createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto){ + public void createActionPlan(Long seedId, ActionPlanCreateRequestDto actionPlanCreateRequestDto){ Seed seed = seedRepository.findSeedByIdOrThrow(seedId); - ActionPlan actionPlan = ActionPlan.builder() - .content(actionPlanCreateRequestDto.getContent()) - .seed(seed) - .build(); - ActionPlan savedActionPlan = actionPlanRepository.save(actionPlan); - return ActionPlanCreateResponseDto.of(savedActionPlan.getId()); + + List contents = actionPlanCreateRequestDto.getContents(); + + contents.stream() + .map(content -> ActionPlan.builder().content(content).seed(seed).build()) + .forEach(actionPlanRepository::save); } @Override @@ -67,7 +69,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/api/seed/controller/SeedController.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/controller/SeedController.java index f901357..11b339a 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/controller/SeedController.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/controller/SeedController.java @@ -3,6 +3,7 @@ import com.example.growthookserver.api.seed.dto.request.SeedMoveRequestDto; import com.example.growthookserver.api.seed.dto.request.SeedCreateRequestDto; import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto; +import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedCreateResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedDetailGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto; @@ -62,4 +63,10 @@ public ApiResponse moveSeed(@PathVariable Long seedId, @Val return ApiResponse.success(SuccessStatus.MOVE_SEED_SUCCESS, seedService.moveSeed(seedId, seedMoveRequestDto)); } + @GetMapping("member/{memberId}/alarm") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "SeedAlarm", description = "기한이 3일 이내로 남은 씨앗에 대한 알림을 조회하는 API입니다.") + public ApiResponse getSeedAlarm(@PathVariable Long memberId) { + return ApiResponse.success(SuccessStatus.GET_SEED_ALARM, seedService.getSeedAlarm(memberId)); + } } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/dto/response/ActionPlanCreateResponseDto.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedAlarmGetResponseDto.java similarity index 60% rename from growthookServer/src/main/java/com/example/growthookserver/api/actionplan/dto/response/ActionPlanCreateResponseDto.java rename to growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedAlarmGetResponseDto.java index ad9ccf9..aa5322d 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/actionplan/dto/response/ActionPlanCreateResponseDto.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedAlarmGetResponseDto.java @@ -1,4 +1,4 @@ -package com.example.growthookserver.api.actionplan.dto.response; +package com.example.growthookserver.api.seed.dto.response; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -8,7 +8,6 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor(staticName = "of") -public class ActionPlanCreateResponseDto { - - private Long actionPlanId; +public class SeedAlarmGetResponseDto { + private int seedCount; } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/repository/SeedRepository.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/repository/SeedRepository.java index dbe7584..2662215 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/repository/SeedRepository.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/repository/SeedRepository.java @@ -1,9 +1,11 @@ package com.example.growthookserver.api.seed.repository; -import com.example.growthookserver.api.cave.domain.Cave; import com.example.growthookserver.api.seed.domain.Seed; import com.example.growthookserver.common.exception.NotFoundException; import com.example.growthookserver.common.response.ErrorStatus; + +import java.time.LocalDate; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,4 +16,6 @@ default Seed findSeedByIdOrThrow(Long seedId) { return findSeedById(seedId) .orElseThrow(()-> new NotFoundException(ErrorStatus.NOT_FOUND_SEED.getMessage())); } + + List findByCave_MemberIdAndLockDateBetween(Long memberId, LocalDate now, LocalDate threeDaysLater); } 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 46be8b7..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 @@ -6,17 +6,21 @@ import com.example.growthookserver.api.seed.dto.request.SeedCreateRequestDto; import com.example.growthookserver.api.seed.dto.request.SeedMoveRequestDto; import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto; +import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedCreateResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedDetailGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto; import com.example.growthookserver.api.seed.repository.SeedRepository; import com.example.growthookserver.api.seed.service.SeedService; import lombok.RequiredArgsConstructor; +import org.springframework.cglib.core.Local; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.temporal.ChronoUnit; +import java.util.Comparator; +import java.util.List; @Service @RequiredArgsConstructor @@ -76,4 +80,19 @@ public SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequ return SeedMoveResponseDto.of(seed.getCave().getId(), seed.getCave().getName()); } + @Override + public SeedAlarmGetResponseDto getSeedAlarm(Long memberId) { + LocalDate now = LocalDate.now(); + LocalDate threeDaysLater = now.plusDays(3); + + List seeds = seedRepository.findByCave_MemberIdAndLockDateBetween(memberId, now, threeDaysLater); + + if(seeds.isEmpty()) { + return SeedAlarmGetResponseDto.of(0); + } + + int seedCount = seeds.size(); + + return SeedAlarmGetResponseDto.of(seedCount); + } } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/SeedService.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/SeedService.java index 636bef2..ecb1984 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/SeedService.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/service/SeedService.java @@ -5,10 +5,13 @@ import com.example.growthookserver.api.seed.dto.request.SeedCreateRequestDto; import com.example.growthookserver.api.seed.dto.request.SeedMoveRequestDto; import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto; +import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedCreateResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedDetailGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto; +import java.time.LocalDate; + public interface SeedService { //* 씨앗 생성 SeedCreateResponseDto createSeed(Long caveId, SeedCreateRequestDto seedCreateRequestDto); @@ -24,4 +27,7 @@ public interface SeedService { //* 씨앗 이동 SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequestDto); + + //* 씨앗 알림 조회 + SeedAlarmGetResponseDto getSeedAlarm(Long memberId); } 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 diff --git a/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java b/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java index fca7a07..1e7afdf 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java +++ b/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java @@ -33,6 +33,7 @@ public enum SuccessStatus { PATCH_SEED_SUCCESS(HttpStatus.OK, "씨앗 수정 성공"), GET_SEED_DETAIL(HttpStatus.OK, "씨앗 상세 정보 조회 성공"), MOVE_SEED_SUCCESS(HttpStatus.OK, "씨앗 이동 성공"), + GET_SEED_ALARM(HttpStatus.OK,"씨앗 알람 조회 성공"), /** * actionplan