Skip to content

Commit

Permalink
Merge pull request #181 from DuruDuru-UMC-7th/feature/#72-ingredient-…
Browse files Browse the repository at this point in the history
…manual-api

Feat: 식재료 소비기한 등록 API 구현
  • Loading branch information
ParkJh38 authored Feb 12, 2025
2 parents 2d915b4 + 5fb72f3 commit 884dff5
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers("trade/like/{trade_id}", "/trade/like/{trade_id}/delete", "/trade/like/{trade_id}/count").permitAll()
.requestMatchers("trade/other-trade", "/trade/keyword/alert").permitAll()
// Ingredient 관련 접근
.requestMatchers("/ingredient/{ingredient_id}/photo","/ingredient/{ingredient_id}/purchase-date", "/ingredient/").permitAll()
.requestMatchers("/ingredient/{ingredient_id}/photo","/ingredient/{ingredient_id}/purchase-date", "/ingredient/{ingredient_id}/expiry-date","/ingredient/").permitAll()
.requestMatchers("/ingredient/{ingredient_id}","/ingredient/{ingredient_id}/category", "/ingredient/{ingredient_id}/storage-type").permitAll()
.requestMatchers("/ingredient/search/name", "/ingredient/category/major-to-minor").permitAll()
.requestMatchers("/ingredient/majorCategory/list", "/ingredient/minorCategory/list", "/ingredient/minorCategory/").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public static IngredientResponseDTO.PurchaseDateResultDTO toPurchaseDateResultDT
.build();
}

public static IngredientResponseDTO.ExpiryDateResultDTO toExpiryDateResultDTO(Ingredient ingredient) {
return IngredientResponseDTO.ExpiryDateResultDTO.builder()
.memberId(ingredient.getMember().getMemberId())
.ingredientId(ingredient.getIngredientId())
.ingredientName(ingredient.getIngredientName())
.fridgeId(ingredient.getFridge().getFridgeId())
.purchaseDate(ingredient.getPurchaseDate())
.expiryDate(ingredient.getExpiryDate())
.build();
}

public static IngredientResponseDTO.StorageTypeResultDTO toStorageTypeResultDTO(Ingredient ingredient) {
return IngredientResponseDTO.StorageTypeResultDTO.builder()
.memberId(ingredient.getMember().getMemberId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IngredientCommandService {
void deleteIngredient(Long memberId, Long ingredientId);

Ingredient registerPurchaseDate(Long memberId, Long ingredientId, IngredientRequestDTO.PurchaseDateRequestDTO request);
Ingredient registerExpiryDate(Long memberId, Long ingredientId, IngredientRequestDTO.ExpiryDateRequestDTO request);
Ingredient setStorageType(Long memberId, Long ingredientId, IngredientRequestDTO.StorageTypeRequestDTO request);

Ingredient registerIngredientImage(Long memberId, Long ingredientId, IngredientRequestDTO.IngredientImageRequestDTO request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void deleteIngredient(Long memberId, Long ingredientId) {
ingredientRepository.delete(ingredient);
}


@Override
public Ingredient registerPurchaseDate(Long memberId, Long ingredientId, IngredientRequestDTO.PurchaseDateRequestDTO request) {
Member member = findMemberById(memberId);
Expand All @@ -97,6 +96,15 @@ public Ingredient registerPurchaseDate(Long memberId, Long ingredientId, Ingredi
return ingredient;
}

@Override
public Ingredient registerExpiryDate(Long memberId, Long ingredientId, IngredientRequestDTO.ExpiryDateRequestDTO request) {
Member member = findMemberById(memberId);
Ingredient ingredient = findIngredientById(ingredientId);

ingredient.setExpiryDate(request.getExpiryDate());
return ingredient;
}

@Override
public Ingredient setStorageType(Long memberId, Long ingredientId, IngredientRequestDTO.StorageTypeRequestDTO request) {
Member member = findMemberById(memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public ApiResponse<IngredientResponseDTO.IngredientImageDTO> updateIngredientPho
return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, IngredientConverter.toIngredientImageDTO(ingredient));
}


// 식재료 카테고리 설정
@PostMapping("/{ingredient_id}/category")
@Operation(summary = "식재료 카테고리 설정 API", description = "식재료의 대분류와 소분류를 설정하는 API 입니다.")
Expand All @@ -56,7 +55,6 @@ public ApiResponse<?> setIngredientCategory(@RequestParam Long memberId,
return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, IngredientConverter.toSetCategoryResultDTO(ingredient));
}


// 식재료 보관 방식 설정
@PostMapping("/{ingredient_id}/storage-type")
@Operation(summary = "식재료 보관 방식 설정 API", description = "식재료의 보관 방식을 설정하는 API 입니다.")
Expand All @@ -66,7 +64,6 @@ public ApiResponse<IngredientResponseDTO.StorageTypeResultDTO> ingredientStorage
return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, IngredientConverter.toStorageTypeResultDTO(ingredient));
}


// 식재료 구매 날짜 등록
@PostMapping("/{ingredient_id}/purchase-date")
@Operation(summary = "식재료 구매 날짜 등록 API", description = "식재료의 구매 날짜를 등록하는 API 입니다.")
Expand All @@ -76,7 +73,14 @@ public ApiResponse<IngredientResponseDTO.PurchaseDateResultDTO> registerPurchase
return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, IngredientConverter.toPurchaseDateResultDTO(ingredient));
}


