chore: update composer dependencies to include phppresentation chore: update composer.lock after adding phppresentation feat: create categories migration for category management feat: create templates migration for template storage feat: create template generations migration for tracking template usage feat: create template keys migration for template customization feat: create notifications migration for user notifications feat: update API routes for categories, templates, and user profile management docs: update API documentation to include new endpoints for profile and wallet
101 lines
3.8 KiB
PHP
101 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\WalletResource;
|
|
use App\Http\Resources\WalletTransactionResource;
|
|
use App\Services\WalletService;
|
|
use App\Traits\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use OpenApi\Attributes as OA;
|
|
|
|
class WalletController extends Controller
|
|
{
|
|
use ApiResponse;
|
|
|
|
public function __construct(private readonly WalletService $walletService) {}
|
|
|
|
#[OA\Get(
|
|
path: '/wallet',
|
|
description: 'Get the authenticated user wallet',
|
|
summary: 'Show wallet',
|
|
security: [['sanctum' => []]],
|
|
tags: ['Wallet'],
|
|
responses: [
|
|
new OA\Response(
|
|
response: 200,
|
|
description: 'Wallet fetched successfully',
|
|
content: new OA\JsonContent(
|
|
properties: [
|
|
new OA\Property(property: 'message', type: 'string', example: 'اطلاعات کیف پول با موفقیت دریافت شد.'),
|
|
new OA\Property(
|
|
property: 'data',
|
|
properties: [
|
|
new OA\Property(property: 'wallet', ref: '#/components/schemas/Wallet'),
|
|
],
|
|
type: 'object'
|
|
),
|
|
]
|
|
)
|
|
),
|
|
new OA\Response(response: 401, description: 'Unauthenticated'),
|
|
]
|
|
)]
|
|
public function show(Request $request): JsonResponse
|
|
{
|
|
$wallet = $this->walletService->createForUser($request->user());
|
|
|
|
return $this->success('اطلاعات کیف پول با موفقیت دریافت شد.', [
|
|
'wallet' => new WalletResource($wallet),
|
|
]);
|
|
}
|
|
|
|
#[OA\Get(
|
|
path: '/wallet/transactions',
|
|
description: 'Get the authenticated user wallet transactions',
|
|
summary: 'List wallet transactions',
|
|
security: [['sanctum' => []]],
|
|
tags: ['Wallet'],
|
|
parameters: [
|
|
new OA\Parameter(name: 'per_page', description: 'Items per page', in: 'query', schema: new OA\Schema(type: 'integer', example: 15)),
|
|
],
|
|
responses: [
|
|
new OA\Response(
|
|
response: 200,
|
|
description: 'Wallet transactions fetched successfully',
|
|
content: new OA\JsonContent(
|
|
properties: [
|
|
new OA\Property(property: 'message', type: 'string', example: 'تراکنشهای کیف پول با موفقیت دریافت شد.'),
|
|
new OA\Property(
|
|
property: 'data',
|
|
properties: [
|
|
new OA\Property(
|
|
property: 'transactions',
|
|
type: 'array',
|
|
items: new OA\Items(ref: '#/components/schemas/WalletTransaction')
|
|
),
|
|
],
|
|
type: 'object'
|
|
),
|
|
]
|
|
)
|
|
),
|
|
new OA\Response(response: 401, description: 'Unauthenticated'),
|
|
]
|
|
)]
|
|
public function transactions(Request $request): JsonResponse
|
|
{
|
|
$wallet = $this->walletService->createForUser($request->user());
|
|
|
|
$perPage = min(max((int) $request->integer('per_page', 15), 1), 100);
|
|
|
|
$transactions = $wallet->transactions()->paginate($perPage);
|
|
|
|
return $this->success('تراکنشهای کیف پول با موفقیت دریافت شد.', [
|
|
'transactions' => WalletTransactionResource::collection($transactions)->response()->getData(true),
|
|
]);
|
|
}
|
|
}
|