Skip to content

Commit

Permalink
#140 [FEAT] 일반 스티커 결제 후 discord 메시지 수정 - 복수 상품 내역 전송
Browse files Browse the repository at this point in the history
  • Loading branch information
05AM committed Dec 15, 2023
1 parent aec278c commit f723dbc
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "장바구니 아이템 추가")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}


Expand Down Expand Up @@ -129,7 +130,8 @@ public ResponseEntity<?> order(
}


// TODO : pageable로 리팩토링하기
// TODO: pageable로 리팩토링하기
// TODO: 결제 내역 response 내용 수정하기
@Operation(summary = "유저 결제 내역 불러오기", description = "유저 id로 결제 내역 불러오기")
@ApiResponses(value = {
@ApiResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +35,7 @@
@Service
@RequiredArgsConstructor
public class OrderFacadeImpl implements OrderFacade {

public final static int SHIPPING_FEE = 3000;

private final OrderProviderImpl orderProvider;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -101,14 +104,14 @@ public void order(PurchaseRequest purchaseRequest, CreateOrderReq orderReq) {
.build());

StickerOrderInfo stickerOrderInfo = getStickerOrderInfo(user, purchaseRequest);
orderService.saveOrderedProducts(orderHistory, stickerOrderInfo);
List<OrderedProduct> orderedProducts = orderService.saveOrderedProducts(orderHistory,
stickerOrderInfo);

if (purchaseRequest.isCartPurchase()) {
cartService.deleteAllByUserId(user);
}

// todo: 디스코드 일반 구매 메시지 형식 수정하기
discordMessageService.sendOrderStickerMessage(orderHistory);
discordMessageService.sendOrderStickerMessage(orderHistory, orderedProducts);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -24,6 +26,7 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OrderHistory {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
Expand All @@ -49,13 +52,18 @@ public class OrderHistory {
@Column(columnDefinition = "tinyint")
private Boolean state;

@OneToMany(mappedBy = "orderHistory")
private List<OrderedProduct> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OrderedProduct> saveOrderedProducts(OrderHistory orderHistory,
StickerOrderInfo stickerOrderInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public OrderHistory saveOrder(OrderHistory orderHistory) {
}

@Override
public void saveOrderedProducts(OrderHistory orderHistory, StickerOrderInfo stickerOrderInfo) {
public List<OrderedProduct> saveOrderedProducts(OrderHistory orderHistory,
StickerOrderInfo stickerOrderInfo) {
List<OrderedProduct> orderedProducts = stickerOrderInfo.getStickerOrderInfos()
.entrySet()
.stream()
Expand All @@ -41,5 +42,6 @@ public void saveOrderedProducts(OrderHistory orderHistory, StickerOrderInfo stic
.collect(Collectors.toUnmodifiableList());

orderedProductRepository.saveAll(orderedProducts);
return orderedProducts;
}
}
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
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)
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<OrderedProduct> 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());
}
}

This file was deleted.

This file was deleted.

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

0 comments on commit f723dbc

Please sign in to comment.