Skip to content

Commit

Permalink
Merge pull request #94 from wei-chun-Nien/development
Browse files Browse the repository at this point in the history
fix: 賣家不能出價自己的商品
  • Loading branch information
keke125 authored Jan 2, 2024
2 parents f01095b + 8cd7afb commit e0cb93f
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ ResponseEntity<Map<String, String>> bidProduct(@Valid @RequestBody BidRequest re
Map<String, String> successMessage = Collections.singletonMap("message", "成功出價");
Map<String, String> failMessage = Collections.singletonMap("message", "出價不合理,出價需比當前最高價高" + productService.getID(request.getProductID()).getBidIncrement());
Map<String, String> expired = Collections.singletonMap("message", "競標已結束");
Map<String, String> violate = Collections.singletonMap("message", "不可以出價自己的商品");

if(Objects.equals(userService.findByUsername(userIdentity.getUsername()).getId(), productService.getID(request.getProductID()).getSellerID())){
return ResponseEntity.badRequest().body(violate);
}


LocalDateTime now = LocalDateTime.now();
if (!now.isBefore(productService.getID(request.getProductID()).getFinishTime())) {
Expand All @@ -157,6 +163,12 @@ ResponseEntity<Map<String, String>> buyProduct(@Valid @RequestBody BuyProductReq
Map<String, String> errorMessage = Collections.singletonMap("message", "只能將不二價商品加入購物車");
Map<String, String> productNotExistMessage = Collections.singletonMap("message", "商品不存在或無法購買");

Map<String, String> violate = Collections.singletonMap("message", "不可以買自己的商品");

if(Objects.equals(userService.findByUsername(userIdentity.getUsername()).getId(), productService.getID(request.getProductID()).getSellerID())){
return ResponseEntity.badRequest().body(violate);
}

// 商品是否存在
if (productService.getID(request.getProductID()) == null) {
return ResponseEntity.badRequest().body(productNotExistMessage);
Expand Down

0 comments on commit e0cb93f

Please sign in to comment.