wip
This commit is contained in:
175
app/Http/Controllers/Api/CardBalance/CardBalanceController.php
Normal file
175
app/Http/Controllers/Api/CardBalance/CardBalanceController.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\CardBalance;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order\Card\CardBalance\CardBalance;
|
||||
use App\Modules\DateHelper\Repositories\DateHelperRepository;
|
||||
use App\Nova\Resources\Order\Card\CardBalance\Actions\DownloadCardBalance;
|
||||
use App\Repos\System\Settings\Legal\PassportRepo;
|
||||
use Dedoc\Scramble\Attributes\Group;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
#[Group('Sargytlar - Kart - Kart galyndylary')]
|
||||
class CardBalanceController extends Controller
|
||||
{
|
||||
/**
|
||||
* LIST*
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return response()->json(
|
||||
CardBalance::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()))],
|
||||
]);
|
||||
|
||||
CardBalance::forceCreate([
|
||||
...$data,
|
||||
...[
|
||||
'user_id' => auth()->id(),
|
||||
],
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => __('Successfully created'),
|
||||
], 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* SHOW*
|
||||
*
|
||||
* ID ugradyp alyan route -da. Soň page-da download button bolmaly, basaňdan soň, modal çykmaly, start date bilen end date ugradyp download basanda `/api/card-transactions-download/{order}` route gelyan pdf download etmeli.
|
||||
*/
|
||||
public function show(CardBalance $order): JsonResponse
|
||||
{
|
||||
if ($order->user_id != auth()->id()) {
|
||||
return response()->json(status: 403);
|
||||
}
|
||||
|
||||
return response()->json($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download*
|
||||
*
|
||||
* Download card transaction file
|
||||
*/
|
||||
public function download(Request $request, CardBalance $order)
|
||||
{
|
||||
$response = DownloadCardBalance::make()->fetchApi(
|
||||
passport_serie: $order->passport_serie,
|
||||
passport_id: $order->passport_id,
|
||||
card_masked: Str::mask($order->card_number, '*', 6, 6),
|
||||
card_expire_date: $order->card_month.'/'.substr($order->card_year, 2),
|
||||
);
|
||||
|
||||
if ($response->errCode != 0) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => $response->message,
|
||||
'url' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => $response
|
||||
]);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 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(CardTransaction $order): JsonResponse
|
||||
// {
|
||||
// if ($order->user_id != auth()->id()) {
|
||||
// return response()->json(status: 403);
|
||||
// }
|
||||
|
||||
// $order->delete();
|
||||
|
||||
// return response()->json([
|
||||
// 'message' => __('Successfully deleted'),
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use Laravel\Nova\Actions\Actionable;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $passport_serie
|
||||
* @property string $passport_id
|
||||
* @property string $card_number
|
||||
|
||||
Reference in New Issue
Block a user