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(); if (!$customer instanceof Customer) { throw new UnprocessableEntityHttpException('مشتری یافت نشد.'); } 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->submit( $customer, $source, max(0, (int) $request->input('rings15')), max(0, (int) $request->input('rings25')) ); 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; } }