Skip to content

Commit

Permalink
Merge pull request #74 from 28th-meetup/fix/typeChange
Browse files Browse the repository at this point in the history
fix: 가격 데이터타입을 double로 변경
  • Loading branch information
summit45 committed Nov 22, 2023
2 parents ddbcbde + 0f6dfea commit 9f430a9
Show file tree
Hide file tree
Showing 25 changed files with 147 additions and 123 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/kusitms/jipbap/food/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class Food extends DateEntity {
@Column(name = "food_name")
private String name;

private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
private String image;
private String description;
private String foodPackage; // 배달포장 모두 가능(ALL), 배달 가능(DELIVERY), 포장 가능(PACKAGE)
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/kusitms/jipbap/food/FoodOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class FoodOption {

private String name;

private Long dollarPrice;

private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;

}
76 changes: 26 additions & 50 deletions src/main/java/com/kusitms/jipbap/food/FoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ public CategoryDto registerCategory(RegisterCategoryRequestDto dto) {

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

Store store = storeRepository.findByOwner(user)
.orElseThrow(()-> new StoreNotExistsException("해당 가게 id는 유효하지 않습니다."));

Category category = categoryRepository.findById(dto.getCategoryId())
.orElseThrow(()-> new CategoryNotExistsException("해당 카테고리 id는 유효하지 않습니다."));

String imageUri = null;
String informationDescriptionImageUri = null;
Expand All @@ -90,8 +95,8 @@ public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartF
.store(store)
.category(category)
.name(dto.getName())
.dollarPrice(dto.getDollarPrice())
.canadaPrice(dto.getCanadaPrice())
.dollarPrice(roundToTwoDecimals(dto.getDollarPrice()))
.canadaPrice(roundToTwoDecimals(dto.getCanadaPrice()))
.image(imageUri)
.description(dto.getDescription())
.foodPackage(dto.getFoodPackage())
Expand All @@ -107,8 +112,8 @@ public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartF
FoodOption foodOption = FoodOption.builder()
.food(food)
.name(foodOptionRequest.getName())
.dollarPrice(foodOptionRequest.getDollarPrice())
.canadaPrice(foodOptionRequest.getCanadaPrice())
.dollarPrice(roundToTwoDecimals(foodOptionRequest.getDollarPrice()))
.canadaPrice(roundToTwoDecimals(foodOptionRequest.getCanadaPrice()))
.build();

foodOptionRepository.save(foodOption);
Expand All @@ -130,8 +135,8 @@ public FoodDetailResponse getFoodDetail(Long foodId) {
.storeName(food.getStore().getName())
.categoryId(food.getCategory().getId())
.name(food.getName())
.dollarPrice(food.getDollarPrice())
.canadaPrice(food.getCanadaPrice())
.dollarPrice(roundToTwoDecimals(food.getDollarPrice()))
.canadaPrice(roundToTwoDecimals(food.getCanadaPrice()))
.image(food.getImage())
.description(food.getDescription())
.foodPackage(food.getFoodPackage())
Expand Down Expand Up @@ -180,28 +185,13 @@ private List<FoodPreviewResponse> getBestSellingFoodByRegion(Long globalRegionId
food.getName(),
food.getStore().getId(),
food.getStore().getName(),
food.getDollarPrice(),
food.getCanadaPrice(),
roundToTwoDecimals(food.getDollarPrice()),
roundToTwoDecimals(food.getCanadaPrice()),
food.getImage(),
food.getStore().getAvgRate()
))
.collect(Collectors.toList());

// List<Food> bestSellingFoodsInRegionList = orderRepository.findTop10BestSellingFoodsInRegion(globalRegionId);
//
// List<FoodPreviewResponse> bestSellingFoodResponseList = bestSellingFoodsInRegionList.stream()
// .map(food -> new FoodPreviewResponse (
// food.getId(),
// food.getName(),
// food.getStore().getId(),
// food.getStore().getName(),
// food.getDollarPrice(),
// food.getCanadaPrice(),
// food.getImage(),
// food.getStore().getAvgRate()
// ))
// .collect(Collectors.toList());
//
return bestSellingFoodResponseList;
}

Expand All @@ -221,30 +211,14 @@ private List<FoodPreviewResponse> getLatestSellingFoodByRegion(Long globalRegion
food.getName(),
food.getStore().getId(),
food.getStore().getName(),
food.getDollarPrice(),
food.getCanadaPrice(),
roundToTwoDecimals(food.getDollarPrice()),
roundToTwoDecimals(food.getCanadaPrice()),
food.getImage(),
food.getStore().getAvgRate()
))
.collect(Collectors.toList());
return latestSellingFoodResponseList;

