feat: add ApiResponse trait for standardized API responses

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
This commit is contained in:
2026-07-07 01:03:12 +03:30
parent cf0e6f82fd
commit ae974c2afa
68 changed files with 3594 additions and 100 deletions

View File

@@ -7,6 +7,7 @@ use App\Http\Requests\Auth\LoginRequest;
use App\Http\Requests\Auth\RegisterRequest;
use App\Http\Resources\UserResource;
use App\Models\User;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
@@ -14,6 +15,8 @@ use OpenApi\Attributes as OA;
class AuthController extends Controller
{
use ApiResponse;
#[OA\Post(
path: '/auth/register',
description: 'Register a new user account',
@@ -64,12 +67,9 @@ class AuthController extends Controller
$token = $user->createToken('auth-token')->plainTextToken;
return response()->json([
'message' => 'ثبت‌نام با موفقیت انجام شد.',
'data' => [
'user' => new UserResource($user),
'token' => $token,
],
return $this->success('ثبت‌نام با موفقیت انجام شد.', [
'user' => new UserResource($user),
'token' => $token,
], 201);
}
@@ -121,22 +121,16 @@ class AuthController extends Controller
->first();
if (! $user || ! Hash::check($request->validated('password'), $user->password)) {
return response()->json([
'message' => 'اطلاعات ورود نادرست است.',
'errors' => [
'login' => ['ایمیل یا نام کاربری یا رمز عبور اشتباه است.'],
],
], 422);
return $this->error('اطلاعات ورود نادرست است.', [
'login' => ['ایمیل یا نام کاربری یا رمز عبور اشتباه است.'],
]);
}
$token = $user->createToken('auth-token')->plainTextToken;
return response()->json([
'message' => 'ورود با موفقیت انجام شد.',
'data' => [
'user' => new UserResource($user),
'token' => $token,
],
return $this->success('ورود با موفقیت انجام شد.', [
'user' => new UserResource($user),
'token' => $token,
]);
}
@@ -147,7 +141,7 @@ class AuthController extends Controller
$counter = 1;
while (User::query()->where('username', $username)->exists()) {
$username = $base.$counter;
$username = $base . $counter;
$counter++;
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Resources\CategoryResource;
use App\Models\Category;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use OpenApi\Attributes as OA;
class CategoryController extends Controller
{
use ApiResponse;
#[OA\Get(
path: '/categories',
description: 'List active template categories',
summary: 'List categories',
tags: ['Templates'],
responses: [
new OA\Response(
response: 200,
description: 'Categories 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: 'categories',
type: 'array',
items: new OA\Items(ref: '#/components/schemas/Category')
),
],
type: 'object'
),
]
)
),
]
)]
public function index(): JsonResponse
{
$categories = Category::query()->where('is_active', true)->orderBy('name')->get();
return $this->success('دسته‌بندی‌ها با موفقیت دریافت شد.', [
'categories' => CategoryResource::collection($categories),
]);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Resources\NotificationResource;
use App\Services\NotificationService;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use OpenApi\Attributes as OA;
class NotificationController extends Controller
{
use ApiResponse;
public function __construct(private readonly NotificationService $notificationService) {}
#[OA\Get(
path: '/notifications',
description: 'Get the authenticated user notifications',
summary: 'List notifications',
security: [['sanctum' => []]],
tags: ['Notifications'],
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: 'Notifications 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: 'notifications',
type: 'array',
items: new OA\Items(ref: '#/components/schemas/Notification')
),
],
type: 'object'
),
]
)
),
new OA\Response(response: 401, description: 'Unauthenticated'),
]
)]
public function index(Request $request): JsonResponse
{
$perPage = min(max((int) $request->integer('per_page', 15), 1), 100);
$notifications = $request->user()->notifications()->paginate($perPage);
return $this->success('نوتیفیکیشن‌ها با موفقیت دریافت شد.', [
'notifications' => NotificationResource::collection($notifications)->response()->getData(true),
]);
}
#[OA\Post(
path: '/notifications/read-all',
description: 'Mark all the authenticated user notifications as read',
summary: 'Mark all notifications as read',
security: [['sanctum' => []]],
tags: ['Notifications'],
responses: [
new OA\Response(
response: 200,
description: 'Notifications marked as read successfully',
content: new OA\JsonContent(
properties: [
new OA\Property(property: 'message', type: 'string', example: 'همه نوتیفیکیشن‌ها خوانده شد.'),
new OA\Property(property: 'data', type: 'object'),
]
)
),
new OA\Response(response: 401, description: 'Unauthenticated'),
]
)]
public function markAllAsRead(Request $request): JsonResponse
{
$this->notificationService->markAllAsRead($request->user());
return $this->success('همه نوتیفیکیشن‌ها خوانده شد.');
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\Profile\UpdateProfileRequest;
use App\Http\Resources\UserResource;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use OpenApi\Attributes as OA;
class ProfileController extends Controller
{
use ApiResponse;
#[OA\Get(
path: '/profile',
description: 'Get the authenticated user profile',
summary: 'Show profile',
security: [['sanctum' => []]],
tags: ['Profile'],
responses: [
new OA\Response(
response: 200,
description: 'Profile 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: 'user', ref: '#/components/schemas/User'),
],
type: 'object'
),
]
)
),
new OA\Response(response: 401, description: 'Unauthenticated'),
]
)]
public function show(): JsonResponse
{
return $this->success('اطلاعات پروفایل با موفقیت دریافت شد.', [
'user' => new UserResource(request()->user()),
]);
}
#[OA\Put(
path: '/profile',
description: 'Update the authenticated user profile',
summary: 'Update profile',
security: [['sanctum' => []]],
tags: ['Profile'],
requestBody: new OA\RequestBody(
required: true,
content: new OA\JsonContent(
properties: [
new OA\Property(property: 'name', type: 'string', example: 'علی رضایی'),
new OA\Property(property: 'username', type: 'string', example: 'ali'),
new OA\Property(property: 'email', type: 'string', format: 'email', example: 'ali@example.com'),
new OA\Property(property: 'mobile', type: 'string', example: '09123456789'),
new OA\Property(property: 'password', type: 'string', format: 'password', example: 'password123'),
]
)
),
responses: [
new OA\Response(
response: 200,
description: 'Profile updated successfully',
content: new OA\JsonContent(
properties: [
new OA\Property(property: 'message', type: 'string', example: 'پروفایل با موفقیت به‌روزرسانی شد.'),
new OA\Property(
property: 'data',
properties: [
new OA\Property(property: 'user', ref: '#/components/schemas/User'),
],
type: 'object'
),
]
)
),
new OA\Response(response: 401, description: 'Unauthenticated'),
new OA\Response(response: 422, description: 'Validation error'),
]
)]
public function update(UpdateProfileRequest $request): JsonResponse
{
$user = $request->user();
$user->update($request->validated());
return $this->success('پروفایل با موفقیت به‌روزرسانی شد.', [
'user' => new UserResource($user->fresh()),
]);
}
}

