upd
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.flower.confession;
|
||||
package com.flower.confession;
|
||||
|
||||
import com.flower.common.ApiException;
|
||||
import com.flower.common.ApiResponse;
|
||||
@@ -41,6 +41,7 @@ public class ConfessionController {
|
||||
if (!order.getUserId().equals(AuthContext.get().getId())) {
|
||||
throw new ApiException(403, "无权限");
|
||||
}
|
||||
ensureOrderPaid(order);
|
||||
Confession confession = new Confession();
|
||||
confession.setOrderId(order.getId());
|
||||
confession.setUserId(order.getUserId());
|
||||
@@ -68,6 +69,9 @@ public class ConfessionController {
|
||||
if (!confession.getUserId().equals(AuthContext.get().getId())) {
|
||||
throw new ApiException(403, "无权限");
|
||||
}
|
||||
Order order = orderRepository.findById(confession.getOrderId())
|
||||
.orElseThrow(() -> new ApiException(404, "订单不存在"));
|
||||
ensureOrderPaid(order);
|
||||
confession.setTitle(request.getTitle());
|
||||
confession.setMessage(request.getMessage());
|
||||
confession.setImageUrl(request.getImageUrl());
|
||||
@@ -122,4 +126,11 @@ public class ConfessionController {
|
||||
private String sender;
|
||||
private String content;
|
||||
}
|
||||
|
||||
private void ensureOrderPaid(Order order) {
|
||||
String status = order.getStatus();
|
||||
if (!"PAID".equals(status) && !"SHIPPED".equals(status) && !"COMPLETED".equals(status)) {
|
||||
throw new ApiException(400, "请至少支付后再定制告白");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user