// 식재료 소비기한 등록
@PostMapping("/{ingredient_id}/expiry-date")
@Operation(summary = "식재료 소비기한 등록 API", description = "식재료의 소비기한을 등록하는 API 입니다.")
public ApiResponse<IngredientResponseDTO.ExpiryDateResultDTO> registerExpiryDate(@RequestParam Long memberId, @PathVariable("ingredient_id") Long ingredientId,
@RequestBody IngredientRequestDTO.ExpiryDateRequestDTO request){
Ingredient ingredient = ingredientCommandService.registerExpiryDate(memberId, ingredientId, request);
return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, IngredientConverter.toExpiryDateResultDTO(ingredient));
}

// 식재료 직접 등록
@PostMapping("/")
Expand All @@ -87,7 +91,6 @@ public ApiResponse<IngredientResponseDTO.CreateRawIngredientResultDTO> ingredien
return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, IngredientConverter.toCreateResultDTO(newIngredient));
}


// 식재료 정보 수정
@PatchMapping("/{ingredient_id}")
@Operation(summary = "식재료 정보 수정 API", description = "식재료의 정보를 수정하는 API 입니다.")
Expand All @@ -97,7 +100,6 @@ public ApiResponse<IngredientResponseDTO.UpdateIngredientResultDTO> updateIngred
IngredientConverter.UpdateIngredientResultDTO(ingredientCommandService.updateIngredient(memberId, ingredientId, request)));
}


// 식재료 삭제
@DeleteMapping("/{ingredient_id}")
@Operation(summary = "식재료 삭제 API", description = "식재료를 삭제하는 API 입니다.")
Expand All @@ -106,7 +108,6 @@ public ApiResponse<?> deleteIngredient(@RequestParam Long memberId, @PathVariabl
return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, null);
}


// 식재료 이름으로 검색
@GetMapping("/search/name")
@Operation(summary = "식재료 이름으로 검색 API", description = "식재료를 이름으로 검색하는 API 입니다. 입력된 키워드가 포함된 식재료를 모두 반환합니다.")
Expand Down Expand Up @@ -200,12 +201,4 @@ public ApiResponse<IngredientResponseDTO.MajorCategoryIngredientPreviewListDTO>
// return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, null);
// }


// // 식재료 소비기한 등록 (자동 계산 포함)
// @PostMapping("/{ingredient_id}/expiry-date")
// @Operation(summary = "식재료 소비기한 등록 API", description = "식재료의 소비기한을 등록하는 API 입니다.")
// public ApiResponse<?> ingredientExpiryDate(){
// return ApiResponse.onSuccess(SuccessStatus.INGREDIENT_OK, null);
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public static class PurchaseDateRequestDTO {
private LocalDate purchaseDate;
}

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class ExpiryDateRequestDTO {
private LocalDate expiryDate;
}

@Getter
@Setter
@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ public static class PurchaseDateResultDTO {
LocalDate purchaseDate;
}

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class ExpiryDateResultDTO {
Long memberId;
Long fridgeId;
Long ingredientId;
String ingredientName;
LocalDate purchaseDate;
LocalDate expiryDate;
}



@Getter
@Builder
@AllArgsConstructor
Expand Down

0 comments on commit 884dff5

Please sign in to comment.