View File

@@ -0,0 +1,104 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Resources\TemplateResource;
use App\Models\Template;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use OpenApi\Attributes as OA;
class TemplateController extends Controller
{
use ApiResponse;
#[OA\Get(
path: '/templates',
description: 'List active templates, optionally filtered by category',
summary: 'List templates',
tags: ['Templates'],
parameters: [
new OA\Parameter(name: 'category', description: 'Category slug', in: 'query', schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'Templates 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: 'templates',
type: 'array',
items: new OA\Items(ref: '#/components/schemas/Template')
),
],
type: 'object'
),
]
)
),
]
)]
public function index(Request $request): JsonResponse
{
$templates = Template::query()
->with('category')
->where('is_active', true)
->when(
$request->string('category')->isNotEmpty(),
fn ($query) => $query->whereHas(
'category',
fn ($categoryQuery) => $categoryQuery->where('slug', $request->string('category'))
)
)
->orderBy('title')
->get();
return $this->success('قالب‌ها با موفقیت دریافت شد.', [
'templates' => TemplateResource::collection($templates),
]);
}
#[OA\Get(
path: '/templates/{slug}',
description: 'Get a template details including its fillable keys',
summary: 'Show template',
tags: ['Templates'],
parameters: [
new OA\Parameter(name: 'slug', description: 'Template slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'Template 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: 'template', ref: '#/components/schemas/Template'),
],
type: 'object'
),
]
)
),
new OA\Response(response: 404, description: 'Template not found'),
]
)]
public function show(Template $template): JsonResponse
{
$template->load('category', 'keys');
return $this->success('قالب با موفقیت دریافت شد.', [
'template' => new TemplateResource($template),
]);
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace App\Http\Controllers\Api;
use App\Enums\TemplateGenerationStatus;
use App\Enums\TemplateKeyType;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\GenerateTemplateRequest;
use App\Http\Resources\TemplateGenerationResource;
use App\Jobs\GenerateTemplateJob;
use App\Models\Template;
use App\Models\TemplateGeneration;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use OpenApi\Attributes as OA;
use Symfony\Component\HttpFoundation\StreamedResponse;
class TemplateGenerationController extends Controller
{
use ApiResponse;
#[OA\Post(
path: '/templates/{slug}/generate',
description: 'Start generating a filled presentation from a template',
summary: 'Generate presentation',
security: [['sanctum' => []]],
tags: ['Templates'],
parameters: [
new OA\Parameter(name: 'slug', description: 'Template slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 202,
description: 'Generation started',
content: new OA\JsonContent(
properties: [
new OA\Property(property: 'message', type: 'string', example: 'درخواست تولید پاورپوینت ثبت شد.'),
new OA\Property(
property: 'data',
properties: [
new OA\Property(property: 'generation', ref: '#/components/schemas/TemplateGeneration'),
],
type: 'object'
),
]
)
),
new OA\Response(response: 401, description: 'Unauthenticated'),
new OA\Response(response: 422, description: 'Validation error'),
]
)]
public function store(GenerateTemplateRequest $request, Template $template): JsonResponse
{
$uuid = (string) Str::uuid();
$values = $request->validated('values', []);
$storedValues = [];
foreach ($template->keys as $key) {
if (! array_key_exists($key->key, $values)) {
continue;
}
if ($key->type === TemplateKeyType::Image) {
$storedValues[$key->key] = $request->file('values.'.$key->key)
->store('templates/generations/inputs/'.$uuid, 'local');
continue;
}
$storedValues[$key->key] = $values[$key->key];
}
$generation = TemplateGeneration::query()->create([
'template_id' => $template->id,
'uuid' => $uuid,
'status' => TemplateGenerationStatus::Pending,
'values' => $storedValues,
'requested_by' => $request->user()->id,
]);
GenerateTemplateJob::dispatch($generation);
return $this->success('درخواست تولید پاورپوینت ثبت شد.', [
'generation' => new TemplateGenerationResource($generation),
], 202);
}
#[OA\Get(
path: '/generations/{uuid}',
description: 'Get the status of a presentation generation request',
summary: 'Show generation status',
security: [['sanctum' => []]],
tags: ['Templates'],
parameters: [
new OA\Parameter(name: 'uuid', description: 'Generation uuid', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'Generation status 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: 'generation', ref: '#/components/schemas/TemplateGeneration'),
],
type: 'object'
),
]
)
),
new OA\Response(response: 401, description: 'Unauthenticated'),
new OA\Response(response: 403, description: 'Forbidden'),
new OA\Response(response: 404, description: 'Not found'),
]
)]
public function show(TemplateGeneration $generation): JsonResponse
{
abort_if($generation->requested_by !== request()->user()->id, 403);
return $this->success('وضعیت تولید با موفقیت دریافت شد.', [
'generation' => new TemplateGenerationResource($generation),
]);
}
#[OA\Get(
path: '/generations/{uuid}/download',
description: 'Download the generated presentation file',
summary: 'Download generated presentation',
security: [['sanctum' => []]],
tags: ['Templates'],
parameters: [
new OA\Parameter(name: 'uuid', description: 'Generation uuid', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(response: 200, description: 'File download'),
new OA\Response(response: 401, description: 'Unauthenticated'),
new OA\Response(response: 403, description: 'Forbidden'),
new OA\Response(response: 404, description: 'Not found or not ready'),
]
)]
public function download(TemplateGeneration $generation): StreamedResponse
{
abort_if($generation->requested_by !== request()->user()->id, Response::HTTP_FORBIDDEN);
abort_if($generation->status !== TemplateGenerationStatus::Completed || ! $generation->output_path, Response::HTTP_NOT_FOUND);
return Storage::disk('local')->download($generation->output_path, $generation->template->slug.'.pptx');
}
}

