From 2d8865a340deb873ff79e914db5a60106f451377 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Fri, 5 Jan 2024 03:16:41 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[FEAT]=20#53=20=EC=94=A8=EC=95=97=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=9E=A9=20=EC=83=81=ED=83=9C=20=EC=A0=84?= =?UTF-8?q?=ED=99=98=20=ED=86=A0=EA=B8=80=20API=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/seed/controller/SeedController.java | 7 +++++++ .../com/example/growthookserver/api/seed/domain/Seed.java | 2 ++ .../api/seed/service/Impl/SeedServiceImpl.java | 7 +++++++ .../growthookserver/api/seed/service/SeedService.java | 3 +++ .../growthookserver/common/response/SuccessStatus.java | 2 +- 5 files changed, 20 insertions(+), 1 deletion(-) 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 d6827f0..ea2fc7f 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 @@ -78,5 +78,12 @@ public ApiResponse> getSeedList() { return ApiResponse.success(SuccessStatus.GET_SEED_LIST, seedService.getSeedList()); } + @PatchMapping("seed/{seedId}/scrap/status") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "ToggleSeedScrapStatus", description = "씨앗 스크랩 여부를 전환하는 토글 API입니다.") + public ApiResponse toggleSeedScrapStatus(@PathVariable Long seedId) { + seedService.toggleSeedScrapStatus(seedId); + return ApiResponse.success(SuccessStatus.TOGGLE_SEED_SCRAP_STATUS.getStatusCode(), SuccessStatus.TOGGLE_SEED_SCRAP_STATUS.getMessage()); + } } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java index 5db70e7..e50b397 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java @@ -69,4 +69,6 @@ public void updateSeed(String newInsight, String newMemo, String newSource, Stri public void changeCave(Cave newCave) { this.cave = newCave; } + + public void toggleScrapStatus() { this.isScraped = !this.isScraped; } } 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 930e96b..d20bc7c 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 @@ -97,6 +97,13 @@ public List getSeedList() { .collect(Collectors.toList()); } + @Override + @Transactional + public void toggleSeedScrapStatus(Long seedId) { + Seed seed = seedRepository.findSeedByIdOrThrow(seedId); + seed.toggleScrapStatus(); + } + private Long calculateRemainingDays(LocalDate lockDate) { LocalDate currentDate = LocalDate.now(); return currentDate.until(lockDate, ChronoUnit.DAYS); 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 16beb26..5a016b7 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 @@ -30,4 +30,7 @@ public interface SeedService { //* 씨앗 전체 리스트 조회 List getSeedList(); + + //* 씨앗 스크랩 상태 변경 + void toggleSeedScrapStatus(Long seedId); } 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 d25c081..68ef4c1 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,7 +3,6 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties.Http; import org.springframework.http.HttpStatus; @Getter @@ -36,6 +35,7 @@ public enum SuccessStatus { MOVE_SEED_SUCCESS(HttpStatus.OK, "씨앗 이동 성공"), GET_SEED_LIST_BY_CAVE(HttpStatus.OK, "보관함별로 씨앗 리스트 조회 성공"), GET_SEED_LIST(HttpStatus.OK, "전체 씨앗 리스트 조회 성공" ), + TOGGLE_SEED_SCRAP_STATUS(HttpStatus.OK, "씨앗 스크랩 여부 토글 전환 성공"), /** * actionplan From 6e1fc4fd8590c3a79a539444f263e64890ebd10d Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Fri, 5 Jan 2024 05:15:06 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[FIX]=20=EC=A0=84=EC=B2=B4=20=EC=94=A8?= =?UTF-8?q?=EC=95=97=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8B=9C,=20memberId=EB=A1=9C=20=EC=A1=B0=EA=B1=B4=EC=A0=88=20?= =?UTF-8?q?=EA=B1=B8=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/seed/controller/SeedController.java | 8 ++++---- .../com/example/growthookserver/api/seed/domain/Seed.java | 5 ++++- .../api/seed/repository/SeedRepository.java | 2 +- .../api/seed/service/Impl/SeedServiceImpl.java | 5 +++-- .../growthookserver/api/seed/service/SeedService.java | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) 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 ea2fc7f..156525c 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 @@ -26,7 +26,7 @@ public class SeedController { private final SeedService seedService; - @PostMapping("/cave/{caveId}/seed") + @PostMapping("/member/{memberId}/cave/{caveId}/seed") @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "SeedPost", description = "씨앗 생성 API입니다.") public ApiResponse createSeed(@PathVariable("caveId") Long caveId, @Valid @RequestBody SeedCreateRequestDto seedCreateRequestDto) { @@ -71,11 +71,11 @@ public ApiResponse> getSeedListByCave(@PathVariable return ApiResponse.success(SuccessStatus.GET_SEED_LIST_BY_CAVE, seedService.getSeedListByCave(caveId)); } - @GetMapping("seed/list") + @GetMapping("member/{memberId}/seed/list") @ResponseStatus(HttpStatus.OK) @Operation(summary = "SeedListGet", description = "전체 씨앗 리스트를 조회하는 API입니다.") - public ApiResponse> getSeedList() { - return ApiResponse.success(SuccessStatus.GET_SEED_LIST, seedService.getSeedList()); + public ApiResponse> getSeedList(@PathVariable Long memberId) { + return ApiResponse.success(SuccessStatus.GET_SEED_LIST, seedService.getSeedList(memberId)); } @PatchMapping("seed/{seedId}/scrap/status") diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java index e50b397..5082f8a 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java @@ -31,6 +31,8 @@ public class Seed extends BaseTimeEntity { private String url; + private Long memberId; + @Column(name = "lock_date") private LocalDate lockDate; @@ -48,7 +50,7 @@ public class Seed extends BaseTimeEntity { private List actionPlans = new ArrayList<>(); @Builder - public Seed(String insight, String memo, String source, String url, Integer goalMonth, Cave cave) { + public Seed(String insight, String memo, String source, String url, Integer goalMonth, Cave cave, Long memberId) { this.insight = insight; this.memo = memo; this.source = source; @@ -57,6 +59,7 @@ public Seed(String insight, String memo, String source, String url, Integer goal this.isScraped = false; this.isLocked = false; this.cave = cave; + this.memberId = memberId; } public void updateSeed(String newInsight, String newMemo, String newSource, String newUrl) { 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 e065b37..2f5f02a 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 @@ -12,7 +12,7 @@ public interface SeedRepository extends JpaRepository { Optional findSeedById(Long seedId); List findByCaveIdOrderByIdDesc(Long caveId); - List findAllByOrderByIdDesc(); + List findByMemberIdOrderByIdDesc(Long memberId); 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 d20bc7c..acad13e 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 @@ -43,6 +43,7 @@ public SeedCreateResponseDto createSeed(Long caveId, SeedCreateRequestDto seedCr .insight(seedCreateRequestDto.getInsight()) .source(seedCreateRequestDto.getSource()) .goalMonth(seedCreateRequestDto.getGoalMonth()) + .memberId(cave.getMember().getId()) .build(); Seed savedSeed = seedRepository.save(seed); return SeedCreateResponseDto.of(savedSeed.getId()); @@ -90,8 +91,8 @@ public List getSeedListByCave(Long caveId) { } @Override - public List getSeedList() { - return seedRepository.findAllByOrderByIdDesc().stream() + public List getSeedList(Long memberId) { + return seedRepository.findByMemberIdOrderByIdDesc(memberId).stream() .map(seed -> SeedListGetResponseDto.of(seed.getId(), seed.getInsight(), calculateRemainingDays(seed.getLockDate()), seed.getIsLocked(), seed.getIsScraped(), checkHasActionPlan(seed))) .collect(Collectors.toList()); 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 5a016b7..364ddaf 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 @@ -29,7 +29,7 @@ public interface SeedService { List getSeedListByCave(Long caveId); //* 씨앗 전체 리스트 조회 - List getSeedList(); + List getSeedList(Long memberId); //* 씨앗 스크랩 상태 변경 void toggleSeedScrapStatus(Long seedId); From e685cf226a914263a7dc719b45335af60af1df95 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Fri, 5 Jan 2024 05:21:19 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[FIX]=20=EC=94=A8=EC=95=97=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20API=20=EC=97=94=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../growthookserver/api/seed/controller/SeedController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 156525c..bc621f1 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 @@ -26,7 +26,7 @@ public class SeedController { private final SeedService seedService; - @PostMapping("/member/{memberId}/cave/{caveId}/seed") + @PostMapping("/cave/{caveId}/seed") @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "SeedPost", description = "씨앗 생성 API입니다.") public ApiResponse createSeed(@PathVariable("caveId") Long caveId, @Valid @RequestBody SeedCreateRequestDto seedCreateRequestDto) {