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] =?UTF-8?q?[FIX]=20=EC=A0=84=EC=B2=B4=20=EC=94=A8=EC=95=97?= =?UTF-8?q?=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C?= =?UTF-8?q?,=20memberId=EB=A1=9C=20=EC=A1=B0=EA=B1=B4=EC=A0=88=20=EA=B1=B8?= =?UTF-8?q?=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);