143 lines
3.7 KiB
PHP
143 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\CardPin;
|
|
|
|
use App\Http\Controllers\Api\CardPin\Requests\CardPinIndexResource;
|
|
use App\Http\Controllers\Api\CardPin\Requests\CardPinStoreRequest;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Order\Card\CardPin\CardPin;
|
|
use App\Repos\Order\OrderRepo;
|
|
use Dedoc\Scramble\Attributes\Group;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
#[Group('Sargytlar - Kart - Kart pin bukjalar')]
|
|
class CardPinController extends Controller
|
|
{
|
|
/**
|
|
* LIST*
|
|
*/
|
|
public function index(): JsonResponse
|
|
{
|
|
return response()->json(CardPinIndexResource::collection(
|
|
CardPin::query()
|
|
->with('branch', 'cardType')
|
|
->where('user_id', auth()->id())
|
|
->get()
|
|
));
|
|
}
|
|
|
|
/**
|
|
* SAVE*
|
|
*/
|
|
public function store(CardPinStoreRequest $request): JsonResponse
|
|
{
|
|
$data = $request->validated();
|
|
|
|
CardPin::forceCreate([
|
|
...$data,
|
|
...[
|
|
'status' => OrderRepo::PENDING,
|
|
'user_id' => auth()->id(),
|
|
],
|
|
...$this->uploadedFiles($request),
|
|
]);
|
|
|
|
return response()->json([
|
|
'message' => __('Successfully created'),
|
|
], 201);
|
|
}
|
|
|
|
/**
|
|
* Upload files
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function uploadedFiles(Request $request): array
|
|
{
|
|
$files = [];
|
|
|
|
foreach (['passport_one', 'passport_two', 'passport_three', 'passport_four'] as $field) {
|
|
if ($request->hasFile($field)) {
|
|
$files[$field] = Str::after($request->file($field)->store('public'), 'public/');
|
|
}
|
|
}
|
|
|
|
return $files;
|
|
}
|
|
|
|
/**
|
|
* SHOW*
|
|
*
|
|
* ID ugradyp alyan route -da.
|
|
*/
|
|
public function show(CardPin $order): JsonResponse
|
|
{
|
|
if ($order->user_id != auth()->id()) {
|
|
return response()->json(status: 403);
|
|
}
|
|
|
|
return response()->json(new CardPinIndexResource($order));
|
|
}
|
|
|
|
// /**
|
|
// * UPDATE*
|
|
// *
|
|
// * ID ugradyp `route`-da update edip bilyan. Base App Enum-lardan peydalan. Panelkadan gor.
|
|
// */
|
|
// public function update(Request $request, CardBalance $order): JsonResponse
|
|
// {
|
|
// $data = $request->validate([
|
|
// /**
|
|
// * @example I-AS
|
|
// */
|
|
// 'passport_serie' => ['sometimes', Rule::in(array_keys(PassportRepo::values()))],
|
|
|
|
// /**
|
|
// * @example 379514
|
|
// */
|
|
// 'passport_id' => ['sometimes', 'numeric', 'digits:6'],
|
|
|
|
// /**
|
|
// * @example 9934612100000243
|
|
// */
|
|
// 'card_number' => ['sometimes', 'digits:16'],
|
|
|
|
// /**
|
|
// * @example 12
|
|
// */
|
|
// 'card_month' => ['sometimes', Rule::in(array_keys(DateHelperRepository::staticNumberMonths()))],
|
|
|
|
// /**
|
|
// * @example 2049
|
|
// */
|
|
// 'card_year' => ['sometimes', Rule::in(array_keys(DateHelperRepository::staticNumberYears()))],
|
|
// ]);
|
|
|
|
// Model::unguarded(function () use ($order, $data) {
|
|
// $order->update($data);
|
|
// });
|
|
|
|
// return response()->json([
|
|
// 'message' => __('Successfully updated'),
|
|
// ]);
|
|
// }
|
|
|
|
// /**
|
|
// * DELETE*
|
|
// */
|
|
// public function destroy(CardBalance $order): JsonResponse
|
|
// {
|
|
// if ($order->user_id != auth()->id()) {
|
|
// return response()->json(status: 403);
|
|
// }
|
|
|
|
// $order->delete();
|
|
|
|
// return response()->json([
|
|
// 'message' => __('Successfully deleted'),
|
|
// ]);
|
|
// }
|
|
}
|