Skip to content

Commit

Permalink
Merge pull request #102 from Part-time-Ray/feature/order
Browse files Browse the repository at this point in the history
訂單回傳: 新增buyername和sellername
  • Loading branch information
Shih-Hsuan authored Jan 11, 2024
2 parents 04ff5c7 + e7f2a4b commit 25f0c4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public class OrderWithProductDetail {
@NotNull
private Long buyerid;

@NotNull
private String buyername;

@NotNull
private String sellername;

@NotNull
private Long sellerid;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ntou.auction.spring.order.service;

import ntou.auction.spring.account.entity.User;
import ntou.auction.spring.account.service.UserService;
import ntou.auction.spring.mail.EmailService;
import ntou.auction.spring.order.entity.Order;
import ntou.auction.spring.order.response.OrderWithProductDetail;
Expand All @@ -22,15 +24,15 @@ public class OrderService {

private final ProductService productService;

private final ShoppingcartService shoppingcartService;
private final UserService userService;
private final EmailService emailService;

private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

public OrderService(OrderRepository repository, ProductService productService, ShoppingcartService shoppingcartService, EmailService emailService) {
public OrderService(OrderRepository repository, ProductService productService, UserService userService, EmailService emailService) {
this.repository = repository;
this.productService = productService;
this.shoppingcartService = shoppingcartService;
this.userService = userService;
this.emailService = emailService;
}

Expand Down Expand Up @@ -159,6 +161,10 @@ public List<OrderWithProductDetail> orderToOrderWithProductDetail(List<Order> ge
addOrder.setUpdateTime(order.getUpdateTime());
addOrder.setStatus(order.getStatus());
addOrder.setOrderid(order.getId());
User buyer = userService.get(order.getBuyerid()).orElse(null);
User seller = userService.get(order.getSellerid()).orElse(null);
if(buyer!=null) addOrder.setBuyername(buyer.getName());
if(seller!=null) addOrder.setSellername(seller.getName());
List<ProductAddAmount> temp = new ArrayList<>();
for (List<Long> product : order.getProductAddAmountList()) {
temp.add(new ProductAddAmount(productService.getID(product.get(0)), product.get(1)));
Expand Down

0 comments on commit 25f0c4a

Please sign in to comment.