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 11b339a..e92b102 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 @@ -6,6 +6,7 @@ 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.SeedListByCaveGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto; import com.example.growthookserver.api.seed.service.SeedService; import com.example.growthookserver.common.response.ApiResponse; @@ -13,7 +14,9 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties.Http; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -63,6 +66,13 @@ public ApiResponse moveSeed(@PathVariable Long seedId, @Val return ApiResponse.success(SuccessStatus.MOVE_SEED_SUCCESS, seedService.moveSeed(seedId, seedMoveRequestDto)); } + @GetMapping("/cave/{caveId}/seed/list") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "SeedListByCaveGet", description = "보관함별 씨앗 리스트를 조회하는 API입니다.") + public ApiResponse> getSeedListByCave(@PathVariable Long caveId) { + return ApiResponse.success(SuccessStatus.GET_SEED_LIST_BY_CAVE, seedService.getSeedListByCave(caveId)); + } + @GetMapping("member/{memberId}/alarm") @ResponseStatus(HttpStatus.OK) @Operation(summary = "SeedAlarm", description = "기한이 3일 이내로 남은 씨앗에 대한 알림을 조회하는 API입니다.") diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedListByCaveGetResponseDto.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedListByCaveGetResponseDto.java new file mode 100644 index 0000000..427a3aa --- /dev/null +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedListByCaveGetResponseDto.java @@ -0,0 +1,18 @@ +package com.example.growthookserver.api.seed.dto.response; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(staticName = "of") +public class SeedListByCaveGetResponseDto { + private Long seedId; + private String insight; + private Long remainingDays; + private Boolean isLocked; + private Boolean isScraped; + private Boolean hasActionPlan; +} 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 2662215..b43d5c0 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 @@ -3,7 +3,6 @@ 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; @@ -11,6 +10,7 @@ public interface SeedRepository extends JpaRepository { Optional findSeedById(Long seedId); + List findByCaveIdOrderByIdDesc(Long caveId); default Seed findSeedByIdOrThrow(Long seedId) { return findSeedById(seedId) 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 e63755d..e407f31 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 @@ -1,5 +1,7 @@ package com.example.growthookserver.api.seed.service.Impl; +import com.example.growthookserver.api.actionplan.domain.ActionPlan; +import com.example.growthookserver.api.actionplan.repository.ActionPlanRepository; import com.example.growthookserver.api.cave.domain.Cave; import com.example.growthookserver.api.cave.repository.CaveRepository; import com.example.growthookserver.api.seed.domain.Seed; @@ -9,9 +11,12 @@ 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.SeedListByCaveGetResponseDto; 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 java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.cglib.core.Local; import org.springframework.stereotype.Service; @@ -29,6 +34,7 @@ public class SeedServiceImpl implements SeedService { private final CaveRepository caveRepository; private final SeedRepository seedRepository; + private final ActionPlanRepository actionPlanRepository; @Override @Transactional @@ -65,8 +71,7 @@ public void updateSeed(Long seedId, SeedUpdateRequestDto seedUpdateRequestDto) { public SeedDetailGetResponseDto getSeedDetail(Long seedId) { Seed seed = seedRepository.findSeedByIdOrThrow(seedId); LocalDate lockDate = seed.getLockDate(); - LocalDate currentDate = LocalDate.now(); - long remainingDays = currentDate.until(lockDate, ChronoUnit.DAYS); + Long remainingDays = calculateRemainingDays(lockDate); return SeedDetailGetResponseDto.of(seed.getCave().getName(), seed.getInsight(), seed.getMemo(), seed.getSource(), seed.getUrl(), seed.getIsScraped(), lockDate.toString(), remainingDays); } @@ -80,6 +85,14 @@ public SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequ return SeedMoveResponseDto.of(seed.getCave().getId(), seed.getCave().getName()); } + @Override + public List getSeedListByCave(Long caveId) { + return seedRepository.findByCaveIdOrderByIdDesc(caveId).stream() + .map(seed -> SeedListByCaveGetResponseDto.of(seed.getId(), seed.getInsight(), calculateRemainingDays(seed.getLockDate()), + seed.getIsLocked(), seed.getIsScraped(), checkHasActionPlan(seed))) + .collect(Collectors.toList()); + } + @Override public SeedAlarmGetResponseDto getSeedAlarm(Long memberId) { LocalDate now = LocalDate.now(); @@ -95,4 +108,14 @@ public SeedAlarmGetResponseDto getSeedAlarm(Long memberId) { return SeedAlarmGetResponseDto.of(seedCount); } + + private Long calculateRemainingDays(LocalDate lockDate) { + LocalDate currentDate = LocalDate.now(); + return currentDate.until(lockDate, ChronoUnit.DAYS); + } + + private boolean checkHasActionPlan(Seed seed) { + List actionPlansBySeedId = actionPlanRepository.findAllBySeedId(seed.getId()); + return !actionPlansBySeedId.isEmpty(); + } } 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 ecb1984..c0f2466 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 @@ -8,7 +8,9 @@ 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.SeedListByCaveGetResponseDto; import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto; +import java.util.List; import java.time.LocalDate; @@ -28,6 +30,10 @@ public interface SeedService { //* 씨앗 이동 SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequestDto); + //* 보관함별 씨앗 리스트 조회 + List getSeedListByCave(Long caveId); + //* 씨앗 알림 조회 SeedAlarmGetResponseDto getSeedAlarm(Long memberId); + } 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 1e7afdf..ca305e2 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 @@ -3,6 +3,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties.Http; import org.springframework.http.HttpStatus; @Getter @@ -33,6 +34,7 @@ public enum SuccessStatus { PATCH_SEED_SUCCESS(HttpStatus.OK, "씨앗 수정 성공"), GET_SEED_DETAIL(HttpStatus.OK, "씨앗 상세 정보 조회 성공"), MOVE_SEED_SUCCESS(HttpStatus.OK, "씨앗 이동 성공"), + GET_SEED_LIST_BY_CAVE(HttpStatus.OK, "보관함별로 씨앗 리스트 조회 성공"), GET_SEED_ALARM(HttpStatus.OK,"씨앗 알람 조회 성공"), /**