Skip to content

Commit

Permalink
Merge pull request #49 from 28th-meetup/feat/registerFood
Browse files Browse the repository at this point in the history
feat: 메뉴 등록 api 필드 추가
  • Loading branch information
summit45 authored Nov 18, 2023
2 parents 97ee712 + a4e439e commit 95b2721
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/kusitms/jipbap/food/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public class Food extends DateEntity {
private Long canadaPrice;
private String image;
private String description;
private Long recommendCount;
private String foodPackage; // 배달포장 모두 가능, 배달 모두 가능, 포장 모두 가능

private String informationDescription; // 상품 정보 설명(이미지)
private String ingredient; //구성 성분(텍스트)
private Long recommendCount;

}
5 changes: 3 additions & 2 deletions src/main/java/com/kusitms/jipbap/food/FoodController.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public CommonResponse<CategoryDto> registerCategory(@RequestBody RegisterCategor
public CommonResponse<FoodDto> registerFood(
@Auth AuthInfo authInfo,
@RequestPart(value = "dto") RegisterFoodRequestDto dto,
@RequestPart(value = "image", required = false) MultipartFile image
@RequestPart(value = "image", required = false) MultipartFile image,
@RequestPart(value = "informationImage", required = false) MultipartFile informationDescriptionImage
) {
return new CommonResponse<>(foodService.registerFood(authInfo.getEmail(), dto, image));
return new CommonResponse<>(foodService.registerFood(authInfo.getEmail(), dto, image, informationDescriptionImage));
}

@Operation(summary = "메뉴 하나 상세조회")
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/kusitms/jipbap/food/FoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ public CategoryDto registerCategory(RegisterCategoryRequestDto dto) {
}

@Transactional
public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartFile image) {
public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartFile image, MultipartFile informationDescriptionImage) {
userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다."));
Store store = storeRepository.findById(dto.getStoreId()).orElseThrow(()-> new StoreNotExistsException("해당 가게 id는 유효하지 않습니다."));
Category category = categoryRepository.findById(dto.getCategoryId()).orElseThrow(()-> new CategoryNotExistsException("해당 카테고리 id는 유효하지 않습니다."));

String imageUri = null;
String informationDescriptionImageUri = null;

// 이미지가 null이 아닌 경우 s3 업로드
if(image!=null) {
Expand All @@ -71,6 +72,13 @@ public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartF
throw new S3RegisterFailureException("메뉴 이미지 저장 중 오류가 발생했습니다.");
}
}
if(informationDescriptionImageUri != null){
try {
informationDescriptionImageUri = S3Utils.saveFile(amazonS3, bucket, informationDescriptionImage);
} catch (IOException e) {
throw new S3RegisterFailureException("메뉴 설명 이미지 저장 중 오류가 발생했습니다.");
}
}

Food food = foodRepository.save(
Food.builder()
Expand All @@ -79,10 +87,12 @@ public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartF
.name(dto.getName())
.dollarPrice(dto.getDollarPrice())
.canadaPrice(dto.getCanadaPrice())
.description(dto.getDescription())
.recommendCount(0L)
.image(imageUri)
.description(dto.getDescription())
.foodPackage(dto.getFoodPackage())
.informationDescription(informationDescriptionImageUri)
.ingredient(dto.getIngredient())
.recommendCount(0L)
.build()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import java.util.List;

@Getter
Expand All @@ -17,13 +18,20 @@
@AllArgsConstructor
public class RegisterFoodRequestDto {

@NotBlank
private Long storeId;
@NotBlank
private Long categoryId;
@NotBlank
private String name;
private Long dollarPrice;
private Long canadaPrice;
@NotBlank
private String description;
private List<FoodOptionRequest> foodOptionRequestList;
@NotBlank
private String foodPackage;
@NotBlank
private String ingredient;

}

0 comments on commit 95b2721

Please sign in to comment.