Skip to content

Commit

Permalink
Merge pull request #56 from Team-Growthook/feat/#52-all-seed-list-get…
Browse files Browse the repository at this point in the history
…-api

[FEAT] 전체 씨앗 리스트 조회 API
  • Loading branch information
yeseul106 authored Jan 4, 2024
2 parents 9e8256f + 823f23f commit 2d112f0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto;
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 @@ -16,7 +16,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 @@ -69,10 +68,17 @@ 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());
}

@GetMapping("member/{memberId}/alarm")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "SeedAlarm", description = "기한이 3일 이내로 남은 씨앗에 대한 알림을 조회하는 API입니다.")
Expand Down
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 @@ -11,7 +11,7 @@
import com.example.growthookserver.api.seed.dto.response.SeedAlarmGetResponseDto;
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 @@ -86,9 +86,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,14 +1,12 @@
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.SeedAlarmGetResponseDto;
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 @@ -31,7 +29,10 @@ public interface SeedService {
SeedMoveResponseDto moveSeed(Long seedId, SeedMoveRequestDto seedMoveRequestDto);

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

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

//* 씨앗 알림 조회
SeedAlarmGetResponseDto getSeedAlarm(Long memberId);
Expand Down
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, "전체 씨앗 리스트 조회 성공" ),
GET_SEED_ALARM(HttpStatus.OK,"씨앗 알람 조회 성공"),

/**
Expand Down

0 comments on commit 2d112f0

Please sign in to comment.