diff --git a/src/main/java/com/jangburich/domain/menu/service/MenuService.java b/src/main/java/com/jangburich/domain/menu/service/MenuService.java index 62da9dc..efc8b28 100644 --- a/src/main/java/com/jangburich/domain/menu/service/MenuService.java +++ b/src/main/java/com/jangburich/domain/menu/service/MenuService.java @@ -1,7 +1,5 @@ package com.jangburich.domain.menu.service; -import java.util.List; - import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -9,14 +7,13 @@ import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.MenuCreateRequestDTO; -import com.jangburich.domain.menu.domain.MenuGetResponseDTO; import com.jangburich.domain.menu.domain.MenuResponse; import com.jangburich.domain.menu.domain.MenuUpdateRequestDTO; import com.jangburich.domain.menu.repository.MenuRepository; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.store.domain.Store; -import com.jangburich.domain.store.domain.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreRepository; import com.jangburich.domain.user.domain.User; import com.jangburich.domain.user.repository.UserRepository; import com.jangburich.global.error.DefaultNullPointerException; diff --git a/src/main/java/com/jangburich/domain/order/application/OrderService.java b/src/main/java/com/jangburich/domain/order/application/OrderService.java index ecc4f4b..0b2ec5b 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -14,8 +14,8 @@ import com.jangburich.domain.order.dto.response.CartResponse; import com.jangburich.domain.order.dto.response.GetCartItemsResponse; import com.jangburich.domain.store.domain.Store; -import com.jangburich.domain.store.domain.repository.StoreRepository; -import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.store.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; import com.jangburich.domain.user.domain.User; diff --git a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java index 12083d2..1120175 100644 --- a/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java +++ b/src/main/java/com/jangburich/domain/order/domain/repository/CartRepository.java @@ -2,6 +2,7 @@ import com.jangburich.domain.common.Status; import com.jangburich.domain.order.domain.Cart; +import com.jangburich.domain.order.domain.Orders; import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.user.domain.User; import java.util.List; @@ -19,4 +20,6 @@ public interface CartRepository extends JpaRepository { List findAllByUserAndStatus(User user, Status status); List findAllByUserAndStoreAndStatus(User user, Store store, Status status); + + List findAllByOrders(Orders orders); } diff --git a/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java b/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java index b1e47b8..dbfa9bc 100644 --- a/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java +++ b/src/main/java/com/jangburich/domain/order/domain/repository/OrdersRepository.java @@ -1,9 +1,38 @@ package com.jangburich.domain.order.domain.repository; +import java.time.LocalDateTime; +import java.util.List; + +import com.jangburich.domain.order.domain.OrderStatus; import com.jangburich.domain.order.domain.Orders; +import com.jangburich.domain.store.domain.Store; + +import org.aspectj.weaver.ast.Or; +import org.hibernate.query.Order; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; @Repository public interface OrdersRepository extends JpaRepository { + @Query(value = "SELECT * FROM orders WHERE store_id = :storeId AND updated_at < :updatedAt AND order_status = :orderStatus", + nativeQuery = true) + List findOrdersByStoreAndDateAndStatusNative( + @Param("storeId") Long storeId, + @Param("updatedAt") LocalDateTime updatedAt, + @Param("orderStatus") String orderStatus); + + @Query("SELECT o FROM Orders o " + + "WHERE o.store.id = :storeId " + + "AND o.updatedAt >= :startOfDay " + + "AND o.updatedAt < :endOfDay " + + "AND o.orderStatus = :orderStatus") + List findOrdersByStoreAndTodayDateAndStatus( + @Param("storeId") Long storeId, + @Param("startOfDay") LocalDateTime startOfDay, + @Param("endOfDay") LocalDateTime endOfDay, + @Param("orderStatus") OrderStatus orderStatus); + + } diff --git a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java index 4f47145..4a153e6 100644 --- a/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java +++ b/src/main/java/com/jangburich/domain/payment/application/KakaopayService.java @@ -20,8 +20,8 @@ import com.jangburich.domain.payment.exception.TeamNotFoundException; import com.jangburich.domain.store.domain.Store; import com.jangburich.domain.store.domain.StoreTeam; -import com.jangburich.domain.store.domain.repository.StoreRepository; -import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.store.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.store.exception.StoreNotFoundException; import com.jangburich.domain.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; diff --git a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java b/src/main/java/com/jangburich/domain/store/controller/StoreController.java similarity index 69% rename from src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java rename to src/main/java/com/jangburich/domain/store/controller/StoreController.java index b25685f..91b8fbf 100644 --- a/src/main/java/com/jangburich/domain/store/domain/controller/StoreController.java +++ b/src/main/java/com/jangburich/domain/store/controller/StoreController.java @@ -1,4 +1,6 @@ -package com.jangburich.domain.store.domain.controller; +package com.jangburich.domain.store.controller; + +import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -22,11 +24,14 @@ import com.jangburich.domain.store.domain.StoreGetResponseDTO; import com.jangburich.domain.store.domain.StoreTeamResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.PaymentGroupDetailResponse; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; -import com.jangburich.domain.store.domain.service.StoreService; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.OrdersDetailResponse; +import com.jangburich.domain.store.dto.response.OrdersGetResponse; +import com.jangburich.domain.store.dto.response.OrdersTodayResponse; +import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.service.StoreService; import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; import com.jangburich.utils.parser.AuthenticationParser; @@ -67,21 +72,17 @@ public ResponseCustom> searchStores( @Operation(summary = "가게 등록", description = "신규 파트너 가게를 등록합니다.") @PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public ResponseCustom createStore( - Authentication authentication, - @Parameter(name = "image", description = "업로드 사진 데이터") - @RequestPart(value = "image") MultipartFile image, + public ResponseCustom createStore(Authentication authentication, + @Parameter(name = "image", description = "업로드 사진 데이터") @RequestPart(value = "image") MultipartFile image, @RequestPart(value = "store") StoreCreateRequestDTO storeCreateRequestDTO) { storeService.createStore(AuthenticationParser.parseUserId(authentication), storeCreateRequestDTO, image); return ResponseCustom.OK(Message.builder().message("success").build()); } - @Operation(summary = "가게 정보 수정", description = "가게 정보를 수정합니다.") @PatchMapping("/update") - public ResponseCustom updateStore( - Authentication authentication, + public ResponseCustom updateStore(Authentication authentication, @RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) { storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO); return ResponseCustom.OK(Message.builder().message("success").build()); @@ -89,15 +90,13 @@ public ResponseCustom updateStore( @Operation(summary = "가게 정보 조회", description = "가게 상세 정보를 조회합니다.") @GetMapping("") - public ResponseCustom getStoreInfo( - Authentication authentication) { + public ResponseCustom getStoreInfo(Authentication authentication) { return ResponseCustom.OK(storeService.getStoreInfo(AuthenticationParser.parseUserId(authentication))); } @Operation(summary = "결제 그룹 조회", description = "장부 결제 그룹을 조회합니다.") @GetMapping("/payment_group") - public ResponseCustom> getPaymentGroup( - Authentication authentication, + public ResponseCustom> getPaymentGroup(Authentication authentication, Pageable pageable) { return ResponseCustom.OK( storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication), pageable)); @@ -105,19 +104,39 @@ public ResponseCustom> getPaymentGroup( @Operation(summary = "결제 그룹 상세 조회", description = "장부 결제 그룹을 상세 조회합니다.") @GetMapping("/payment_group/{teamId}") - public ResponseCustom getPaymentGroupDetail( - Authentication authentication, @PathVariable Long teamId, - Pageable pageable) { + public ResponseCustom getPaymentGroupDetail(Authentication authentication, + @PathVariable Long teamId, Pageable pageable) { return ResponseCustom.OK( storeService.getPaymentGroupDetail(AuthenticationParser.parseUserId(authentication), teamId, pageable)); } @Operation(summary = "결제 내역 조회", description = "가게에서 일어난 결제 내역을 조회합니다.") @GetMapping("/payment_history") - public ResponseCustom getPaymentHistory( - Authentication authentication, - Pageable pageable) { + public ResponseCustom getPaymentHistory(Authentication authentication, Pageable pageable) { return ResponseCustom.OK( storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication), pageable)); } + + @Operation(summary = "지난 주문 조회", description = "가게에 있는 지난 주문을 조회합니다") + @GetMapping("/orders/last") + public ResponseCustom> getLastOrders(Authentication authentication) { + List ordersLast = storeService.getOrdersLast( + AuthenticationParser.parseUserId(authentication)); + return ResponseCustom.OK(ordersLast); + } + + @Operation(summary = "오늘 주문 조회", description = "가게에 있는 오늘 주문을 조회합니다") + @GetMapping("/orders/today") + public ResponseCustom getTodayOrders(Authentication authentication) { + return ResponseCustom.OK(storeService.getTodayOrders( + AuthenticationParser.parseUserId(authentication))); + } + + @Operation(summary = "주문 상세 조회", description = "가게에 있는 주문을 상세 조회합니다") + @GetMapping("/orders/{ordersId}") + public ResponseCustom getOrders(Authentication authentication, @RequestParam Long orderId) { + return ResponseCustom.OK( + storeService.getOrderDetails(AuthenticationParser.parseUserId(authentication), orderId)); + } + } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchCondition.java b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchCondition.java similarity index 58% rename from src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchCondition.java rename to src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchCondition.java index 96249c4..9b5d309 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchCondition.java +++ b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchCondition.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.condition; +package com.jangburich.domain.store.dto.condition; public record StoreSearchCondition( Double lat, diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchConditionWithType.java b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchConditionWithType.java similarity index 90% rename from src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchConditionWithType.java rename to src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchConditionWithType.java index d807d6c..092d941 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/condition/StoreSearchConditionWithType.java +++ b/src/main/java/com/jangburich/domain/store/dto/condition/StoreSearchConditionWithType.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.condition; +package com.jangburich.domain.store.dto.condition; import com.querydsl.core.annotations.QueryProjection; diff --git a/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java new file mode 100644 index 0000000..73b5c28 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/dto/response/OrdersDetailResponse.java @@ -0,0 +1,30 @@ +package com.jangburich.domain.store.dto.response; + +import java.time.LocalDateTime; +import java.util.List; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class OrdersDetailResponse { + private Long id; + private String teamName; + private String teamUserName; + private List menus; + private LocalDateTime dateTime; + private Integer amount; + private Integer totalPrice; + private Integer discountPrice; + + @Getter + @Setter + public static class Menu { + private String menuName; + private Integer amount; + } +} + diff --git a/src/main/java/com/jangburich/domain/store/dto/response/OrdersGetResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/OrdersGetResponse.java new file mode 100644 index 0000000..3582ba3 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/dto/response/OrdersGetResponse.java @@ -0,0 +1,18 @@ +package com.jangburich.domain.store.dto.response; + +import java.time.LocalDateTime; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class OrdersGetResponse { + private Long id; + private String menuNames; + private LocalDateTime date; + private Integer count; + private Integer price; +} diff --git a/src/main/java/com/jangburich/domain/store/dto/response/OrdersTodayResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/OrdersTodayResponse.java new file mode 100644 index 0000000..6f53752 --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/dto/response/OrdersTodayResponse.java @@ -0,0 +1,13 @@ +package com.jangburich.domain.store.dto.response; + +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class OrdersTodayResponse { + private Integer totalPrice; + private List ordersGetResponses; +} diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/PaymentGroupDetailResponse.java similarity index 95% rename from src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java rename to src/main/java/com/jangburich/domain/store/dto/response/PaymentGroupDetailResponse.java index 20bdd5d..ef096a6 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/response/PaymentGroupDetailResponse.java +++ b/src/main/java/com/jangburich/domain/store/dto/response/PaymentGroupDetailResponse.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.response; +package com.jangburich.domain.store.dto.response; import org.springframework.data.domain.Page; diff --git a/src/main/java/com/jangburich/domain/store/domain/dto/response/SearchStoresResponse.java b/src/main/java/com/jangburich/domain/store/dto/response/SearchStoresResponse.java similarity index 94% rename from src/main/java/com/jangburich/domain/store/domain/dto/response/SearchStoresResponse.java rename to src/main/java/com/jangburich/domain/store/dto/response/SearchStoresResponse.java index 3036c13..3aea72d 100644 --- a/src/main/java/com/jangburich/domain/store/domain/dto/response/SearchStoresResponse.java +++ b/src/main/java/com/jangburich/domain/store/dto/response/SearchStoresResponse.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.dto.response; +package com.jangburich.domain.store.dto.response; import com.jangburich.domain.store.domain.Category; import com.querydsl.core.annotations.QueryProjection; diff --git a/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java b/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java new file mode 100644 index 0000000..6328c5d --- /dev/null +++ b/src/main/java/com/jangburich/domain/store/exception/OrdersNotFoundException.java @@ -0,0 +1,7 @@ +package com.jangburich.domain.store.exception; + +public class OrdersNotFoundException extends RuntimeException { + public OrdersNotFoundException() { + super("해당 가게를 찾을 수 없습니다."); + } +} diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepository.java b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepository.java similarity index 63% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepository.java rename to src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepository.java index d2e618d..5edbea3 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepository.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepository.java @@ -1,9 +1,9 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import com.jangburich.domain.store.domain.Category; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepositoryImpl.java b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepositoryImpl.java similarity index 93% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepositoryImpl.java rename to src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepositoryImpl.java index 03f15e6..7e88bef 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreQueryDslRepositoryImpl.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreQueryDslRepositoryImpl.java @@ -1,12 +1,12 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import static com.jangburich.domain.store.domain.QStore.store; import com.jangburich.domain.store.domain.Category; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.QSearchStoresResponse; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.QSearchStoresResponse; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.impl.JPAQuery; diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreRepository.java b/src/main/java/com/jangburich/domain/store/repository/StoreRepository.java similarity index 87% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreRepository.java rename to src/main/java/com/jangburich/domain/store/repository/StoreRepository.java index 7525f86..a6b549c 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreRepository.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreRepository.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import java.util.Optional; diff --git a/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java b/src/main/java/com/jangburich/domain/store/repository/StoreTeamRepository.java similarity index 91% rename from src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java rename to src/main/java/com/jangburich/domain/store/repository/StoreTeamRepository.java index e05e178..2fa84fb 100644 --- a/src/main/java/com/jangburich/domain/store/domain/repository/StoreTeamRepository.java +++ b/src/main/java/com/jangburich/domain/store/repository/StoreTeamRepository.java @@ -1,4 +1,4 @@ -package com.jangburich.domain.store.domain.repository; +package com.jangburich.domain.store.repository; import java.util.Optional; diff --git a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java b/src/main/java/com/jangburich/domain/store/service/StoreService.java similarity index 64% rename from src/main/java/com/jangburich/domain/store/domain/service/StoreService.java rename to src/main/java/com/jangburich/domain/store/service/StoreService.java index 3849c08..b5b695c 100644 --- a/src/main/java/com/jangburich/domain/store/domain/service/StoreService.java +++ b/src/main/java/com/jangburich/domain/store/service/StoreService.java @@ -1,4 +1,9 @@ -package com.jangburich.domain.store.domain.service; +package com.jangburich.domain.store.service; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -9,6 +14,11 @@ import com.jangburich.domain.menu.domain.Menu; import com.jangburich.domain.menu.domain.MenuCreateRequestDTO; import com.jangburich.domain.menu.repository.MenuRepository; +import com.jangburich.domain.order.domain.Cart; +import com.jangburich.domain.order.domain.OrderStatus; +import com.jangburich.domain.order.domain.Orders; +import com.jangburich.domain.order.domain.repository.CartRepository; +import com.jangburich.domain.order.domain.repository.OrdersRepository; import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.payment.domain.TeamChargeHistoryResponse; @@ -22,12 +32,16 @@ import com.jangburich.domain.store.domain.StoreTeam; import com.jangburich.domain.store.domain.StoreTeamResponseDTO; import com.jangburich.domain.store.domain.StoreUpdateRequestDTO; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchCondition; -import com.jangburich.domain.store.domain.dto.condition.StoreSearchConditionWithType; -import com.jangburich.domain.store.domain.dto.response.PaymentGroupDetailResponse; -import com.jangburich.domain.store.domain.dto.response.SearchStoresResponse; -import com.jangburich.domain.store.domain.repository.StoreRepository; -import com.jangburich.domain.store.domain.repository.StoreTeamRepository; +import com.jangburich.domain.store.dto.condition.StoreSearchCondition; +import com.jangburich.domain.store.dto.condition.StoreSearchConditionWithType; +import com.jangburich.domain.store.dto.response.OrdersDetailResponse; +import com.jangburich.domain.store.dto.response.OrdersGetResponse; +import com.jangburich.domain.store.dto.response.OrdersTodayResponse; +import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse; +import com.jangburich.domain.store.dto.response.SearchStoresResponse; +import com.jangburich.domain.store.exception.OrdersNotFoundException; +import com.jangburich.domain.store.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreTeamRepository; import com.jangburich.domain.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; import com.jangburich.domain.user.domain.User; @@ -50,6 +64,8 @@ public class StoreService { private final TeamChargeHistoryRepository teamChargeHistoryRepository; private final MenuRepository menuRepository; private final S3Service s3Service; + private final OrdersRepository ordersRepository; + private final CartRepository cartRepository; @Transactional public void createStore(String authentication, StoreCreateRequestDTO storeCreateRequestDTO, MultipartFile image) { @@ -238,4 +254,115 @@ public Page getPaymentHistory(String userId, Pageabl Page historyResponses = teamChargeHistoryRepository.findAllByStore(store, pageable); return historyResponses; } + + public List getOrdersLast(String userId) { + List ordersGetResponses = new ArrayList<>(); + + User user = userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Owner owner = ownerRepository.findByUser(user) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Store store = storeRepository.findByOwner(owner) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + LocalDateTime todayStart = LocalDate.now().atStartOfDay(); + List allByStore = ordersRepository.findOrdersByStoreAndDateAndStatusNative(store.getId(), todayStart, + "TICKET_USED"); + + for (Orders orders : allByStore) { + OrdersGetResponse newOrdersGetResponse = new OrdersGetResponse(); + List carts = cartRepository.findAllByOrders(orders); + newOrdersGetResponse.setId(orders.getId()); + newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() : + carts.get(0).getMenu().getName() + " 외 " + (carts.size() - 1) + "개"); + newOrdersGetResponse.setCount(carts.size()); + newOrdersGetResponse.setDate(orders.getUpdatedAt()); + int price = 0; + for (Cart cart : carts) { + price += (cart.getMenu().getPrice() * cart.getQuantity()); + } + newOrdersGetResponse.setPrice(price); + ordersGetResponses.add(newOrdersGetResponse); + } + + return ordersGetResponses; + } + + public OrdersTodayResponse getTodayOrders(String userId) { + List ordersGetResponses = new ArrayList<>(); + + User user = userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Owner owner = ownerRepository.findByUser(user) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Store store = storeRepository.findByOwner(owner) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + LocalDateTime startOfDay = LocalDate.now().atStartOfDay(); // 오늘 시작 + LocalDateTime endOfDay = LocalDate.now().plusDays(1).atStartOfDay(); // 내일 시작 (오늘의 끝) + + List allByStore = ordersRepository.findOrdersByStoreAndTodayDateAndStatus( + store.getId(), startOfDay, endOfDay, OrderStatus.TICKET_USED); + int totalPrice = 0; + for (Orders orders : allByStore) { + OrdersGetResponse newOrdersGetResponse = new OrdersGetResponse(); + List carts = cartRepository.findAllByOrders(orders); + + newOrdersGetResponse.setId(orders.getId()); + newOrdersGetResponse.setMenuNames(carts.size() == 1 ? carts.get(0).getMenu().getName() : + carts.get(0).getMenu().getName() + " 외 " + (carts.size() - 1) + "개"); + newOrdersGetResponse.setCount(carts.size()); + newOrdersGetResponse.setDate(orders.getUpdatedAt()); + int price = 0; + for (Cart cart : carts) { + price += (cart.getMenu().getPrice() * cart.getQuantity()); + } + newOrdersGetResponse.setPrice(price); + totalPrice += price; + ordersGetResponses.add(newOrdersGetResponse); + } + + OrdersTodayResponse ordersTodayResponse = new OrdersTodayResponse(); + ordersTodayResponse.setOrdersGetResponses(ordersGetResponses); + ordersTodayResponse.setTotalPrice(totalPrice); + + return ordersTodayResponse; + } + + public OrdersDetailResponse getOrderDetails(String userId, Long orderId) { + OrdersDetailResponse ordersDetailResponse = new OrdersDetailResponse(); + + userRepository.findByProviderId(userId) + .orElseThrow(() -> new DefaultNullPointerException(ErrorCode.INVALID_AUTHENTICATION)); + + Orders orders = ordersRepository.findById(orderId).orElseThrow(OrdersNotFoundException::new); + + ordersDetailResponse.setId(orders.getId()); + ordersDetailResponse.setTeamName(orders.getTeam().getName()); + ordersDetailResponse.setTeamUserName(orders.getUser().getName()); + + List carts = cartRepository.findAllByOrders(orders); + List menus = new ArrayList<>(); + Integer amount = 0; + Integer price = 0; + for (Cart cart : carts) { + OrdersDetailResponse.Menu menu = new OrdersDetailResponse.Menu(); + menu.setMenuName(cart.getMenu().getName()); + menu.setAmount(cart.getQuantity()); + menus.add(menu); + amount += cart.getQuantity(); + price += (cart.getQuantity() * cart.getMenu().getPrice()); + } + ordersDetailResponse.setMenus(menus); + ordersDetailResponse.setDateTime(orders.getUpdatedAt()); + ordersDetailResponse.setAmount(amount); + ordersDetailResponse.setTotalPrice(price); + ordersDetailResponse.setDiscountPrice(0); + + return ordersDetailResponse; + } } diff --git a/src/main/java/com/jangburich/domain/user/service/UserService.java b/src/main/java/com/jangburich/domain/user/service/UserService.java index 6259e6f..b67b7dd 100644 --- a/src/main/java/com/jangburich/domain/user/service/UserService.java +++ b/src/main/java/com/jangburich/domain/user/service/UserService.java @@ -12,7 +12,7 @@ import com.jangburich.domain.owner.domain.Owner; import com.jangburich.domain.owner.domain.repository.OwnerRepository; import com.jangburich.domain.store.domain.Store; -import com.jangburich.domain.store.domain.repository.StoreRepository; +import com.jangburich.domain.store.repository.StoreRepository; import com.jangburich.domain.user.domain.AdditionalInfoCreateDTO; import com.jangburich.domain.user.domain.KakaoApiResponseDTO; import com.jangburich.domain.user.domain.TokenResponseDTO;