Skip to content

Commit

Permalink
[FEAT] #52 전체 보관함의 모든 씨앗 리스트 조회 API 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Jan 4, 2024
1 parent ab88a16 commit 6743546
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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.SeedListGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto;
import com.example.growthookserver.api.seed.service.SeedService;
import com.example.growthookserver.common.response.ApiResponse;
Expand All @@ -15,7 +15,6 @@
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.*;

Expand Down Expand Up @@ -68,8 +67,16 @@ public ApiResponse<SeedMoveResponseDto> moveSeed(@PathVariable Long seedId, @Val
@GetMapping("/cave/{caveId}/seed/list")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "SeedListByCaveGet", description = "보관함별 씨앗 리스트를 조회하는 API입니다.")
public ApiResponse<List<SeedListByCaveGetResponseDto>> getSeedListByCave(@PathVariable Long caveId) {
public ApiResponse<List<SeedListGetResponseDto>> getSeedListByCave(@PathVariable Long caveId) {
return ApiResponse.success(SuccessStatus.GET_SEED_LIST_BY_CAVE, seedService.getSeedListByCave(caveId));
}

@GetMapping("seed/list")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "SeedListGet", description = "전체 씨앗 리스트를 조회하는 API입니다.")
public ApiResponse<List<SeedListGetResponseDto>> getSeedList() {
return ApiResponse.success(SuccessStatus.GET_SEED_LIST, seedService.getSeedList());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(staticName = "of")
public class SeedListByCaveGetResponseDto {
public class SeedListGetResponseDto {
private Long seedId;
private String insight;
private Long remainingDays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface SeedRepository extends JpaRepository<Seed, Long> {
Optional<Seed> findSeedById(Long seedId);
List<Seed> findByCaveIdOrderByIdDesc(Long caveId);

List<Seed> findAllByOrderByIdDesc();

default Seed findSeedByIdOrThrow(Long seedId) {
return findSeedById(seedId)
.orElseThrow(()-> new NotFoundException(ErrorStatus.NOT_FOUND_SEED.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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.SeedListGetResponseDto;
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;
Expand Down Expand Up @@ -82,9 +82,17 @@ public SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequ
}

@Override
public List<SeedListByCaveGetResponseDto> getSeedListByCave(Long caveId) {
public List<SeedListGetResponseDto> getSeedListByCave(Long caveId) {
return seedRepository.findByCaveIdOrderByIdDesc(caveId).stream()
.map(seed -> SeedListByCaveGetResponseDto.of(seed.getId(), seed.getInsight(), calculateRemainingDays(seed.getLockDate()),
.map(seed -> SeedListGetResponseDto.of(seed.getId(), seed.getInsight(), calculateRemainingDays(seed.getLockDate()),
seed.getIsLocked(), seed.getIsScraped(), checkHasActionPlan(seed)))
.collect(Collectors.toList());
}

@Override
public List<SeedListGetResponseDto> getSeedList() {
return seedRepository.findAllByOrderByIdDesc().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
@@ -1,13 +1,11 @@
package com.example.growthookserver.api.seed.service;

import com.example.growthookserver.api.cave.dto.request.CaveCreateRequestDto;
import com.example.growthookserver.api.cave.dto.response.CaveCreateResponseDto;
import com.example.growthookserver.api.seed.dto.request.SeedCreateRequestDto;
import com.example.growthookserver.api.seed.dto.request.SeedMoveRequestDto;
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.SeedListGetResponseDto;
import com.example.growthookserver.api.seed.dto.response.SeedMoveResponseDto;
import java.util.List;

Expand All @@ -28,5 +26,8 @@ public interface SeedService {
SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequestDto);

//* 보관함별 씨앗 리스트 조회
List<SeedListByCaveGetResponseDto> getSeedListByCave(Long caveId);
List<SeedListGetResponseDto> getSeedListByCave(Long caveId);

//* 씨앗 전체 리스트 조회
List<SeedListGetResponseDto> getSeedList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum SuccessStatus {
GET_SEED_DETAIL(HttpStatus.OK, "씨앗 상세 정보 조회 성공"),
MOVE_SEED_SUCCESS(HttpStatus.OK, "씨앗 이동 성공"),
GET_SEED_LIST_BY_CAVE(HttpStatus.OK, "보관함별로 씨앗 리스트 조회 성공"),
GET_SEED_LIST(HttpStatus.OK, "전체 씨앗 리스트 조회 성공" ),

/**
* actionplan
Expand Down

0 comments on commit 6743546

Please sign in to comment.