Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] swagger 설명 추가 및 DTO 재료 id 추가 #88

Merged
merged 5 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package umc.IRECIPE_Server.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -36,6 +42,13 @@ public class IngredientController {

//재료추가
@PostMapping(value = "/", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
@Operation(summary = "냉장고 재료 추가 API",description = "냉장고에 재료를 추가하는 API입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
public ApiResponse<IngredientResponse.addResultDTO> addIngredient(@RequestPart("request") IngredientRequest.addDTO request)
{
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Expand All @@ -47,20 +60,50 @@ public ApiResponse<IngredientResponse.addResultDTO> addIngredient(@RequestPart("

//재료 상세정보 조회
@GetMapping("/{ingredientId}")
@Operation(summary = "재료 정보 상세 조회 API",description = "재료 클릭시 상세 정보를 조회하는 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
@Parameters({
@Parameter(name = "ingredientId", description = "재료의 아이디, path variable 입니다!")
})
public ApiResponse<IngredientResponse.findOneResultDTO> findOne(@PathVariable(name = "ingredientId") Long ingredientId) {
Ingredient ingredient = ingredientQueryService.findOne(ingredientId);
return ApiResponse.onSuccess(IngredientConverter.toFindOneResultDTO(ingredient));
}

//재료 삭제
@DeleteMapping("/{ingredientId}")
@Operation(summary = "재료 삭제 API",description = "재료를 삭제하는 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
@Parameters({
@Parameter(name = "ingredientId", description = "재료의 아이디, path variable 입니다!")
})
public ApiResponse<IngredientResponse.deleteResultDTO> deleteIngredient(@PathVariable(name = "ingredientId") Long ingredientId) {
ingredientQueryService.delete(ingredientId);
return ApiResponse.onSuccess(IngredientConverter.toDeleteResultDTO());
}

//재료 수정
@PatchMapping("/{ingredientId}")
@Operation(summary = "재료 정보 수정 조회 API",description = "재료 정보를 수정하는 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
@Parameters({
@Parameter(name = "ingredientId", description = "재료의 아이디, path variable 입니다!")
})
public ApiResponse<IngredientResponse.updateResultDTO> updateIngredient(
@RequestBody @Valid IngredientRequest.updateDTO request,
@PathVariable(name = "ingredientId") Long ingredientId) {
Expand All @@ -71,6 +114,13 @@ public ApiResponse<IngredientResponse.updateResultDTO> updateIngredient(

//재료 전체 조회
@GetMapping("/")
@Operation(summary = "재료 전체 조회 API",description = "냉장고 메인 화면 전체 재료 조회하는 API, query String 으로 page 번호를 주세요")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
public ApiResponse<IngredientResponse.findAllResultListDTO> findAll(@RequestParam(name = "page") Integer page) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String userId = authentication.getName();
Expand All @@ -81,6 +131,13 @@ public ApiResponse<IngredientResponse.findAllResultListDTO> findAll(@RequestPara

//보관 방법별 재료 리스트 조회
@GetMapping("/types")
@Operation(summary = "보관 방법별 재료 리스트 조회 API",description = "보관 방법별로 재료를 조회하는 API, query String 으로 page 번호, 보관 방법을 주세요")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
public ApiResponse<IngredientResponse.findAllResultListDTO> findRefrigeratedList(@RequestParam(name = "page") Integer page,
@RequestParam(name = "type") Type type
) {
Expand All @@ -93,6 +150,13 @@ public ApiResponse<IngredientResponse.findAllResultListDTO> findRefrigeratedList

//재료 이름 검색
@GetMapping("/search")
@Operation(summary = "재료 이름 검색 API",description = "이름으로 냉장고 내 재료를 검색하는 API, query String 으로 page 번호, 검색어를 주세요")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
public ApiResponse<IngredientResponse.findAllResultListDTO> searchIngredient(@RequestParam(name = "name") String name,
@RequestParam(name = "page") Integer page) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Expand All @@ -103,6 +167,13 @@ public ApiResponse<IngredientResponse.findAllResultListDTO> searchIngredient(@Re
}

@GetMapping("/expire")
@Operation(summary = "유통기한 만료일 순 재료 조회 API",description = "유통기한이 얼마 안남은 순으로 재료 리스트 조회하는 API, query String 으로 page 번호를 주세요")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH003", description = "access 토큰을 주세요!",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH004", description = "acess 토큰 만료",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "AUTH006", description = "acess 토큰 모양이 이상함",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
public ApiResponse<IngredientResponse.findAllResultListDTO> findNearingExpirationIngredient(@RequestParam(name = "page") Integer page) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String userId = authentication.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static Ingredient toIngredient(Member member, IngredientRequest.addDTO re
public static IngredientResponse.findOneResultDTO toFindOneResultDTO(Ingredient ingredient) {

return IngredientResponse.findOneResultDTO.builder()
.ingredientId(ingredient.getIngredientId())
.name(ingredient.getName())
.memo(ingredient.getMemo())
.category(ingredient.getCategory())
Expand Down Expand Up @@ -66,6 +67,7 @@ public static IngredientResponse.findAllResultListDTO toFindAllResultListDTO(Pag
private static IngredientResponse.findIngredientResultDTO toFindIngredientResultDTO(Ingredient ingredient) {

return IngredientResponse.findIngredientResultDTO.builder()
.ingredientId(ingredient.getIngredientId())
.name(ingredient.getName())
.memo(ingredient.getMemo())
.category(ingredient.getCategory())
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/umc/IRECIPE_Server/dto/IngredientRequest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package umc.IRECIPE_Server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -13,27 +14,39 @@

public class IngredientRequest {

@Schema(description = "냉장고 재료 추가 DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class addDTO{
@Schema(description = "재료 이름", defaultValue = "소고기")
String name;
@Schema(description = "재료 카테고리", defaultValue = "MEAT")
IngredientCategory category;
@Schema(description = "재료 메모", defaultValue = "빨리 먹어야 함")
String memo;
@Schema(description = "재료 보관방법", defaultValue = "FROZEN")
Type type;
@Schema(description = "재료 유통기한", defaultValue = "2025-02-09")
LocalDate expiryDate;
}

@Schema(description = "냉장고 재료 수정 DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class updateDTO{
@Schema(description = "재료 이름", defaultValue = "소고기")
String name;
@Schema(description = "재료 카테고리", defaultValue = "MEAT")
IngredientCategory category;
@Schema(description = "재료 메모", defaultValue = "빨리 먹어야 함")
String memo;
@Schema(description = "재료 보관방법", defaultValue = "FROZEN")
Type type;
@Schema(description = "재료 유통기한", defaultValue = "2025-02-09")
LocalDate expiryDate;
}

Expand Down
37 changes: 36 additions & 1 deletion src/main/java/umc/IRECIPE_Server/dto/IngredientResponse.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package umc.IRECIPE_Server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.IRECIPE_Server.common.enums.IngredientCategory;
import umc.IRECIPE_Server.common.enums.Type;
import umc.IRECIPE_Server.dto.response.PostResponseDTO;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -14,67 +16,100 @@

public class IngredientResponse {

@Schema(description = "냉장고 재료 추가 DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class addResultDTO{
@Schema(description = "재료 아이디", defaultValue = "1")
Long ingredientId;
@Schema(description = "재료 생성일시")
LocalDateTime createdAt;
}
@Schema(description = "재료 상세 정보 조회 DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class findOneResultDTO{
@Schema(description = "재료 아이디", defaultValue = "1")
Long ingredientId;
@Schema(description = "재료 이름", defaultValue = "소고기")
String name;
@Schema(description = "재료 카테고리", defaultValue = "MEAT")
IngredientCategory category;
@Schema(description = "재료 메모", defaultValue = "빨리 먹어야 함")
String memo;
@Schema(description = "재료 보관방법", defaultValue = "FROZEN")
Type type;
@Schema(description = "재료 유통기한", defaultValue = "2025-02-09")
LocalDate expiryDate;
@Schema(description = "유통기한까지 남은 일 수", defaultValue = "10")
Integer remainingDays;
}

@Schema(description = "재료 정보 수정 DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class updateResultDTO{
@Schema(description = "재료 아이디", defaultValue = "1")
Long ingredientId;
@Schema(description = "수정 일시")
LocalDateTime updatedAt;
}

@Schema(description = "냉장고 재료 삭제 DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class deleteResultDTO{
@Schema(description = "완료 메세지", defaultValue = "삭제 완료")
String message;
}

@Schema(description = "냉장고 재료 조회 DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class findIngredientResultDTO{
@Schema(description = "재료 아이디", defaultValue = "1")
Long ingredientId;
@Schema(description = "재료 이름", defaultValue = "소고기")
String name;
@Schema(description = "재료 카테고리", defaultValue = "MEAT")
IngredientCategory category;
@Schema(description = "재료 메모", defaultValue = "빨리 먹어야 함")
String memo;
@Schema(description = "재료 보관방법", defaultValue = "FROZEN")
Type type;
@Schema(description = "재료 유통기한", defaultValue = "2025-02-09")
LocalDate expiryDate;
@Schema(description = "유통기한까지 남은 일 수", defaultValue = "10")
Integer remainingDays;
}

@Schema(description = "조회 리스트 정보DTO")
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class findAllResultListDTO{
List<findIngredientResultDTO> ingredientList;
@Schema(description = "게시글 리스트")
List<PostResponseDTO.getRankedPostDTO> postList;
@Schema(description = "리스트 사이즈", defaultValue = "1")
Integer listSize;
@Schema(description = "전체 페이지 갯수", defaultValue = "1")
Integer totalPage;
@Schema(description = "전체 데이터 갯수", defaultValue = "10")
Long totalElements;
@Schema(description = "첫 페이지면 true", defaultValue = "true")
Boolean isFirst;
@Schema(description = " 마지막 페이지면 true", defaultValue = "true")
Boolean isLast;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public static class getRankedPostDTO {

@Schema(description = "게시글 한달 평균 별점", defaultValue = "4.3")
private Float scoresInOneMonth;

}

@Schema(description = "이달의 랭킹 게시글 리스트 DTO")
Expand All @@ -214,11 +215,17 @@ public static class getRankedPostDTO {
@NoArgsConstructor
@AllArgsConstructor
public static class findAllResultListDTO{
@Schema(description = "게시글 리스트")
List<PostResponseDTO.getRankedPostDTO> postList;
@Schema(description = "리스트 사이즈", defaultValue = "1")
Integer listSize;
@Schema(description = "전체 페이지 갯수", defaultValue = "1")
Integer totalPage;
@Schema(description = "전체 데이터 갯수", defaultValue = "10")
Long totalElements;
@Schema(description = "첫 페이지면 true", defaultValue = "true")
Boolean isFirst;
@Schema(description = " 마지막 페이지면 true", defaultValue = "true")
Boolean isLast;
}
}