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

@@ -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(),
];
}
}