Skip to content

Commit

Permalink
style: 포인트트랜잭션 레포지토리명 변경 (#49)
Browse files Browse the repository at this point in the history
* feat: 장바구니 추가 기능 구현

* feat: 장바구니 조회 기능 구현

* feat: 상품 주문과 식권 사용 기능 구현

* style: 포인트트랜잭션 레포지토리명 변경
  • Loading branch information
LEEJaeHyeok97 authored Nov 19, 2024
1 parent 54fd78b commit 0cf2f14
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -72,6 +75,7 @@ public Message addCart(String userProviderId, AddCartRequest addCartRequest) {

cartRepository.save(newCart);


return Message.builder()
.message("장바구니에 상품을 추가했습니다.")
.build();
Expand Down Expand Up @@ -99,6 +103,8 @@ public CartResponse getCartItems(String userProviderId) {
int discountAmount = 0;
CartResponse cartResponse = CartResponse.of(cartItems, discountAmount);



return cartResponse;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -33,39 +24,39 @@
@RequestMapping("/orders")
public class OrderController {

private final OrderService orderService;

@Operation(summary = "장바구니 담기", description = "장바구니에 물건과 수량을 담습니다.")
@PostMapping("/carts")
public ResponseCustom<Message> 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<CartResponse> getCartItems(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader
) {
return ResponseCustom.OK(orderService.getCartItems(GetAuthorization.getUserId(authorizationHeader)));
}

@Operation(summary = "상품 주문", description = "상품을 주문합니다.")
@PostMapping
public ResponseCustom<Message> order(
@RequestAttribute(value = "authorizationHeader") String authorizationHeader,
@RequestBody OrderRequest orderRequest
) {
return ResponseCustom.OK(orderService.order(GetAuthorization.getUserId(authorizationHeader), orderRequest));
}

@Operation(summary = "식권 사용", description = "식권을 사용합니다.")
public ResponseCustom<Message> 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<Message> addCart(
Authentication authentication,
@RequestBody AddCartRequest addCartRequest
) {
return ResponseCustom.OK(orderService.addCart(AuthenticationParser.parseUserId(authentication), addCartRequest));
}

@Operation(summary = "장바구니 조회", description = "장바구니에 담은 상품을 조회합니다.")
@GetMapping("/carts")
public ResponseCustom<CartResponse> getCartItems(
Authentication authentication
) {
return ResponseCustom.OK(orderService.getCartItems(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "상품 주문", description = "상품을 주문합니다.")
@PostMapping
public ResponseCustom<Message> order(
Authentication authentication,
@RequestBody OrderRequest orderRequest
) {
return ResponseCustom.OK(orderService.order(AuthenticationParser.parseUserId(authentication), orderRequest));
}

@Operation(summary = "식권 사용", description = "식권을 사용합니다.")
public ResponseCustom<Message> useMealTicket(
Authentication authentication,
@PathVariable Long orderId
) {
return ResponseCustom.OK(orderService.useMealTicket(AuthenticationParser.parseUserId(authentication), orderId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<PointTransaction, Long> {
}

0 comments on commit 0cf2f14

Please sign in to comment.