Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/orders #71

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
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;
import org.springframework.transaction.annotation.Transactional;

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,4 +20,6 @@ public interface CartRepository extends JpaRepository<Cart, Long> {
List<Cart> findAllByUserAndStatus(User user, Status status);

List<Cart> findAllByUserAndStoreAndStatus(User user, Store store, Status status);

List<Cart> findAllByOrders(Orders orders);
}
Original file line number Diff line number Diff line change
@@ -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<Orders, Long> {
@Query(value = "SELECT * FROM orders WHERE store_id = :storeId AND updated_at < :updatedAt AND order_status = :orderStatus",
nativeQuery = true)
List<Orders> 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<Orders> findOrdersByStoreAndTodayDateAndStatus(
@Param("storeId") Long storeId,
@Param("startOfDay") LocalDateTime startOfDay,
@Param("endOfDay") LocalDateTime endOfDay,
@Param("orderStatus") OrderStatus orderStatus);


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -67,57 +72,71 @@ public ResponseCustom<Page<SearchStoresResponse>> searchStores(

@Operation(summary = "κ°€κ²Œ 등둝", description = "μ‹ κ·œ νŒŒνŠΈλ„ˆ κ°€κ²Œλ₯Ό λ“±λ‘ν•©λ‹ˆλ‹€.")
@PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseCustom<Message> createStore(
Authentication authentication,
@Parameter(name = "image", description = "μ—…λ‘œλ“œ 사진 데이터")
@RequestPart(value = "image") MultipartFile image,
public ResponseCustom<Message> 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<Message> updateStore(
Authentication authentication,
public ResponseCustom<Message> updateStore(Authentication authentication,
@RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) {
storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "κ°€κ²Œ 정보 쑰회", description = "κ°€κ²Œ 상세 정보λ₯Ό μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping("")
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(
Authentication authentication) {
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(Authentication authentication) {
return ResponseCustom.OK(storeService.getStoreInfo(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "결제 κ·Έλ£Ή 쑰회", description = "μž₯λΆ€ 결제 그룹을 μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping("/payment_group")
public ResponseCustom<Page<StoreTeamResponseDTO>> getPaymentGroup(
Authentication authentication,
public ResponseCustom<Page<StoreTeamResponseDTO>> getPaymentGroup(Authentication authentication,
Pageable pageable) {
return ResponseCustom.OK(
storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication), pageable));
}

@Operation(summary = "결제 κ·Έλ£Ή 상세 쑰회", description = "μž₯λΆ€ 결제 그룹을 상세 μ‘°νšŒν•©λ‹ˆλ‹€.")
@GetMapping("/payment_group/{teamId}")
public ResponseCustom<PaymentGroupDetailResponse> getPaymentGroupDetail(
Authentication authentication, @PathVariable Long teamId,
Pageable pageable) {
public ResponseCustom<PaymentGroupDetailResponse> 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<List<OrdersGetResponse>> getLastOrders(Authentication authentication) {
List<OrdersGetResponse> ordersLast = storeService.getOrdersLast(
AuthenticationParser.parseUserId(authentication));
return ResponseCustom.OK(ordersLast);
}

@Operation(summary = "였늘 μ£Όλ¬Έ 쑰회", description = "κ°€κ²Œμ— μžˆλŠ” 였늘 주문을 μ‘°νšŒν•©λ‹ˆλ‹€")
@GetMapping("/orders/today")
public ResponseCustom<OrdersTodayResponse> getTodayOrders(Authentication authentication) {
return ResponseCustom.OK(storeService.getTodayOrders(
AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "μ£Όλ¬Έ 상세 쑰회", description = "κ°€κ²Œμ— μžˆλŠ” 주문을 상세 μ‘°νšŒν•©λ‹ˆλ‹€")
@GetMapping("/orders/{ordersId}")
public ResponseCustom<OrdersDetailResponse> getOrders(Authentication authentication, @RequestParam Long orderId) {
return ResponseCustom.OK(
storeService.getOrderDetails(AuthenticationParser.parseUserId(authentication), orderId));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jangburich.domain.store.domain.dto.condition;
package com.jangburich.domain.store.dto.condition;

public record StoreSearchCondition(
Double lat,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Menu> 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;
}
}

Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<OrdersGetResponse> ordersGetResponses;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.jangburich.domain.store.exception;

public class OrdersNotFoundException extends RuntimeException {
public OrdersNotFoundException() {
super("ν•΄λ‹Ή κ°€κ²Œλ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.");
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jangburich.domain.store.domain.repository;
package com.jangburich.domain.store.repository;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jangburich.domain.store.domain.repository;
package com.jangburich.domain.store.repository;

import java.util.Optional;

Expand Down
Loading