Skip to content

Commit

Permalink
feat: 진행 중 주문, 오늘 중 주문 api 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
summit45 committed Nov 22, 2023
1 parent 998d934 commit 747759a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ public CommonResponse<List<OrderHistoryResponse>> getMyOrderHistory(@Auth AuthIn
public CommonResponse<StoreProcessingResponse> getStoreProcessingOrder(@Auth AuthInfo authInfo) {
return new CommonResponse<>(orderService.getStoreProcessingOrder(authInfo.getEmail()));
}

}
7 changes: 7 additions & 0 deletions src/main/java/com/kusitms/jipbap/order/OrderRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

Expand All @@ -15,4 +16,10 @@ public interface OrderRepository extends JpaRepository <Order, Long> {

Optional<List<Order>> findByUser_Id(Long userId);

@Query("SELECT COUNT(o) FROM Order o WHERE DATE(o.createdAt) = :date")
Long countOrdersByDate(@Param("date") LocalDate date);

@Query("SELECT COUNT(o) FROM Order o WHERE o.status = :status")
Long countOrdersByStatus(@Param("status") OrderStatus status);

}
7 changes: 7 additions & 0 deletions src/main/java/com/kusitms/jipbap/store/StoreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,11 @@ public CommonResponse<StoreInfoResponse> getStoreInfoDetail(@Auth AuthInfo authI
return new CommonResponse<>(storeService.getStoreInfoDetail(authInfo.getEmail(), storeId));
}

@Operation(summary = "주문관리에서 진행 중 주문과 오늘 총 주문 조회하기")
@GetMapping("/manage")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<StoreManageResponse> getStoreManageOrder(@Auth AuthInfo authInfo) {
return new CommonResponse<>(storeService.getStoreManageOrder(authInfo.getEmail()));
}

}
20 changes: 20 additions & 0 deletions src/main/java/com/kusitms/jipbap/store/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.kusitms.jipbap.common.utils.S3Utils;
import com.kusitms.jipbap.food.dto.FoodDto;
import com.kusitms.jipbap.food.dto.FoodPreviewResponse;
import com.kusitms.jipbap.order.OrderRepository;
import com.kusitms.jipbap.order.OrderStatus;
import com.kusitms.jipbap.store.dto.*;
import com.kusitms.jipbap.store.exception.StoreExistsException;
import com.kusitms.jipbap.store.exception.StoreNotExistsException;
Expand All @@ -27,6 +29,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -41,6 +44,7 @@ public class StoreService {
private final UserRepository userRepository;
private final FoodRepository foodRepository;
private final GlobalRegionRepository globalRegionRepository;
private final OrderRepository orderRepository;

private final AmazonS3 amazonS3;

Expand Down Expand Up @@ -256,6 +260,22 @@ public StoreInfoResponse getStoreInfoDetail(String email, Long storeId){
);
}

public StoreManageResponse getStoreManageOrder(String email){
User user = userRepository.findByEmail(email)
.orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다."));
Store store = storeRepository.findByOwner(user)
.orElseThrow(()-> new StoreNotExistsException("가게 정보가 존재하지 않습니다."));

OrderStatus orderStatus = OrderStatus.ACCEPTED;
Long processingOrderCount = orderRepository.countOrdersByStatus(orderStatus);
Long todayOrderCount = orderRepository.countOrdersByDate(LocalDate.now());


return new StoreManageResponse(
processingOrderCount,
todayOrderCount
);
}
private double roundToTwoDecimals(double value) {
return Math.round(value * 100) / 100.0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kusitms.jipbap.store.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class StoreManageResponse {
private Long processingOrderCount;
private Long todayOrderCount;
}

0 comments on commit 747759a

Please sign in to comment.