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 9fd8ee7..00f9c58 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 @@ -72,11 +72,19 @@ 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") + @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()); } @GetMapping("member/{memberId}/alarm") @@ -85,4 +93,5 @@ public ApiResponse> getSeedList() { 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/seed/domain/Seed.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/domain/Seed.java index 5db70e7..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) { @@ -69,4 +72,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/repository/SeedRepository.java b/growthookServer/src/main/java/com/example/growthookserver/api/seed/repository/SeedRepository.java index 43f18c8..e8bc7b6 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 38b43ac..0e68bf2 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 @@ -47,6 +47,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()); @@ -94,8 +95,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()); @@ -117,6 +118,13 @@ public SeedAlarmGetResponseDto getSeedAlarm(Long memberId) { return SeedAlarmGetResponseDto.of(seedCount); } + @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 a8bf33c..563a51e 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 @@ -32,7 +32,10 @@ public interface SeedService { List getSeedListByCave(Long caveId); //* 씨앗 전체 리스트 조회 - List getSeedList(); + List getSeedList(Long memberId); + + //* 씨앗 스크랩 상태 변경 + void toggleSeedScrapStatus(Long seedId); //* 씨앗 알림 조회 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 3be4ddd..20c7627 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, "씨앗 스크랩 여부 토글 전환 성공"), GET_SEED_ALARM(HttpStatus.OK,"씨앗 알람 조회 성공"), /**