feat(convert): let customers list and change pending requests
History is limited to the signed-in customer. Update and delete only apply while the request is still pending. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,6 +10,16 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
||||
|
||||
class CopperConvertRequestController extends Controller
|
||||
{
|
||||
public function index(CopperConvertRequestService $service)
|
||||
{
|
||||
$customer = auth('customer')->user();
|
||||
if (!$customer instanceof Customer) {
|
||||
throw new UnprocessableEntityHttpException('مشتری یافت نشد.');
|
||||
}
|
||||
|
||||
return response()->json($service->listForCustomer($customer));
|
||||
}
|
||||
|
||||
public function store(Request $request, CopperConvertRequestService $service)
|
||||
{
|
||||
$customer = auth('customer')->user();
|
||||
@@ -35,4 +45,45 @@ class CopperConvertRequestController extends Controller
|
||||
|
||||
return response()->json($row);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id, CopperConvertRequestService $service)
|
||||
{
|
||||
$customer = $this->customer();
|
||||
self::assertCustomerIdentityVerified($customer);
|
||||
if (!$customer->trade_active) {
|
||||
throw new UnprocessableEntityHttpException('امکان سفارش برای شما غیرفعال است.');
|
||||
}
|
||||
|
||||
$source = (string) $request->input('source');
|
||||
if (!in_array($source, ['katod', 'maftoul', 'shamsh'], true)) {
|
||||
throw new UnprocessableEntityHttpException('نوع دارایی نامعتبر است.');
|
||||
}
|
||||
|
||||
$row = $service->update(
|
||||
$customer,
|
||||
$id,
|
||||
$source,
|
||||
max(0, (int) $request->input('rings15')),
|
||||
max(0, (int) $request->input('rings25'))
|
||||
);
|
||||
|
||||
return response()->json($row);
|
||||
}
|
||||
|
||||
public function destroy(int $id, CopperConvertRequestService $service)
|
||||
{
|
||||
$service->remove($this->customer(), $id);
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
private function customer(): Customer
|
||||
{
|
||||
$customer = auth('customer')->user();
|
||||
if (!$customer instanceof Customer) {
|
||||
throw new UnprocessableEntityHttpException('مشتری یافت نشد.');
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user