From f723dbc656fcc3f3c47e2ae24c5a7240544000b0 Mon Sep 17 00:00:00 2001 From: 05AM Date: Fri, 15 Dec 2023 19:57:18 +0900 Subject: [PATCH] =?UTF-8?q?#140=20[FEAT]=20=EC=9D=BC=EB=B0=98=20=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EC=BB=A4=20=EA=B2=B0=EC=A0=9C=20=ED=9B=84=20discord?= =?UTF-8?q?=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95=20-=20?= =?UTF-8?q?=EB=B3=B5=EC=88=98=20=EC=83=81=ED=92=88=20=EB=82=B4=EC=97=AD=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cart/controller/CartController.java | 3 +- .../order/controller/OrderController.java | 8 ++- .../order/facade/impl/OrderFacadeImpl.java | 11 ++-- .../domain/order/model/OrderHistory.java | 12 +++- .../domain/order/model/OrderedProduct.java | 8 ++- .../domain/order/service/OrderService.java | 6 +- .../order/service/impl/OrderServiceImpl.java | 4 +- .../resquest/OrderStickerDiscordMessage.java | 57 ++++++++++--------- .../resquest/PointChargeDiscordMessage.java | 21 ------- .../property/PointWebhookProperty.java | 16 ------ .../service/DiscordMessageService.java | 33 +++++------ 11 files changed, 82 insertions(+), 97 deletions(-) delete mode 100644 server/src/main/java/org/tattour/server/infra/discord/dto/resquest/PointChargeDiscordMessage.java delete mode 100644 server/src/main/java/org/tattour/server/infra/discord/property/PointWebhookProperty.java diff --git a/server/src/main/java/org/tattour/server/domain/cart/controller/CartController.java b/server/src/main/java/org/tattour/server/domain/cart/controller/CartController.java index 1f800495..f9802c11 100644 --- a/server/src/main/java/org/tattour/server/domain/cart/controller/CartController.java +++ b/server/src/main/java/org/tattour/server/domain/cart/controller/CartController.java @@ -33,10 +33,11 @@ @RestController @RequestMapping("/api/v1/cart") @SecurityRequirement(name = "JWT Auth") -@Tag(name = "Cart(장바구니)", description = "Cart API Document") +@Tag(name = "Cart", description = "Cart API Document") @RequiredArgsConstructor @Validated public class CartController { + private final CartFacade cartFacade; @Operation(summary = "장바구니 아이템 추가") diff --git a/server/src/main/java/org/tattour/server/domain/order/controller/OrderController.java b/server/src/main/java/org/tattour/server/domain/order/controller/OrderController.java index 81a3d545..fc48fab2 100644 --- a/server/src/main/java/org/tattour/server/domain/order/controller/OrderController.java +++ b/server/src/main/java/org/tattour/server/domain/order/controller/OrderController.java @@ -20,10 +20,10 @@ import org.springframework.web.bind.annotation.RestController; import org.tattour.server.domain.order.controller.dto.request.OrderReq; import org.tattour.server.domain.order.controller.dto.response.ReadOrderSheetRes; -import org.tattour.server.domain.order.model.PurchaseRequest; import org.tattour.server.domain.order.facade.dto.request.CreateOrderReq; import org.tattour.server.domain.order.facade.dto.response.ReadUserOrderHistoryListRes; import org.tattour.server.domain.order.facade.impl.OrderFacadeImpl; +import org.tattour.server.domain.order.model.PurchaseRequest; import org.tattour.server.global.config.annotations.UserId; import org.tattour.server.global.dto.BaseResponse; import org.tattour.server.global.dto.FailResponse; @@ -74,7 +74,8 @@ public ResponseEntity getOrderSheet( @Parameter(description = "상품 개수") @RequestParam(required = false) Integer count ) { return BaseResponse.success( - SuccessType.GET_SUCCESS, orderFacade.readOrderSheet(userId, PurchaseRequest.of(stickerId, count))); + SuccessType.GET_SUCCESS, + orderFacade.readOrderSheet(userId, PurchaseRequest.of(stickerId, count))); } @@ -129,7 +130,8 @@ public ResponseEntity order( } - // TODO : pageable로 리팩토링하기 + // TODO: pageable로 리팩토링하기 + // TODO: 결제 내역 response 내용 수정하기 @Operation(summary = "유저 결제 내역 불러오기", description = "유저 id로 결제 내역 불러오기") @ApiResponses(value = { @ApiResponse( diff --git a/server/src/main/java/org/tattour/server/domain/order/facade/impl/OrderFacadeImpl.java b/server/src/main/java/org/tattour/server/domain/order/facade/impl/OrderFacadeImpl.java index dcbeb863..f21de244 100644 --- a/server/src/main/java/org/tattour/server/domain/order/facade/impl/OrderFacadeImpl.java +++ b/server/src/main/java/org/tattour/server/domain/order/facade/impl/OrderFacadeImpl.java @@ -16,6 +16,7 @@ import org.tattour.server.domain.order.facade.dto.response.ReadUserOrderHistoryListRes; import org.tattour.server.domain.order.model.OrderHistory; import org.tattour.server.domain.order.model.OrderStatus; +import org.tattour.server.domain.order.model.OrderedProduct; import org.tattour.server.domain.order.model.PurchaseRequest; import org.tattour.server.domain.order.provider.impl.OrderProviderImpl; import org.tattour.server.domain.order.provider.vo.OrderAmountDetailRes; @@ -34,6 +35,7 @@ @Service @RequiredArgsConstructor public class OrderFacadeImpl implements OrderFacade { + public final static int SHIPPING_FEE = 3000; private final OrderProviderImpl orderProvider; @@ -71,7 +73,8 @@ private StickerOrderInfo getStickerOrderInfo(User user, PurchaseRequest purchase return getCartStickersOrderInfo(carts); } - return getSingleStickerOrderInfo(purchaseRequest.getStickerId(), purchaseRequest.getCount()); + return getSingleStickerOrderInfo(purchaseRequest.getStickerId(), + purchaseRequest.getCount()); } private StickerOrderInfo getSingleStickerOrderInfo(int stickerId, int count) { @@ -101,14 +104,14 @@ public void order(PurchaseRequest purchaseRequest, CreateOrderReq orderReq) { .build()); StickerOrderInfo stickerOrderInfo = getStickerOrderInfo(user, purchaseRequest); - orderService.saveOrderedProducts(orderHistory, stickerOrderInfo); + List orderedProducts = orderService.saveOrderedProducts(orderHistory, + stickerOrderInfo); if (purchaseRequest.isCartPurchase()) { cartService.deleteAllByUserId(user); } - // todo: 디스코드 일반 구매 메시지 형식 수정하기 - discordMessageService.sendOrderStickerMessage(orderHistory); + discordMessageService.sendOrderStickerMessage(orderHistory, orderedProducts); } @Override diff --git a/server/src/main/java/org/tattour/server/domain/order/model/OrderHistory.java b/server/src/main/java/org/tattour/server/domain/order/model/OrderHistory.java index 7972e0d6..4d359c3d 100644 --- a/server/src/main/java/org/tattour/server/domain/order/model/OrderHistory.java +++ b/server/src/main/java/org/tattour/server/domain/order/model/OrderHistory.java @@ -1,5 +1,6 @@ package org.tattour.server.domain.order.model; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -10,6 +11,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.persistence.Table; import lombok.AccessLevel; import lombok.Builder; @@ -24,6 +26,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class OrderHistory { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @@ -49,13 +52,18 @@ public class OrderHistory { @Column(columnDefinition = "tinyint") private Boolean state; + @OneToMany(mappedBy = "orderHistory") + private List orderedProducts; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; @Builder - public OrderHistory(Integer productAmount, Integer shippingFee, Integer totalAmount, String recipientName, - String contact, String mailingAddress, String baseAddress, String detailAddress, User user) { + public OrderHistory(Integer productAmount, Integer shippingFee, Integer totalAmount, + String recipientName, + String contact, String mailingAddress, String baseAddress, String detailAddress, + User user) { this.productAmount = productAmount; this.shippingFee = shippingFee; this.totalAmount = totalAmount; diff --git a/server/src/main/java/org/tattour/server/domain/order/model/OrderedProduct.java b/server/src/main/java/org/tattour/server/domain/order/model/OrderedProduct.java index 7c1ec309..c4a33999 100644 --- a/server/src/main/java/org/tattour/server/domain/order/model/OrderedProduct.java +++ b/server/src/main/java/org/tattour/server/domain/order/model/OrderedProduct.java @@ -11,13 +11,16 @@ import javax.persistence.Table; import lombok.AccessLevel; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; import org.tattour.server.domain.sticker.model.Sticker; @Entity @Table(name = "ordered_product") +@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class OrderedProduct { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @@ -36,8 +39,9 @@ public class OrderedProduct { private OrderHistory orderHistory; @Builder - private OrderedProduct(String name, Integer price, Integer count, String mainImageUrl, Sticker sticker, - OrderHistory orderHistory) { + private OrderedProduct(String name, Integer price, Integer count, String mainImageUrl, + Sticker sticker, + OrderHistory orderHistory) { this.name = name; this.price = price; this.count = count; diff --git a/server/src/main/java/org/tattour/server/domain/order/service/OrderService.java b/server/src/main/java/org/tattour/server/domain/order/service/OrderService.java index 1e13428a..fa997b18 100644 --- a/server/src/main/java/org/tattour/server/domain/order/service/OrderService.java +++ b/server/src/main/java/org/tattour/server/domain/order/service/OrderService.java @@ -1,10 +1,14 @@ package org.tattour.server.domain.order.service; +import java.util.List; import org.tattour.server.domain.order.model.OrderHistory; +import org.tattour.server.domain.order.model.OrderedProduct; import org.tattour.server.domain.sticker.provider.vo.StickerOrderInfo; public interface OrderService { + OrderHistory saveOrder(OrderHistory orderHistory); - void saveOrderedProducts(OrderHistory orderHistory, StickerOrderInfo stickerOrderInfo); + List saveOrderedProducts(OrderHistory orderHistory, + StickerOrderInfo stickerOrderInfo); } diff --git a/server/src/main/java/org/tattour/server/domain/order/service/impl/OrderServiceImpl.java b/server/src/main/java/org/tattour/server/domain/order/service/impl/OrderServiceImpl.java index 9b972c03..8fd53322 100644 --- a/server/src/main/java/org/tattour/server/domain/order/service/impl/OrderServiceImpl.java +++ b/server/src/main/java/org/tattour/server/domain/order/service/impl/OrderServiceImpl.java @@ -26,7 +26,8 @@ public OrderHistory saveOrder(OrderHistory orderHistory) { } @Override - public void saveOrderedProducts(OrderHistory orderHistory, StickerOrderInfo stickerOrderInfo) { + public List saveOrderedProducts(OrderHistory orderHistory, + StickerOrderInfo stickerOrderInfo) { List orderedProducts = stickerOrderInfo.getStickerOrderInfos() .entrySet() .stream() @@ -41,5 +42,6 @@ public void saveOrderedProducts(OrderHistory orderHistory, StickerOrderInfo stic .collect(Collectors.toUnmodifiableList()); orderedProductRepository.saveAll(orderedProducts); + return orderedProducts; } } diff --git a/server/src/main/java/org/tattour/server/infra/discord/dto/resquest/OrderStickerDiscordMessage.java b/server/src/main/java/org/tattour/server/infra/discord/dto/resquest/OrderStickerDiscordMessage.java index df395880..d7732fe0 100644 --- a/server/src/main/java/org/tattour/server/infra/discord/dto/resquest/OrderStickerDiscordMessage.java +++ b/server/src/main/java/org/tattour/server/infra/discord/dto/resquest/OrderStickerDiscordMessage.java @@ -1,9 +1,11 @@ package org.tattour.server.infra.discord.dto.resquest; +import java.util.List; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import org.tattour.server.domain.order.model.OrderHistory; +import org.tattour.server.domain.order.model.OrderedProduct; @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) @@ -11,33 +13,34 @@ public class OrderStickerDiscordMessage { String title; String description; - DiscordCustomImage image; - // todo: 디스코드 메시지 내용 형식 수정 - public static OrderStickerDiscordMessage from(OrderHistory orderHistory) { -// String title = "Order Id : " + orderHistory.getId(); -// String description = "\n유저 Id : " + orderHistory.getUser().getId() -// + "\n수령인 : " + orderHistory.getRecipientName() -// + "\n연락처 : " + orderHistory.getContact() -// + "\n유저 이메일 : " + orderHistory.getMailingAddress() -// + "\n상품 Id : " + orderHistory.getProductName() -// + "\n상품 이름 : " + orderHistory.getProductName() -// + "\n상품 크기 : " + orderHistory.getProductSize() -// + "\n상품 금액 : " + orderHistory.getProductAmount() -// + "\n상품 개수 : " + orderHistory.getProductCount() -// + "\n총 주문 금액 : " + orderHistory.getTotalAmount() -// + "\n기본 주소 : " + orderHistory.getBaseAddress() -// + "\n싱세 주소 : " + orderHistory.getDetailAddress() -// + "\n배송비 : " + orderHistory.getShippingFee(); -// return new OrderStickerDiscordMessage( -// title, -// description, -// new DiscordCustomImage(orderHistory.getProductImageUrl()) -// ); - return new OrderStickerDiscordMessage( - "[임시 응답]", - "메시지 형식에 대한 추가 개발이 필요해 임시 응답을 전달합니다.", - new DiscordCustomImage(null) - ); + public static OrderStickerDiscordMessage from( + OrderHistory orderHistory, + List orderedProducts) { + String title = "주문 번호: " + orderHistory.getId(); + StringBuilder description = new StringBuilder(); + description.append("\n\n### [주문 정보]") + .append("\n유저 번호: ").append(orderHistory.getUser().getId()) + .append("\n상품 금액: ").append(orderHistory.getProductAmount()) + .append("\n총 주문 금액: ").append(orderHistory.getTotalAmount()); + + description.append("\n\n### [주문 상품 내역]"); + orderedProducts.forEach(product -> { + description.append("\n"); + description.append("\n상품 번호: ").append(product.getSticker().getId()); + description.append("\n상품명: ").append(product.getSticker().getName()); + description.append("\n가격: ").append(product.getPrice()); + description.append("\n수량: ").append(product.getCount()); + }); + + description.append("\n\n### [배송 정보]") + .append("\n수령인: ").append(orderHistory.getRecipientName()) + .append("\n연락처: ").append(orderHistory.getContact()) + .append("\n우편 번호: ").append(orderHistory.getMailingAddress()) + .append("\n기본 주소: ").append(orderHistory.getBaseAddress()) + .append("\n싱세 주소: ").append(orderHistory.getDetailAddress()) + .append("\n배송비: ").append(orderHistory.getShippingFee()); + + return new OrderStickerDiscordMessage(title, description.toString()); } } diff --git a/server/src/main/java/org/tattour/server/infra/discord/dto/resquest/PointChargeDiscordMessage.java b/server/src/main/java/org/tattour/server/infra/discord/dto/resquest/PointChargeDiscordMessage.java deleted file mode 100644 index c6d7cd02..00000000 --- a/server/src/main/java/org/tattour/server/infra/discord/dto/resquest/PointChargeDiscordMessage.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.tattour.server.infra.discord.dto.resquest; - -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import org.tattour.server.domain.user.model.User; - -@Getter -@AllArgsConstructor(access = AccessLevel.PRIVATE) -public class PointChargeDiscordMessage { - - String title; - String description; - - public static PointChargeDiscordMessage from(User user, Integer amount) { - String description = amount + "원 송금 확인해주세요" - + "전화번호 : " + user.getPhoneNumber(); - return new PointChargeDiscordMessage("User Id : " + user.getId(), amount + "원 송금 확인해주세요"); - } - -} diff --git a/server/src/main/java/org/tattour/server/infra/discord/property/PointWebhookProperty.java b/server/src/main/java/org/tattour/server/infra/discord/property/PointWebhookProperty.java deleted file mode 100644 index b49952b6..00000000 --- a/server/src/main/java/org/tattour/server/infra/discord/property/PointWebhookProperty.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.tattour.server.infra.discord.property; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Setter -@Getter -@Configuration -@ConfigurationProperties("discord.webhook.point") -public class PointWebhookProperty { - - private String clientId; - private String token; -} diff --git a/server/src/main/java/org/tattour/server/infra/discord/service/DiscordMessageService.java b/server/src/main/java/org/tattour/server/infra/discord/service/DiscordMessageService.java index 92bfbfec..a26ca080 100644 --- a/server/src/main/java/org/tattour/server/infra/discord/service/DiscordMessageService.java +++ b/server/src/main/java/org/tattour/server/infra/discord/service/DiscordMessageService.java @@ -1,19 +1,19 @@ package org.tattour.server.infra.discord.service; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.tattour.server.domain.custom.model.Custom; import org.tattour.server.domain.order.model.OrderHistory; +import org.tattour.server.domain.order.model.OrderedProduct; import org.tattour.server.domain.user.model.User; import org.tattour.server.infra.discord.client.DiscordApiClient; import org.tattour.server.infra.discord.dto.resquest.CustomApplyDiscordMessage; import org.tattour.server.infra.discord.dto.resquest.DiscordMessageReq; import org.tattour.server.infra.discord.dto.resquest.OrderStickerDiscordMessage; -import org.tattour.server.infra.discord.dto.resquest.PointChargeDiscordMessage; import org.tattour.server.infra.discord.property.CustomWebhookProperty; import org.tattour.server.infra.discord.property.OrderWebhookProperty; -import org.tattour.server.infra.discord.property.PointWebhookProperty; @Component @RequiredArgsConstructor @@ -22,35 +22,30 @@ public class DiscordMessageService { private final DiscordApiClient discordApiClient; private final OrderWebhookProperty orderWebhookProperty; private final CustomWebhookProperty customWebhookProperty; - private final PointWebhookProperty pointWebhookProperty; @Transactional - public Boolean sendPointChargeLogMessage(User user, Integer amount) { - PointChargeDiscordMessage payload = PointChargeDiscordMessage.from(user, amount); - sendDiscordMessage(pointWebhookProperty.getClientId(), pointWebhookProperty.getToken(), - user, "님이 포인트 충전을 요구했습니다", payload); - return true; - } - - @Transactional - public Boolean sendCustomApplyMessage(Custom custom) { + public void sendCustomApplyMessage(Custom custom) { CustomApplyDiscordMessage payload = CustomApplyDiscordMessage.from(custom.getUser(), custom); sendDiscordMessage(customWebhookProperty.getClientId(), customWebhookProperty.getToken(), custom.getUser(), "님이 커스텀 도안을 신청했습니다.", payload); - return true; } @Transactional - public Boolean sendOrderStickerMessage(OrderHistory orderHistory) { - OrderStickerDiscordMessage payload = OrderStickerDiscordMessage.from(orderHistory); - sendDiscordMessage(orderWebhookProperty.getClientId(), orderWebhookProperty.getToken(), - orderHistory.getUser(), "님이 스티커를 주문했습니다.", payload); - return true; + public void sendOrderStickerMessage(OrderHistory orderHistory, + List orderedProducts) { + OrderStickerDiscordMessage payload = + OrderStickerDiscordMessage.from(orderHistory, orderedProducts); + sendDiscordMessage( + orderWebhookProperty.getClientId(), + orderWebhookProperty.getToken(), + orderHistory.getUser(), + " 님이 스티커를 주문했습니다.", + payload); } public void sendDiscordMessage(String clientId, String token, User user, String content, - Object payload) { + Object payload) { DiscordMessageReq request = DiscordMessageReq.from(user, content, payload); discordApiClient.sendMessage(clientId, token, request); }