From 0cf2f14b30711f8a43050093776397f302f7bf95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=ED=98=81?= Date: Tue, 19 Nov 2024 20:29:52 +0900 Subject: [PATCH] =?UTF-8?q?style:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=ED=8A=B8?= =?UTF-8?q?=EB=9E=9C=EC=9E=AD=EC=85=98=20=EB=A0=88=ED=8F=AC=EC=A7=80?= =?UTF-8?q?=ED=86=A0=EB=A6=AC=EB=AA=85=20=EB=B3=80=EA=B2=BD=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현 * feat: 상품 주문과 식권 사용 기능 구현 * style: 포인트트랜잭션 레포지토리명 변경 --- .../order/application/OrderService.java | 8 +- .../order/presentation/OrderController.java | 81 +++++++++---------- .../domain/point/domain/PointTransaction.java | 10 +++ .../PointTransactionRepository.java | 9 +++ 4 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 src/main/java/com/jangburich/domain/point/domain/repository/PointTransactionRepository.java 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 4564f3e..f31198f 100644 --- a/src/main/java/com/jangburich/domain/order/application/OrderService.java +++ b/src/main/java/com/jangburich/domain/order/application/OrderService.java @@ -12,12 +12,14 @@ import com.jangburich.domain.order.dto.request.OrderRequest; import com.jangburich.domain.order.dto.response.CartResponse; import com.jangburich.domain.order.dto.response.GetCartItemsResponse; +import com.jangburich.domain.point.domain.repository.PointTransaction; 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.team.domain.Team; import com.jangburich.domain.team.domain.repository.TeamRepository; import com.jangburich.domain.user.domain.User; -import com.jangburich.domain.user.repository.UserRepository; +import com.jangburich.domain.user.domain.repository.UserRepository; import com.jangburich.global.payload.Message; import java.util.List; import java.util.Optional; @@ -36,6 +38,7 @@ public class OrderService { private final StoreRepository storeRepository; private final OrdersRepository ordersRepository; private final TeamRepository teamRepository; + private final StoreTeamRepository storeTeamRepository; @Transactional public Message addCart(String userProviderId, AddCartRequest addCartRequest) { @@ -72,6 +75,7 @@ public Message addCart(String userProviderId, AddCartRequest addCartRequest) { cartRepository.save(newCart); + return Message.builder() .message("장바구니에 상품을 추가했습니다.") .build(); @@ -99,6 +103,8 @@ public CartResponse getCartItems(String userProviderId) { int discountAmount = 0; CartResponse cartResponse = CartResponse.of(cartItems, discountAmount); + + return cartResponse; } diff --git a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java index ea1f0b2..b6f53a1 100644 --- a/src/main/java/com/jangburich/domain/order/presentation/OrderController.java +++ b/src/main/java/com/jangburich/domain/order/presentation/OrderController.java @@ -1,21 +1,12 @@ package com.jangburich.domain.order.presentation; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestAttribute; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - import com.jangburich.domain.order.application.OrderService; import com.jangburich.domain.order.dto.request.AddCartRequest; import com.jangburich.domain.order.dto.request.OrderRequest; import com.jangburich.domain.order.dto.response.CartResponse; -import com.jangburich.global.GetAuthorization; import com.jangburich.global.payload.Message; import com.jangburich.global.payload.ResponseCustom; - +import com.jangburich.utils.parser.AuthenticationParser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -33,39 +24,39 @@ @RequestMapping("/orders") public class OrderController { - private final OrderService orderService; - - @Operation(summary = "장바구니 담기", description = "장바구니에 물건과 수량을 담습니다.") - @PostMapping("/carts") - public ResponseCustom addCart( - @RequestAttribute(value = "authorizationHeader") String authorizationHeader, - @RequestBody AddCartRequest addCartRequest - ) { - return ResponseCustom.OK(orderService.addCart(GetAuthorization.getUserId(authorizationHeader), addCartRequest)); - } - - @Operation(summary = "장바구니 조회", description = "장바구니에 담은 상품을 조회합니다.") - @GetMapping("/carts") - public ResponseCustom getCartItems( - @RequestAttribute(value = "authorizationHeader") String authorizationHeader - ) { - return ResponseCustom.OK(orderService.getCartItems(GetAuthorization.getUserId(authorizationHeader))); - } - - @Operation(summary = "상품 주문", description = "상품을 주문합니다.") - @PostMapping - public ResponseCustom order( - @RequestAttribute(value = "authorizationHeader") String authorizationHeader, - @RequestBody OrderRequest orderRequest - ) { - return ResponseCustom.OK(orderService.order(GetAuthorization.getUserId(authorizationHeader), orderRequest)); - } - - @Operation(summary = "식권 사용", description = "식권을 사용합니다.") - public ResponseCustom useMealTicket( - @RequestAttribute(value = "authorizationHeader") String authorizationHeader, - @PathVariable Long orderId - ) { - return ResponseCustom.OK(orderService.useMealTicket(GetAuthorization.getUserId(authorizationHeader), orderId)); - } + private final OrderService orderService; + + @Operation(summary = "장바구니 담기", description = "장바구니에 물건과 수량을 담습니다.") + @PostMapping("/carts") + public ResponseCustom addCart( + Authentication authentication, + @RequestBody AddCartRequest addCartRequest + ) { + return ResponseCustom.OK(orderService.addCart(AuthenticationParser.parseUserId(authentication), addCartRequest)); + } + + @Operation(summary = "장바구니 조회", description = "장바구니에 담은 상품을 조회합니다.") + @GetMapping("/carts") + public ResponseCustom getCartItems( + Authentication authentication + ) { + return ResponseCustom.OK(orderService.getCartItems(AuthenticationParser.parseUserId(authentication))); + } + + @Operation(summary = "상품 주문", description = "상품을 주문합니다.") + @PostMapping + public ResponseCustom order( + Authentication authentication, + @RequestBody OrderRequest orderRequest + ) { + return ResponseCustom.OK(orderService.order(AuthenticationParser.parseUserId(authentication), orderRequest)); + } + + @Operation(summary = "식권 사용", description = "식권을 사용합니다.") + public ResponseCustom useMealTicket( + Authentication authentication, + @PathVariable Long orderId + ) { + return ResponseCustom.OK(orderService.useMealTicket(AuthenticationParser.parseUserId(authentication), orderId)); + } } \ No newline at end of file diff --git a/src/main/java/com/jangburich/domain/point/domain/PointTransaction.java b/src/main/java/com/jangburich/domain/point/domain/PointTransaction.java index 9e8d98a..55f320c 100644 --- a/src/main/java/com/jangburich/domain/point/domain/PointTransaction.java +++ b/src/main/java/com/jangburich/domain/point/domain/PointTransaction.java @@ -15,6 +15,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -43,4 +44,13 @@ public class PointTransaction extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "store_id") private Store store; + + + @Builder + public PointTransaction(TransactionType transactionType, Team team, User user, Store store) { + this.transactionType = transactionType; + this.team = team; + this.user = user; + this.store = store; + } } diff --git a/src/main/java/com/jangburich/domain/point/domain/repository/PointTransactionRepository.java b/src/main/java/com/jangburich/domain/point/domain/repository/PointTransactionRepository.java new file mode 100644 index 0000000..e1c0c61 --- /dev/null +++ b/src/main/java/com/jangburich/domain/point/domain/repository/PointTransactionRepository.java @@ -0,0 +1,9 @@ +package com.jangburich.domain.point.domain.repository; + +import com.jangburich.domain.point.domain.PointTransaction; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface PointTransactionRepository extends JpaRepository { +} \ No newline at end of file