Skip to content

Commit

Permalink
Refactor: 소비기한 계산시 구매 날짜가 등록되지 않으면 발생하는 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkJh38 committed Feb 2, 2025
1 parent c152632 commit 919cb28
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ private Ingredient createAndSaveIngredient(String productName, Member member, Fr
int shelfLifeDays = minorCategory.getShelfLifeDays();
StorageType storageType = minorCategory.getStorageType();

LocalDate purchaseDate = (receipt.getPurchaseDate() != null) ? receipt.getPurchaseDate() : LocalDate.now();
LocalDate expiryDate = purchaseDate.plusDays(shelfLifeDays);

Ingredient ingredient = Ingredient.builder()
.member(member)
Expand All @@ -299,10 +301,11 @@ private Ingredient createAndSaveIngredient(String productName, Member member, Fr
.minorCategory(minorCategory != null ? minorCategory : MinorCategory.기타)
.storageType(storageType)
.count(1L)
.purchaseDate(receipt.getPurchaseDate())
.expiryDate(receipt.getPurchaseDate().plusDays(shelfLifeDays))
.purchaseDate(purchaseDate)
.expiryDate(expiryDate)
.receipt(receipt)
.build();

return ingredientRepository.save(ingredient);
}

Expand Down

0 comments on commit 919cb28

Please sign in to comment.