From a12249657723bee31a6f677408b2b4dcc0e3aa44 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Thu, 4 Jan 2024 16:31:57 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FEAT]=20=EB=B3=B4=EA=B4=80=ED=95=A8?= =?UTF-8?q?=EB=B3=84=20=EC=9D=B8=EC=82=AC=EC=9D=B4=ED=8A=B8=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B0=9C?= =?UTF-8?q?=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/seed/controller/SeedController.java | 10 +++++++ .../SeedListByCaveGetResponseDto.java | 18 +++++++++++++ .../api/seed/repository/SeedRepository.java | 2 ++ .../seed/service/Impl/SeedServiceImpl.java | 26 +++++++++++++++++-- .../api/seed/service/SeedService.java | 5 ++++ .../common/response/SuccessStatus.java | 2 ++ 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 growthookServer/src/main/java/com/example/growthookserver/api/seed/dto/response/SeedListByCaveGetResponseDto.java 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..c238171 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 @@ -5,6 +5,7 @@ import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto; 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; @@ -12,7 +13,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.*; @@ -62,4 +65,11 @@ 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)); + } + } 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 dbe7584..374ced2 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 @@ -4,11 +4,13 @@ import com.example.growthookserver.api.seed.domain.Seed; import com.example.growthookserver.common.exception.NotFoundException; import com.example.growthookserver.common.response.ErrorStatus; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface SeedRepository extends JpaRepository { Optional findSeedById(Long seedId); + List findAllByCaveId(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 46be8b7..e265d17 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; @@ -8,9 +10,12 @@ import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto; 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.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -25,6 +30,7 @@ public class SeedServiceImpl implements SeedService { private final CaveRepository caveRepository; private final SeedRepository seedRepository; + private final ActionPlanRepository actionPlanRepository; @Override @Transactional @@ -61,8 +67,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); } @@ -76,4 +81,21 @@ public SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequ return SeedMoveResponseDto.of(seed.getCave().getId(), seed.getCave().getName()); } + @Override + public List getSeedListByCave(Long caveId) { + return seedRepository.findAllByCaveId(caveId).stream() + .map(seed -> SeedListByCaveGetResponseDto.of(seed.getId(), seed.getInsight(), calculateRemainingDays(seed.getLockDate()), + seed.getIsLocked(), seed.getIsScraped(), checkHasActionPlan(seed))) + .collect(Collectors.toList()); + } + + 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 636bef2..780c319 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 @@ -7,7 +7,9 @@ import com.example.growthookserver.api.seed.dto.request.SeedUpdateRequestDto; 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; public interface SeedService { //* 씨앗 생성 @@ -24,4 +26,7 @@ public interface SeedService { //* 씨앗 이동 SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequestDto); + + //* 보관함별 씨앗 리스트 조회 + List getSeedListByCave(Long caveId); } 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..b705aa3 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, "보관함별로 씨앗 리스트 조회 성공"), /** * actionplan From cad00305886c74cfdd062ac84338a134407898fa Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Thu, 4 Jan 2024 19:16:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[ADD]=20=EC=9D=B8=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8B=9C,=20=EC=A0=95=EB=A0=AC=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../growthookserver/api/seed/repository/SeedRepository.java | 2 +- .../growthookserver/api/seed/service/Impl/SeedServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 374ced2..2501e05 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 @@ -10,7 +10,7 @@ public interface SeedRepository extends JpaRepository { Optional findSeedById(Long seedId); - List findAllByCaveId(Long caveId); + 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 e265d17..c5d3006 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 @@ -83,7 +83,7 @@ public SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequ @Override public List getSeedListByCave(Long caveId) { - return seedRepository.findAllByCaveId(caveId).stream() + 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());