feat: Implement comprehensive product management, including categories, pricing, and integration into the order system.
This commit is contained in:
@@ -22,7 +22,28 @@ class OrderController extends Controller
|
||||
try {
|
||||
$customer = $request->user();
|
||||
|
||||
$result = $this->orderService->create($request->validated(), $customer);
|
||||
$data = $request->validated();
|
||||
|
||||
// Convert UUID to ID for internal processing
|
||||
$product = \App\Models\Product::where('uuid', $data['product_id'])->first();
|
||||
|
||||
if (!$product) {
|
||||
// Should not happen if validation passes, but safety first (e.g. race condition or soft delete mismatch)
|
||||
throw new \Exception('Sản phẩm không tìm thấy hoặc đã bị xóa.');
|
||||
}
|
||||
|
||||
$data['product_id'] = $product->id;
|
||||
|
||||
$customer = $request->user();
|
||||
|
||||
if (!$customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Người dùng chưa đăng nhập hoặc phiên đăng nhập hết hạn.'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$result = $this->orderService->create($data, $customer);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
@@ -65,4 +86,28 @@ class OrderController extends Controller
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function getList(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$customer = $request->user();
|
||||
|
||||
$filters = [
|
||||
'total_price' => $request->query('total_price'),
|
||||
'pending' => $request->query('pending')
|
||||
];
|
||||
|
||||
$orders = $this->orderRepo->getOrders($customer->id, $filters);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $orders
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user