// List<Food> latestFoodsInRegionList = orderRepository.findLatestFoodsByRegionId(globalRegionId);
//
// List<FoodPreviewResponse> latestSellingFoodResponseList = latestFoodsInRegionList.stream()
// .map(food -> new FoodPreviewResponse(
// food.getId(),
// food.getName(),
// food.getStore().getId(),
// food.getStore().getName(),
// food.getDollarPrice(),
// food.getCanadaPrice(),
// food.getImage(),
// food.getStore().getAvgRate()
// ))
// .collect(Collectors.toList());
//
// return latestSellingFoodResponseList;
}

public List<FoodPreviewResponse> getFoodByCategory(AuthInfo authInfo, Long categoryId, SortingType sortingType){
Expand All @@ -257,7 +231,6 @@ public List<FoodPreviewResponse> getFoodByCategory(AuthInfo authInfo, Long categ

List<Food> foodList = foodRepository.findByStoreGlobalRegionAndCategory(globalRegion, category);

System.out.println("sortingType" + sortingType);
foodList = sortFoodList(foodList, sortingType);

List<FoodPreviewResponse> foodDtoList = foodList.stream()
Expand All @@ -266,8 +239,8 @@ public List<FoodPreviewResponse> getFoodByCategory(AuthInfo authInfo, Long categ
food.getName(),
food.getStore().getId(),
food.getStore().getName(),
food.getDollarPrice(),
food.getCanadaPrice(),
roundToTwoDecimals(food.getDollarPrice()),
roundToTwoDecimals(food.getCanadaPrice()),
food.getImage(),
food.getStore().getAvgRate()
))
Expand All @@ -285,21 +258,24 @@ private List<Food> sortFoodList(List<Food> foodList, SortingType sortingType) {
foodList.sort(Comparator.comparingDouble(food -> -food.getStore().getAvgRate()));
break;
case PRICE_HIGH:
foodList.sort(Comparator.comparingLong(Food::getDollarPrice).reversed());
foodList.sort(Comparator.comparingDouble(Food::getDollarPrice).reversed());
break;
case PRICE_LOW:
foodList.sort(Comparator.comparingLong(Food::getDollarPrice));
foodList.sort(Comparator.comparingDouble(Food::getDollarPrice));
break;
case RECENTLY_ADDED:
foodList.sort(Comparator.comparing(Food::getCreatedAt).reversed());
break;
default:
// 기본은 추천 순으로 정렬
// 추천 순으로 정렬할 기준이 없다면 아무 처리도 하지 않습니다.
foodList.sort(Comparator.comparingLong(Food::getRecommendCount).reversed());
break;
}
return foodList;
}