View File

@@ -0,0 +1,100 @@
<?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),
]);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Http\Requests\Api;
use App\Enums\TemplateKeyType;
use App\Models\Template;
use Illuminate\Foundation\Http\FormRequest;
class GenerateTemplateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
/** @var Template $template */
$template = $this->route('template');
$rules = [];
foreach ($template->keys as $key) {
$fieldRules = [$key->is_required ? 'required' : 'nullable'];
$fieldRules[] = match ($key->type) {
TemplateKeyType::Text => 'string',
TemplateKeyType::Image => 'file|image',
TemplateKeyType::Chart => 'prohibited',
};
$rules['values.'.$key->key] = $fieldRules;
}
return $rules;
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'*.prohibited' => 'کلید :attribute از نوع چارت است و فعلاً پشتیبانی نمی‌شود.',
];
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Http\Requests\Profile;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UpdateProfileRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$userId = $this->user()->id;
return [
'name' => ['sometimes', 'required', 'string', 'max:255'],
'username' => ['sometimes', 'required', 'string', 'max:255', Rule::unique('users', 'username')->ignore($userId)],
'email' => ['sometimes', 'required', 'string', 'email', 'max:255', Rule::unique('users', 'email')->ignore($userId)],
'mobile' => ['sometimes', 'required', 'string', 'regex:/^09\d{9}$/', Rule::unique('users', 'mobile')->ignore($userId)],
'password' => ['sometimes', 'required', 'string', 'min:8'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array
{
return [
'name.required' => 'نام و نام خانوادگی الزامی است.',
'username.required' => 'نام کاربری الزامی است.',
'username.unique' => 'این نام کاربری قبلاً استفاده شده است.',
'email.required' => 'ایمیل الزامی است.',
'email.email' => 'فرمت ایمیل صحیح نیست.',
'email.unique' => 'این ایمیل قبلاً ثبت شده است.',
'mobile.required' => 'شماره موبایل الزامی است.',
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست.',
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
'password.required' => 'رمز عبور الزامی است.',
'password.min' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
];
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Resources;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Attributes as OA;
#[OA\Schema(
schema: 'Category',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'name', type: 'string', example: 'کسب‌وکار'),
new OA\Property(property: 'slug', type: 'string', example: 'business'),
new OA\Property(property: 'description', type: 'string', example: 'قالب‌های ارائه کسب‌وکار', nullable: true),
]
)]
/** @mixin Category */
class CategoryResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
];
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Resources;
use App\Models\Notification;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Attributes as OA;
#[OA\Schema(
schema: 'Notification',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'type', type: 'string', example: 'system'),
new OA\Property(property: 'type_label', type: 'string', example: 'سیستمی'),
new OA\Property(property: 'title', type: 'string', example: 'خوش آمدید'),
new OA\Property(property: 'body', type: 'string', example: 'به هوش‌پوینت خوش آمدید.'),
new OA\Property(property: 'data', type: 'object', nullable: true),
new OA\Property(property: 'read_at', type: 'string', format: 'date-time', nullable: true),
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
]
)]
/** @mixin Notification */
class NotificationResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'type' => $this->type->value,
'type_label' => $this->type->label(),
'title' => $this->title,
'body' => $this->body,
'data' => $this->data,
'read_at' => $this->read_at?->toIso8601String(),
'created_at' => $this->created_at?->toIso8601String(),
];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Http\Resources;
use App\Models\TemplateGeneration;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Attributes as OA;
#[OA\Schema(
schema: 'TemplateGeneration',
properties: [
new OA\Property(property: 'uuid', type: 'string', example: '9d6f0b1e-9a3a-4f0a-8a1a-6c9a2e5b3d10'),
new OA\Property(property: 'status', type: 'string', example: 'completed'),
new OA\Property(property: 'status_label', type: 'string', example: 'تکمیل شده'),
new OA\Property(property: 'error_message', type: 'string', example: null, nullable: true),
new OA\Property(property: 'download_url', type: 'string', example: 'https://example.com/api/generations/9d6f.../download', nullable: true),
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
]
)]
/** @mixin TemplateGeneration */
class TemplateGenerationResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'uuid' => $this->uuid,
'status' => $this->status->value,
'status_label' => $this->status->label(),
'error_message' => $this->error_message,
'download_url' => $this->output_path ? route('api.generations.download', $this->uuid) : null,
'created_at' => $this->created_at?->toIso8601String(),
];
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Http\Resources;
use App\Models\TemplateKey;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Attributes as OA;
#[OA\Schema(
schema: 'TemplateKey',
properties: [
new OA\Property(property: 'key', type: 'string', example: 'title'),
new OA\Property(property: 'label', type: 'string', example: 'عنوان اسلاید'),
new OA\Property(property: 'type', type: 'string', example: 'text'),
new OA\Property(property: 'type_label', type: 'string', example: 'متن'),
new OA\Property(property: 'is_required', type: 'boolean', example: true),
new OA\Property(property: 'description', type: 'string', example: 'عنوان اصلی اسلاید نخست', nullable: true),
]
)]
/** @mixin TemplateKey */
class TemplateKeyResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'key' => $this->key,
'label' => $this->label,
'type' => $this->type->value,
'type_label' => $this->type->label(),
'is_required' => $this->is_required,
'description' => $this->description,
];
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Resources;
use App\Models\Template;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Attributes as OA;
#[OA\Schema(
schema: 'Template',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'title', type: 'string', example: 'گزارش فروش ماهانه'),
new OA\Property(property: 'slug', type: 'string', example: 'monthly-sales-report'),
new OA\Property(property: 'description', type: 'string', example: 'قالب گزارش فروش ماهانه', nullable: true),
new OA\Property(property: 'thumbnail_url', type: 'string', example: 'https://example.com/storage/templates/thumbnails/1.png', nullable: true),
new OA\Property(property: 'category', ref: '#/components/schemas/Category'),
new OA\Property(
property: 'keys',
type: 'array',
items: new OA\Items(ref: '#/components/schemas/TemplateKey')
),
]
)]
/** @mixin Template */
class TemplateResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'description' => $this->description,
'thumbnail_url' => $this->thumbnail_path ? asset('storage/'.$this->thumbnail_path) : null,
'category' => new CategoryResource($this->whenLoaded('category')),
'keys' => TemplateKeyResource::collection($this->whenLoaded('keys')),
];
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Resources;
use App\Models\Wallet;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Attributes as OA;
#[OA\Schema(
schema: 'Wallet',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'balance', type: 'integer', example: 500000),
new OA\Property(property: 'is_active', type: 'boolean', example: true),
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
]
)]
/** @mixin Wallet */
class WalletResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'balance' => $this->balance,
'is_active' => $this->is_active,
'created_at' => $this->created_at?->toIso8601String(),
];
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Http\Resources;
use App\Models\WalletTransaction;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Attributes as OA;
#[OA\Schema(
schema: 'WalletTransaction',
properties: [
new OA\Property(property: 'id', type: 'integer', example: 1),
new OA\Property(property: 'type', type: 'string', example: 'credit'),
new OA\Property(property: 'type_label', type: 'string', example: 'واریز'),
new OA\Property(property: 'amount', type: 'integer', example: 100000),
new OA\Property(property: 'balance_before', type: 'integer', example: 400000),
new OA\Property(property: 'balance_after', type: 'integer', example: 500000),
new OA\Property(property: 'description', type: 'string', example: 'شارژ کیف پول', nullable: true),
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
]
)]
/** @mixin WalletTransaction */
class WalletTransactionResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'type' => $this->type->value,
'type_label' => $this->type->label(),
'amount' => $this->amount,
'balance_before' => $this->balance_before,
'balance_after' => $this->balance_after,
'description' => $this->description,
'created_at' => $this->created_at?->toIso8601String(),
];
}
}