修复:新增后台订单详情接口
This commit is contained in:
+20
@@ -83,6 +83,26 @@ public class AdminOrderController {
|
|||||||
return Result.success(result);
|
return Result.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/detail/{id}")
|
||||||
|
@RequirePermission("order:view")
|
||||||
|
public Result<OrderVO> getOrderDetail(HttpServletRequest request, @PathVariable Long id) {
|
||||||
|
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||||
|
List<OrderVO> allOrders;
|
||||||
|
if (Integer.valueOf(3).equals(currentUser.getType())) {
|
||||||
|
allOrders = orderService.getOrdersByArtistId(currentUser.getId());
|
||||||
|
} else {
|
||||||
|
allOrders = orderService.getAllOrders();
|
||||||
|
}
|
||||||
|
OrderVO orderVO = allOrders.stream()
|
||||||
|
.filter(order -> id.equals(order.getId()))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new RuntimeException("订单不存在"));
|
||||||
|
if (!Integer.valueOf(3).equals(currentUser.getType())) {
|
||||||
|
adminScopeHelper.ensureShopAccessible(currentUser, orderVO.getShopId(), "无权查看其他店铺订单");
|
||||||
|
}
|
||||||
|
return Result.success(orderVO);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新订单状态
|
* 更新订单状态
|
||||||
*/
|
*/
|
||||||
|
|||||||
+36
@@ -19,8 +19,10 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
|
|
||||||
class AdminOrderControllerTest {
|
class AdminOrderControllerTest {
|
||||||
|
|
||||||
@@ -63,6 +65,40 @@ class AdminOrderControllerTest {
|
|||||||
assertThat(result.getData().getList()).containsExactly(visibleOrder);
|
assertThat(result.getData().getList()).containsExactly(visibleOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getOrderDetailShouldReturnVisibleOrderForAdmin() {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
UserDO platformAdmin = new UserDO();
|
||||||
|
platformAdmin.setType(4);
|
||||||
|
when(adminScopeHelper.getCurrentUser(request)).thenReturn(platformAdmin);
|
||||||
|
|
||||||
|
OrderVO visibleOrder = order(8L);
|
||||||
|
when(orderService.getAllOrders()).thenReturn(List.of(visibleOrder));
|
||||||
|
|
||||||
|
Result<OrderVO> result = controller.getOrderDetail(request, visibleOrder.getId());
|
||||||
|
|
||||||
|
assertThat(result.getData()).isSameAs(visibleOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getOrderDetailShouldRejectOtherShopForManager() {
|
||||||
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
UserDO manager = new UserDO();
|
||||||
|
manager.setType(2);
|
||||||
|
manager.setShopId(8L);
|
||||||
|
when(adminScopeHelper.getCurrentUser(request)).thenReturn(manager);
|
||||||
|
|
||||||
|
OrderVO otherShopOrder = order(9L);
|
||||||
|
when(orderService.getAllOrders()).thenReturn(List.of(otherShopOrder));
|
||||||
|
doThrow(new RuntimeException("无权查看其他店铺订单"))
|
||||||
|
.when(adminScopeHelper)
|
||||||
|
.ensureShopAccessible(manager, otherShopOrder.getShopId(), "无权查看其他店铺订单");
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> controller.getOrderDetail(request, otherShopOrder.getId()))
|
||||||
|
.isInstanceOf(RuntimeException.class)
|
||||||
|
.hasMessageContaining("无权查看其他店铺订单");
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isShopIdRequestParam(Parameter parameter) {
|
private boolean isShopIdRequestParam(Parameter parameter) {
|
||||||
RequestParam requestParam = parameter.getAnnotation(RequestParam.class);
|
RequestParam requestParam = parameter.getAnnotation(RequestParam.class);
|
||||||
return requestParam != null && Long.class.equals(parameter.getType());
|
return requestParam != null && Long.class.equals(parameter.getType());
|
||||||
|
|||||||
Reference in New Issue
Block a user