Skip to content

Commit

Permalink
[FIX] 전체 씨앗 리스트 조회 시, memberId로 조건절 걸도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Jan 4, 2024
1 parent 2d8865a commit 6e1fc4f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SeedCreateResponseDto> createSeed(@PathVariable("caveId") Long caveId, @Valid @RequestBody SeedCreateRequestDto seedCreateRequestDto) {
Expand Down Expand Up @@ -71,11 +71,11 @@ public ApiResponse<List<SeedListGetResponseDto>> 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<List<SeedListGetResponseDto>> getSeedList() {
return ApiResponse.success(SuccessStatus.GET_SEED_LIST, seedService.getSeedList());
public ApiResponse<List<SeedListGetResponseDto>> getSeedList(@PathVariable Long memberId) {
return ApiResponse.success(SuccessStatus.GET_SEED_LIST, seedService.getSeedList(memberId));
}

@PatchMapping("seed/{seedId}/scrap/status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Seed extends BaseTimeEntity {

private String url;

private Long memberId;

@Column(name = "lock_date")
private LocalDate lockDate;

Expand All @@ -48,7 +50,7 @@ public class Seed extends BaseTimeEntity {
private List<ActionPlan> 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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface SeedRepository extends JpaRepository<Seed, Long> {
Optional<Seed> findSeedById(Long seedId);
List<Seed> findByCaveIdOrderByIdDesc(Long caveId);

List<Seed> findAllByOrderByIdDesc();
List<Seed> findByMemberIdOrderByIdDesc(Long memberId);

default Seed findSeedByIdOrThrow(Long seedId) {
return findSeedById(seedId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -90,8 +91,8 @@ public List<SeedListGetResponseDto> getSeedListByCave(Long caveId) {
}

@Override
public List<SeedListGetResponseDto> getSeedList() {
return seedRepository.findAllByOrderByIdDesc().stream()
public List<SeedListGetResponseDto> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface SeedService {
List<SeedListGetResponseDto> getSeedListByCave(Long caveId);

//* 씨앗 전체 리스트 조회
List<SeedListGetResponseDto> getSeedList();
List<SeedListGetResponseDto> getSeedList(Long memberId);

//* 씨앗 스크랩 상태 변경
void toggleSeedScrapStatus(Long seedId);
Expand Down

0 comments on commit 6e1fc4f

Please sign in to comment.