147 lines
3.8 KiB
PHP
147 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\CardTransaction;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Order\Card\CardTransaction\CardTransaction;
|
|
use App\Modules\DateHelper\Repositories\DateHelperRepository;
|
|
use App\Repos\System\Settings\Legal\PassportRepo;
|
|
use Dedoc\Scramble\Attributes\Group;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
#[Group('Sargytlar - Kart - Kart hereketleri')]
|
|
class CardTransactionsController extends Controller
|
|
{
|
|
/**
|
|
* LIST*
|
|
*/
|
|
public function index(): JsonResponse
|
|
{
|
|
return response()->json(
|
|
CardTransaction::query()
|
|
->where('user_id', auth()->id())
|
|
->get()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* SAVE*
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
/**
|
|
* @example I-AS
|
|
*/
|
|
'passport_serie' => ['required', Rule::in(array_keys(PassportRepo::values()))],
|
|
|
|
/**
|
|
* @example 379514
|
|
*/
|
|
'passport_id' => ['required', 'numeric', 'digits:6'],
|
|
|
|
/**
|
|
* @example 9934612100000243
|
|
*/
|
|
'card_number' => ['required', 'digits:16'],
|
|
|
|
/**
|
|
* @example 12
|
|
*/
|
|
'card_month' => ['required', Rule::in(array_keys(DateHelperRepository::staticNumberMonths()))],
|
|
|
|
/**
|
|
* @example 2049
|
|
*/
|
|
'card_year' => ['required', Rule::in(array_keys(DateHelperRepository::staticNumberYears()))]
|
|
]);
|
|
|
|
CardTransaction::forceCreate([
|
|
...$data,
|
|
...[
|
|
'user_id' => auth()->id(),
|
|
],
|
|
]);
|
|
|
|
return response()->json([
|
|
'message' => __('Successfully created'),
|
|
], 201);
|
|
}
|
|
|
|
/**
|
|
* SHOW*
|
|
*
|
|
* ID ugradyp alyan route -da.
|
|
*/
|
|
public function show(CardTransaction $order): JsonResponse
|
|
{
|
|
if ($order->user_id != auth()->id()) {
|
|
return response()->json(status: 403);
|
|
}
|
|
|
|
return response()->json($order);
|
|
}
|
|
|
|
/**
|
|
* UPDATE*
|
|
*
|
|
* ID ugradyp `route`-da update edip bilyan. Base App Enum-lardan peydalan. Panelkadan gor.
|
|
*/
|
|
public function update(Request $request, CardTransaction $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(LoanRemainingOrder $order): JsonResponse
|
|
// {
|
|
// if ($order->user_id != auth()->id()) {
|
|
// return response()->json(status: 403);
|
|
// }
|
|
|
|
// $order->delete();
|
|
|
|
// return response()->json([
|
|
// 'message' => __('Successfully deleted'),
|
|
// ]);
|
|
// }
|
|
}
|