private double roundToTwoDecimals(double value) {
return Math.round(value * 100) / 100.0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class BestSellingFoodResponse {
private Long foodId;
private String name;
private String storeName;
private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
private Double avgRate;

public BestSellingFoodResponse(Long foodId, String name, String storeName, Double dollarPrice, Double canadaPrice, Double avgRate) {
this.foodId = foodId;
this.name = name;
this.storeName = storeName;
this.dollarPrice = roundToTwoDecimals(dollarPrice);
this.canadaPrice = roundToTwoDecimals(canadaPrice);
this.avgRate = roundToTwoDecimals(avgRate);
}

private double roundToTwoDecimals(double value) {
return Math.round(value * 100) / 100.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class FoodDetailByStoreResponse {
private Long id;
private Long categoryId;
private String name;
private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
private String description;
private Long recommendCount;
private String image;
Expand All @@ -25,10 +25,14 @@ public FoodDetailByStoreResponse(Food food){
this.id = food.getId();
this.categoryId = food.getCategory().getId();
this.name = food.getName();
this.dollarPrice = food.getDollarPrice();
this.canadaPrice = food.getCanadaPrice();
this.dollarPrice = roundToTwoDecimals(food.getDollarPrice());
this.canadaPrice = roundToTwoDecimals(food.getCanadaPrice());
this.description = food.getDescription();
this.recommendCount = food.getRecommendCount();
this.image = food.getImage();
}

private double roundToTwoDecimals(double value) {
return Math.round(value * 100) / 100.0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class FoodDetailResponse {
private String storeName;
private Long categoryId;
private String name;
private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
private String image;
private String description;
private String foodPackage;
private String informationDescription;
private String ingredient;
private Long minOrderAmount; // 최소 주문 금액 추가
private Double minOrderAmount; // 최소 주문 금액 추가
private List<FoodOptionResponse> foodOptionResponseList;
}
4 changes: 2 additions & 2 deletions src/main/java/com/kusitms/jipbap/food/dto/FoodDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class FoodDto {
private Long storeId;
private Long categoryId;
private String name;
private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
private String description;
private String image;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class FoodOptionRequest {
private String name;

private Long dollarPrice;
private Double dollarPrice;

private Long canadaPrice;
private Double canadaPrice;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
public class FoodOptionResponse {
private Long id;
private String name;
private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class FoodPreviewResponse {
private String name;
private Long storeId;
private String storeName;
private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
private String image;
private Double avgRate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class RegisterFoodRequestDto {
private Long categoryId;
@NotBlank
private String name;
private Long dollarPrice;
private Long canadaPrice;
private Double dollarPrice;
private Double canadaPrice;
@NotBlank
private String description;
private List<FoodOptionRequest> foodOptionRequestList;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kusitms/jipbap/order/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Order extends DateEntity {
private Store store;

@NotNull
private Long totalPrice; //총 주문 결제 금액
private Double totalPrice; //총 주문 결제 금액
private Long totalCount; //총 주문한 메뉴 개수

@NotNull
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kusitms/jipbap/order/OrderDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class OrderDetail {
private Long orderCount; //품목 개수

@NotNull
private Long orderAmount; //품목당 가격
private Double orderAmount; //품목당 가격

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/kusitms/jipbap/order/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class OrderService {
private final UserRepository userRepository;
private final FoodRepository foodRepository;
private final FoodOptionRepository foodOptionRepository;
private final NotificationRepository notificationRepository;
private final StoreRepository storeRepository;
private final FCMNotificationService fcmNotificationService;

Expand All @@ -47,12 +46,11 @@ public OrderFoodResponse orderFood(String email, OrderFoodRequest dto) {
.orElseThrow(() -> new UserNotFoundException("해당 유저를 찾을 수 없습니다."));
Store store = storeRepository.findById(dto.getStore())
.orElseThrow(()-> new StoreNotExistsException("해당 가게는 존재하지 않습니다."));

Order order = orderRepository.save(
Order.builder()
.user(user)
.store(store)
.totalPrice(dto.getTotalPrice())
.totalPrice(roundToTwoDecimals(dto.getTotalPrice()))
.totalCount(dto.getTotalCount())
.regionId(user.getGlobalRegion().getId())
.selectedOption(dto.getSelectedOption())
Expand All @@ -76,6 +74,7 @@ public OrderFoodResponse orderFood(String email, OrderFoodRequest dto) {
public List<OrderDetail> saveOrderFoodDetail(Long orderId, List<OrderFoodDetailRequest> orderFoodDetailList) {
Order order = orderRepository.findById(orderId)
.orElseThrow(() -> new OrderNotFoundException("주문 아이디를 찾을 수 없습니다."));

return orderFoodDetailList.stream()
.map(item -> {
Food food = foodRepository.findById(item.getFoodId())
Expand All @@ -86,7 +85,7 @@ public List<OrderDetail> saveOrderFoodDetail(Long orderId, List<OrderFoodDetailR
.food(food)
.foodOption(foodOption) // 수정
.orderCount(item.getOrderCount())
.orderAmount(item.getOrderAmount())
.orderAmount(roundToTwoDecimals(item.getOrderAmount()))
.order(order)
.build();
orderDetailRepository.save(orderDetail);
Expand All @@ -104,7 +103,6 @@ public OrderDto getOrderDetail(Long orderId) {
public OwnerOrderStatusResponse getStoreOrderHistoryByOrderStatus(String email, String orderStatus) {
User user = userRepository.findByEmail(email)
.orElseThrow(() -> new UserNotFoundException("해당 유저를 찾을 수 없습니다."));

Store store = storeRepository.findByOwner(user)
.orElseThrow(() -> new StoreNotExistsException("해당 유저의 가게를 찾을 수 없습니다."));

Expand Down Expand Up @@ -148,7 +146,6 @@ public void processOrder(String email, Long orderId, String status) {
FCMRequestDto dto = new FCMRequestDto(buyer.getId(), "가게가 주문을 수락했습니다.", "맛있는 한식 집밥이 곧 찾아갑니다!");
String ans = fcmNotificationService.sendNotificationByToken(dto);
log.info("판매자가 주문을 수락, 구매자에게 알림 전송 결과: " + ans);

}
else if(newStatus.equals(OrderStatus.REJECTED)) { //판매자가 주문을 취소함
FCMRequestDto dto = new FCMRequestDto(buyer.getId(), "가게가 주문을 취소했습니다.", "다른 상품을 주문해 주세요.");
Expand Down Expand Up @@ -220,4 +217,8 @@ public StoreProcessingResponse getStoreProcessingOrder(String email) {
}
return new StoreProcessingResponse(orderList.size(), processingFoodResponseList);
}

private double roundToTwoDecimals(double value) {
return Math.round(value * 100) / 100.0;
}
}
Loading

0 comments on commit 9f430a9

Please sign in to comment.