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:
19
app/Enums/NotificationType.php
Normal file
19
app/Enums/NotificationType.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum NotificationType: string
|
||||||
|
{
|
||||||
|
case System = 'system';
|
||||||
|
case Wallet = 'wallet';
|
||||||
|
case Template = 'template';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::System => 'سیستمی',
|
||||||
|
self::Wallet => 'کیف پول',
|
||||||
|
self::Template => 'قالب',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
21
app/Enums/TemplateGenerationStatus.php
Normal file
21
app/Enums/TemplateGenerationStatus.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum TemplateGenerationStatus: string
|
||||||
|
{
|
||||||
|
case Pending = 'pending';
|
||||||
|
case Processing = 'processing';
|
||||||
|
case Completed = 'completed';
|
||||||
|
case Failed = 'failed';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Pending => 'در انتظار',
|
||||||
|
self::Processing => 'در حال تولید',
|
||||||
|
self::Completed => 'تکمیل شده',
|
||||||
|
self::Failed => 'ناموفق',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Enums/TemplateKeyType.php
Normal file
19
app/Enums/TemplateKeyType.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum TemplateKeyType: string
|
||||||
|
{
|
||||||
|
case Text = 'text';
|
||||||
|
case Image = 'image';
|
||||||
|
case Chart = 'chart';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Text => 'متن',
|
||||||
|
self::Image => 'عکس',
|
||||||
|
self::Chart => 'چارت',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
54
app/Filament/Resources/Categories/CategoryResource.php
Normal file
54
app/Filament/Resources/Categories/CategoryResource.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Categories;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Categories\Pages\CreateCategory;
|
||||||
|
use App\Filament\Resources\Categories\Pages\EditCategory;
|
||||||
|
use App\Filament\Resources\Categories\Pages\ListCategories;
|
||||||
|
use App\Filament\Resources\Categories\Schemas\CategoryForm;
|
||||||
|
use App\Filament\Resources\Categories\Tables\CategoriesTable;
|
||||||
|
use App\Models\Category;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class CategoryResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Category::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'پاورپوینتها';
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'name';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'دستهبندی';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'دستهبندیها';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'دستهبندیها';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 20;
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return CategoryForm::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return CategoriesTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListCategories::route('/'),
|
||||||
|
'create' => CreateCategory::route('/create'),
|
||||||
|
'edit' => EditCategory::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
11
app/Filament/Resources/Categories/Pages/CreateCategory.php
Normal file
11
app/Filament/Resources/Categories/Pages/CreateCategory.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Categories\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Categories\CategoryResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateCategory extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CategoryResource::class;
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Categories/Pages/EditCategory.php
Normal file
19
app/Filament/Resources/Categories/Pages/EditCategory.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Categories\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Categories\CategoryResource;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditCategory extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = CategoryResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Categories/Pages/ListCategories.php
Normal file
19
app/Filament/Resources/Categories/Pages/ListCategories.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Categories\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Categories\CategoryResource;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListCategories extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = CategoryResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Filament/Resources/Categories/Schemas/CategoryForm.php
Normal file
34
app/Filament/Resources/Categories/Schemas/CategoryForm.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Categories\Schemas;
|
||||||
|
|
||||||
|
use Filament\Forms\Components\Textarea;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class CategoryForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
TextInput::make('name')
|
||||||
|
->label('نام')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
TextInput::make('slug')
|
||||||
|
->label('شناسه')
|
||||||
|
->required()
|
||||||
|
->unique(ignoreRecord: true)
|
||||||
|
->maxLength(255),
|
||||||
|
Textarea::make('description')
|
||||||
|
->label('توضیحات')
|
||||||
|
->maxLength(1000)
|
||||||
|
->rows(3),
|
||||||
|
Toggle::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->default(true),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
55
app/Filament/Resources/Categories/Tables/CategoriesTable.php
Normal file
55
app/Filament/Resources/Categories/Tables/CategoriesTable.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Categories\Tables;
|
||||||
|
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Actions\DeleteBulkAction;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Tables\Columns\IconColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\TernaryFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class CategoriesTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('name')
|
||||||
|
->label('نام')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('slug')
|
||||||
|
->label('شناسه')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('templates_count')
|
||||||
|
->label('تعداد قالبها')
|
||||||
|
->counts('templates'),
|
||||||
|
IconColumn::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->boolean(),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ ایجاد')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
TernaryFilter::make('is_active')
|
||||||
|
->label('وضعیت')
|
||||||
|
->placeholder('همه')
|
||||||
|
->trueLabel('فعال')
|
||||||
|
->falseLabel('غیرفعال'),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
EditAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Notifications;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Notifications\Pages\CreateNotification;
|
||||||
|
use App\Filament\Resources\Notifications\Pages\EditNotification;
|
||||||
|
use App\Filament\Resources\Notifications\Pages\ListNotifications;
|
||||||
|
use App\Filament\Resources\Notifications\Pages\ViewNotification;
|
||||||
|
use App\Filament\Resources\Notifications\Schemas\NotificationForm;
|
||||||
|
use App\Filament\Resources\Notifications\Tables\NotificationsTable;
|
||||||
|
use App\Models\Notification;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class NotificationResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Notification::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBell;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'اعلانها';
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'title';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'نوتیفیکیشن';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'نوتیفیکیشنها';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'نوتیفیکیشنها';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 30;
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return NotificationForm::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return NotificationsTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListNotifications::route('/'),
|
||||||
|
'create' => CreateNotification::route('/create'),
|
||||||
|
'view' => ViewNotification::route('/{record}'),
|
||||||
|
'edit' => EditNotification::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Notifications\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Notifications\NotificationResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateNotification extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = NotificationResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Notifications\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Notifications\NotificationResource;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditNotification extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = NotificationResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ViewAction::make(),
|
||||||
|
DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Notifications\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Notifications\NotificationResource;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListNotifications extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = NotificationResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Notifications\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Notifications\NotificationResource;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewNotification extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = NotificationResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Notifications\Schemas;
|
||||||
|
|
||||||
|
use App\Enums\NotificationType;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\Textarea;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class NotificationForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
Select::make('user_id')
|
||||||
|
->label('کاربر')
|
||||||
|
->relationship('user', 'name')
|
||||||
|
->searchable()
|
||||||
|
->required(),
|
||||||
|
Select::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->options(collect(NotificationType::cases())->mapWithKeys(fn (NotificationType $type) => [$type->value => $type->label()]))
|
||||||
|
->required(),
|
||||||
|
TextInput::make('title')
|
||||||
|
->label('عنوان')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
Textarea::make('body')
|
||||||
|
->label('متن')
|
||||||
|
->required()
|
||||||
|
->rows(4),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Notifications\Tables;
|
||||||
|
|
||||||
|
use App\Enums\NotificationType;
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Actions\DeleteBulkAction;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Tables\Columns\IconColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Filters\TernaryFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class NotificationsTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('user.name')
|
||||||
|
->label('کاربر')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (NotificationType $state): string => $state->label()),
|
||||||
|
TextColumn::make('title')
|
||||||
|
->label('عنوان')
|
||||||
|
->searchable()
|
||||||
|
->limit(40),
|
||||||
|
IconColumn::make('read_at')
|
||||||
|
->label('خوانده شده')
|
||||||
|
->boolean()
|
||||||
|
->getStateUsing(fn ($record): bool => $record->read_at !== null),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ ایجاد')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->options(collect(NotificationType::cases())->mapWithKeys(fn (NotificationType $type) => [$type->value => $type->label()])),
|
||||||
|
TernaryFilter::make('read_at')
|
||||||
|
->label('وضعیت')
|
||||||
|
->placeholder('همه')
|
||||||
|
->trueLabel('خوانده شده')
|
||||||
|
->falseLabel('خوانده نشده')
|
||||||
|
->queries(
|
||||||
|
true: fn ($query) => $query->whereNotNull('read_at'),
|
||||||
|
false: fn ($query) => $query->whereNull('read_at'),
|
||||||
|
),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
ViewAction::make(),
|
||||||
|
EditAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TemplateGenerations\TemplateGenerationResource;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListTemplateGenerations extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = TemplateGenerationResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TemplateGenerations\TemplateGenerationResource;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewTemplateGeneration extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TemplateGenerationResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations\Tables;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class TemplateGenerationsTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('uuid')
|
||||||
|
->label('شناسه')
|
||||||
|
->searchable()
|
||||||
|
->copyable(),
|
||||||
|
TextColumn::make('template.title')
|
||||||
|
->label('قالب')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('status')
|
||||||
|
->label('وضعیت')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (TemplateGenerationStatus $state): string => $state->label())
|
||||||
|
->color(fn (TemplateGenerationStatus $state): string => match ($state) {
|
||||||
|
TemplateGenerationStatus::Pending => 'gray',
|
||||||
|
TemplateGenerationStatus::Processing => 'warning',
|
||||||
|
TemplateGenerationStatus::Completed => 'success',
|
||||||
|
TemplateGenerationStatus::Failed => 'danger',
|
||||||
|
}),
|
||||||
|
TextColumn::make('requester.name')
|
||||||
|
->label('درخواستدهنده')
|
||||||
|
->searchable()
|
||||||
|
->placeholder('—'),
|
||||||
|
TextColumn::make('error_message')
|
||||||
|
->label('خطا')
|
||||||
|
->limit(50)
|
||||||
|
->placeholder('—'),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ')
|
||||||
|
->dateTime()
|
||||||
|
->sortable(),
|
||||||
|
])
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('status')
|
||||||
|
->label('وضعیت')
|
||||||
|
->options([
|
||||||
|
TemplateGenerationStatus::Pending->value => TemplateGenerationStatus::Pending->label(),
|
||||||
|
TemplateGenerationStatus::Processing->value => TemplateGenerationStatus::Processing->label(),
|
||||||
|
TemplateGenerationStatus::Completed->value => TemplateGenerationStatus::Completed->label(),
|
||||||
|
TemplateGenerationStatus::Failed->value => TemplateGenerationStatus::Failed->label(),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
ViewAction::make(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations;
|
||||||
|
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Pages\ListTemplateGenerations;
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Pages\ViewTemplateGeneration;
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Tables\TemplateGenerationsTable;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class TemplateGenerationResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = TemplateGeneration::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentArrowDown;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'پاورپوینتها';
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'uuid';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'تولید';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'تولیدها';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'تولیدها';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 22;
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return TemplateGenerationsTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListTemplateGenerations::route('/'),
|
||||||
|
'view' => ViewTemplateGeneration::route('/{record}'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canCreate(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canEdit($record): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canDelete($record): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Filament/Resources/Templates/Pages/CreateTemplate.php
Normal file
22
app/Filament/Resources/Templates/Pages/CreateTemplate.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\TemplateResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateTemplate extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TemplateResource::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $data
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
$data['created_by'] = auth()->id();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
app/Filament/Resources/Templates/Pages/EditTemplate.php
Normal file
21
app/Filament/Resources/Templates/Pages/EditTemplate.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\TemplateResource;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditTemplate extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TemplateResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ViewAction::make(),
|
||||||
|
DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Templates/Pages/ListTemplates.php
Normal file
19
app/Filament/Resources/Templates/Pages/ListTemplates.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\TemplateResource;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListTemplates extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = TemplateResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Templates/Pages/ViewTemplate.php
Normal file
19
app/Filament/Resources/Templates/Pages/ViewTemplate.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\TemplateResource;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewTemplate extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TemplateResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\RelationManagers;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class GenerationsRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'generations';
|
||||||
|
|
||||||
|
protected static ?string $title = 'تولیدها';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'تولید';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'تولیدها';
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->recordTitleAttribute('uuid')
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('uuid')
|
||||||
|
->label('شناسه')
|
||||||
|
->searchable()
|
||||||
|
->copyable(),
|
||||||
|
TextColumn::make('status')
|
||||||
|
->label('وضعیت')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (TemplateGenerationStatus $state): string => $state->label())
|
||||||
|
->color(fn (TemplateGenerationStatus $state): string => match ($state) {
|
||||||
|
TemplateGenerationStatus::Pending => 'gray',
|
||||||
|
TemplateGenerationStatus::Processing => 'warning',
|
||||||
|
TemplateGenerationStatus::Completed => 'success',
|
||||||
|
TemplateGenerationStatus::Failed => 'danger',
|
||||||
|
}),
|
||||||
|
TextColumn::make('requester.name')
|
||||||
|
->label('درخواستدهنده')
|
||||||
|
->placeholder('—'),
|
||||||
|
TextColumn::make('error_message')
|
||||||
|
->label('خطا')
|
||||||
|
->limit(40)
|
||||||
|
->placeholder('—'),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ')
|
||||||
|
->dateTime()
|
||||||
|
->sortable(),
|
||||||
|
])
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('status')
|
||||||
|
->label('وضعیت')
|
||||||
|
->options([
|
||||||
|
TemplateGenerationStatus::Pending->value => TemplateGenerationStatus::Pending->label(),
|
||||||
|
TemplateGenerationStatus::Processing->value => TemplateGenerationStatus::Processing->label(),
|
||||||
|
TemplateGenerationStatus::Completed->value => TemplateGenerationStatus::Completed->label(),
|
||||||
|
TemplateGenerationStatus::Failed->value => TemplateGenerationStatus::Failed->label(),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->recordActions([])
|
||||||
|
->toolbarActions([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\RelationManagers;
|
||||||
|
|
||||||
|
use App\Enums\TemplateKeyType;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Tables\Columns\IconColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class KeysRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'keys';
|
||||||
|
|
||||||
|
protected static ?string $title = 'کلیدها';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'کلید';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'کلیدها';
|
||||||
|
|
||||||
|
public function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
TextInput::make('key')
|
||||||
|
->label('کلید')
|
||||||
|
->helperText('در فایل پاورپوینت برای متن بهصورت {{key}} و برای عکس/چارت بهصورت نام شکل (shape name) استفاده میشود.')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
TextInput::make('label')
|
||||||
|
->label('برچسب')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
Select::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->options([
|
||||||
|
TemplateKeyType::Text->value => TemplateKeyType::Text->label(),
|
||||||
|
TemplateKeyType::Image->value => TemplateKeyType::Image->label(),
|
||||||
|
TemplateKeyType::Chart->value => TemplateKeyType::Chart->label(),
|
||||||
|
])
|
||||||
|
->required()
|
||||||
|
->live(),
|
||||||
|
TextInput::make('shape_name')
|
||||||
|
->label('نام شکل (Shape Name)')
|
||||||
|
->helperText('نام شکل تعیینشده در Selection Pane نرمافزار PowerPoint')
|
||||||
|
->visible(fn (Get $get): bool => $get('type') !== TemplateKeyType::Text->value)
|
||||||
|
->maxLength(255),
|
||||||
|
TextInput::make('description')
|
||||||
|
->label('راهنما')
|
||||||
|
->helperText('توضیحی که برای مصرفکننده API نمایش داده میشود')
|
||||||
|
->maxLength(255),
|
||||||
|
Toggle::make('is_required')
|
||||||
|
->label('اجباری')
|
||||||
|
->default(true),
|
||||||
|
TextInput::make('sort_order')
|
||||||
|
->label('ترتیب نمایش')
|
||||||
|
->numeric()
|
||||||
|
->integer()
|
||||||
|
->default(0),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->recordTitleAttribute('key')
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('key')
|
||||||
|
->label('کلید')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('label')
|
||||||
|
->label('برچسب')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (TemplateKeyType $state): string => $state->label()),
|
||||||
|
TextColumn::make('shape_name')
|
||||||
|
->label('نام شکل')
|
||||||
|
->placeholder('—'),
|
||||||
|
IconColumn::make('is_required')
|
||||||
|
->label('اجباری')
|
||||||
|
->boolean(),
|
||||||
|
TextColumn::make('sort_order')
|
||||||
|
->label('ترتیب')
|
||||||
|
->sortable(),
|
||||||
|
])
|
||||||
|
->defaultSort('sort_order')
|
||||||
|
->headerActions([
|
||||||
|
CreateAction::make(),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
EditAction::make(),
|
||||||
|
DeleteAction::make(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
app/Filament/Resources/Templates/Schemas/TemplateForm.php
Normal file
54
app/Filament/Resources/Templates/Schemas/TemplateForm.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Schemas;
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use Filament\Forms\Components\FileUpload;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\Textarea;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class TemplateForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
Select::make('category_id')
|
||||||
|
->label('دستهبندی')
|
||||||
|
->options(fn (): array => Category::query()->pluck('name', 'id')->all())
|
||||||
|
->searchable()
|
||||||
|
->required(),
|
||||||
|
TextInput::make('title')
|
||||||
|
->label('عنوان')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
TextInput::make('slug')
|
||||||
|
->label('شناسه')
|
||||||
|
->required()
|
||||||
|
->unique(ignoreRecord: true)
|
||||||
|
->maxLength(255),
|
||||||
|
Textarea::make('description')
|
||||||
|
->label('توضیحات')
|
||||||
|
->maxLength(1000)
|
||||||
|
->rows(3),
|
||||||
|
FileUpload::make('file_path')
|
||||||
|
->label('فایل پاورپوینت')
|
||||||
|
->disk('local')
|
||||||
|
->directory('templates/sources')
|
||||||
|
->acceptedFileTypes(['application/vnd.openxmlformats-officedocument.presentationml.presentation'])
|
||||||
|
->required()
|
||||||
|
->visibility('private'),
|
||||||
|
FileUpload::make('thumbnail_path')
|
||||||
|
->label('تصویر بندانگشتی')
|
||||||
|
->disk('public')
|
||||||
|
->directory('templates/thumbnails')
|
||||||
|
->image(),
|
||||||
|
Toggle::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->default(true),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
61
app/Filament/Resources/Templates/Tables/TemplatesTable.php
Normal file
61
app/Filament/Resources/Templates/Tables/TemplatesTable.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Tables;
|
||||||
|
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Actions\DeleteBulkAction;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Tables\Columns\IconColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Filters\TernaryFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class TemplatesTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('title')
|
||||||
|
->label('عنوان')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('category.name')
|
||||||
|
->label('دستهبندی')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('keys_count')
|
||||||
|
->label('تعداد کلیدها')
|
||||||
|
->counts('keys'),
|
||||||
|
IconColumn::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->boolean(),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ ایجاد')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('category_id')
|
||||||
|
->label('دستهبندی')
|
||||||
|
->relationship('category', 'name'),
|
||||||
|
TernaryFilter::make('is_active')
|
||||||
|
->label('وضعیت')
|
||||||
|
->placeholder('همه')
|
||||||
|
->trueLabel('فعال')
|
||||||
|
->falseLabel('غیرفعال'),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
ViewAction::make(),
|
||||||
|
EditAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
66
app/Filament/Resources/Templates/TemplateResource.php
Normal file
66
app/Filament/Resources/Templates/TemplateResource.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\Pages\CreateTemplate;
|
||||||
|
use App\Filament\Resources\Templates\Pages\EditTemplate;
|
||||||
|
use App\Filament\Resources\Templates\Pages\ListTemplates;
|
||||||
|
use App\Filament\Resources\Templates\Pages\ViewTemplate;
|
||||||
|
use App\Filament\Resources\Templates\RelationManagers\GenerationsRelationManager;
|
||||||
|
use App\Filament\Resources\Templates\RelationManagers\KeysRelationManager;
|
||||||
|
use App\Filament\Resources\Templates\Schemas\TemplateForm;
|
||||||
|
use App\Filament\Resources\Templates\Tables\TemplatesTable;
|
||||||
|
use App\Models\Template;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class TemplateResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Template::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPresentationChartBar;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'پاورپوینتها';
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'title';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'قالب';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'قالبها';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'قالبها';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 21;
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return TemplateForm::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return TemplatesTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
KeysRelationManager::class,
|
||||||
|
GenerationsRelationManager::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListTemplates::route('/'),
|
||||||
|
'create' => CreateTemplate::route('/create'),
|
||||||
|
'view' => ViewTemplate::route('/{record}'),
|
||||||
|
'edit' => EditTemplate::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ use App\Http\Requests\Auth\LoginRequest;
|
|||||||
use App\Http\Requests\Auth\RegisterRequest;
|
use App\Http\Requests\Auth\RegisterRequest;
|
||||||
use App\Http\Resources\UserResource;
|
use App\Http\Resources\UserResource;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@@ -14,6 +15,8 @@ use OpenApi\Attributes as OA;
|
|||||||
|
|
||||||
class AuthController extends Controller
|
class AuthController extends Controller
|
||||||
{
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
#[OA\Post(
|
#[OA\Post(
|
||||||
path: '/auth/register',
|
path: '/auth/register',
|
||||||
description: 'Register a new user account',
|
description: 'Register a new user account',
|
||||||
@@ -64,12 +67,9 @@ class AuthController extends Controller
|
|||||||
|
|
||||||
$token = $user->createToken('auth-token')->plainTextToken;
|
$token = $user->createToken('auth-token')->plainTextToken;
|
||||||
|
|
||||||
return response()->json([
|
return $this->success('ثبتنام با موفقیت انجام شد.', [
|
||||||
'message' => 'ثبتنام با موفقیت انجام شد.',
|
'user' => new UserResource($user),
|
||||||
'data' => [
|
'token' => $token,
|
||||||
'user' => new UserResource($user),
|
|
||||||
'token' => $token,
|
|
||||||
],
|
|
||||||
], 201);
|
], 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,22 +121,16 @@ class AuthController extends Controller
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $user || ! Hash::check($request->validated('password'), $user->password)) {
|
if (! $user || ! Hash::check($request->validated('password'), $user->password)) {
|
||||||
return response()->json([
|
return $this->error('اطلاعات ورود نادرست است.', [
|
||||||
'message' => 'اطلاعات ورود نادرست است.',
|
'login' => ['ایمیل یا نام کاربری یا رمز عبور اشتباه است.'],
|
||||||
'errors' => [
|
]);
|
||||||
'login' => ['ایمیل یا نام کاربری یا رمز عبور اشتباه است.'],
|
|
||||||
],
|
|
||||||
], 422);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = $user->createToken('auth-token')->plainTextToken;
|
$token = $user->createToken('auth-token')->plainTextToken;
|
||||||
|
|
||||||
return response()->json([
|
return $this->success('ورود با موفقیت انجام شد.', [
|
||||||
'message' => 'ورود با موفقیت انجام شد.',
|
'user' => new UserResource($user),
|
||||||
'data' => [
|
'token' => $token,
|
||||||
'user' => new UserResource($user),
|
|
||||||
'token' => $token,
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +141,7 @@ class AuthController extends Controller
|
|||||||
$counter = 1;
|
$counter = 1;
|
||||||
|
|
||||||
while (User::query()->where('username', $username)->exists()) {
|
while (User::query()->where('username', $username)->exists()) {
|
||||||
$username = $base.$counter;
|
$username = $base . $counter;
|
||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
52
app/Http/Controllers/Api/CategoryController.php
Normal file
52
app/Http/Controllers/Api/CategoryController.php
Normal 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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
89
app/Http/Controllers/Api/NotificationController.php
Normal file
89
app/Http/Controllers/Api/NotificationController.php
Normal 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('همه نوتیفیکیشنها خوانده شد.');
|
||||||
|
}
|
||||||
|
}
|
||||||
98
app/Http/Controllers/Api/ProfileController.php
Normal file
98
app/Http/Controllers/Api/ProfileController.php
Normal 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()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
104
app/Http/Controllers/Api/TemplateController.php
Normal file
104
app/Http/Controllers/Api/TemplateController.php
Normal 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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
155
app/Http/Controllers/Api/TemplateGenerationController.php
Normal file
155
app/Http/Controllers/Api/TemplateGenerationController.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
100
app/Http/Controllers/Api/WalletController.php
Normal file
100
app/Http/Controllers/Api/WalletController.php
Normal 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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Http/Requests/Api/GenerateTemplateRequest.php
Normal file
50
app/Http/Requests/Api/GenerateTemplateRequest.php
Normal 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 از نوع چارت است و فعلاً پشتیبانی نمیشود.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal file
50
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal 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' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Http/Resources/CategoryResource.php
Normal file
34
app/Http/Resources/CategoryResource.php
Normal 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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Http/Resources/NotificationResource.php
Normal file
42
app/Http/Resources/NotificationResource.php
Normal 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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Resources/TemplateGenerationResource.php
Normal file
38
app/Http/Resources/TemplateGenerationResource.php
Normal 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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Resources/TemplateKeyResource.php
Normal file
38
app/Http/Resources/TemplateKeyResource.php
Normal 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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
44
app/Http/Resources/TemplateResource.php
Normal file
44
app/Http/Resources/TemplateResource.php
Normal 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')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Http/Resources/WalletResource.php
Normal file
34
app/Http/Resources/WalletResource.php
Normal 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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Http/Resources/WalletTransactionResource.php
Normal file
42
app/Http/Resources/WalletTransactionResource.php
Normal 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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Jobs/GenerateTemplateJob.php
Normal file
39
app/Jobs/GenerateTemplateJob.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use App\Services\TemplateFillService;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class GenerateTemplateJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public function __construct(private readonly TemplateGeneration $generation) {}
|
||||||
|
|
||||||
|
public function handle(TemplateFillService $templateFillService): void
|
||||||
|
{
|
||||||
|
$this->generation->update(['status' => TemplateGenerationStatus::Processing]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$outputPath = $templateFillService->fill($this->generation);
|
||||||
|
|
||||||
|
$this->generation->update([
|
||||||
|
'status' => TemplateGenerationStatus::Completed,
|
||||||
|
'output_path' => $outputPath,
|
||||||
|
]);
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
$this->generation->update([
|
||||||
|
'status' => TemplateGenerationStatus::Failed,
|
||||||
|
'error_message' => $exception->getMessage(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/Models/Category.php
Normal file
29
app/Models/Category.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
#[Fillable(['name', 'slug', 'description', 'is_active'])]
|
||||||
|
class Category extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return HasMany<Template, $this>
|
||||||
|
*/
|
||||||
|
public function templates(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Template::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'is_active' => 'boolean',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Models/Notification.php
Normal file
37
app/Models/Notification.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\NotificationType;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
#[Fillable(['user_id', 'type', 'title', 'body', 'data', 'read_at'])]
|
||||||
|
class Notification extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<User, $this>
|
||||||
|
*/
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isRead(): bool
|
||||||
|
{
|
||||||
|
return $this->read_at !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => NotificationType::class,
|
||||||
|
'data' => 'array',
|
||||||
|
'read_at' => 'datetime',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
63
app/Models/Template.php
Normal file
63
app/Models/Template.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
|
||||||
|
#[Fillable([
|
||||||
|
'category_id',
|
||||||
|
'title',
|
||||||
|
'slug',
|
||||||
|
'description',
|
||||||
|
'file_path',
|
||||||
|
'thumbnail_path',
|
||||||
|
'is_active',
|
||||||
|
'created_by',
|
||||||
|
])]
|
||||||
|
class Template extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<Category, $this>
|
||||||
|
*/
|
||||||
|
public function category(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Category::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<User, $this>
|
||||||
|
*/
|
||||||
|
public function creator(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'created_by');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return HasMany<TemplateKey, $this>
|
||||||
|
*/
|
||||||
|
public function keys(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(TemplateKey::class)->orderBy('sort_order');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return HasMany<TemplateGeneration, $this>
|
||||||
|
*/
|
||||||
|
public function generations(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(TemplateGeneration::class)->latest();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'is_active' => 'boolean',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
47
app/Models/TemplateGeneration.php
Normal file
47
app/Models/TemplateGeneration.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
#[Fillable([
|
||||||
|
'template_id',
|
||||||
|
'uuid',
|
||||||
|
'status',
|
||||||
|
'values',
|
||||||
|
'output_path',
|
||||||
|
'error_message',
|
||||||
|
'requested_by',
|
||||||
|
])]
|
||||||
|
class TemplateGeneration extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<Template, $this>
|
||||||
|
*/
|
||||||
|
public function template(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Template::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<User, $this>
|
||||||
|
*/
|
||||||
|
public function requester(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'requested_by');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'status' => TemplateGenerationStatus::class,
|
||||||
|
'values' => 'array',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
41
app/Models/TemplateKey.php
Normal file
41
app/Models/TemplateKey.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\TemplateKeyType;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
#[Fillable([
|
||||||
|
'template_id',
|
||||||
|
'key',
|
||||||
|
'label',
|
||||||
|
'type',
|
||||||
|
'shape_name',
|
||||||
|
'is_required',
|
||||||
|
'sort_order',
|
||||||
|
'description',
|
||||||
|
])]
|
||||||
|
class TemplateKey extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<Template, $this>
|
||||||
|
*/
|
||||||
|
public function template(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Template::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => TemplateKeyType::class,
|
||||||
|
'is_required' => 'boolean',
|
||||||
|
'sort_order' => 'integer',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|||||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
@@ -47,6 +48,14 @@ class User extends Authenticatable implements FilamentUser
|
|||||||
return $this->hasManyThrough(WalletTransaction::class, Wallet::class);
|
return $this->hasManyThrough(WalletTransaction::class, Wallet::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return HasMany<Notification, $this>
|
||||||
|
*/
|
||||||
|
public function notifications(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Notification::class)->latest();
|
||||||
|
}
|
||||||
|
|
||||||
public function hasRole(string|array $roles): bool
|
public function hasRole(string|array $roles): bool
|
||||||
{
|
{
|
||||||
$roles = (array) $roles;
|
$roles = (array) $roles;
|
||||||
|
|||||||
39
app/Policies/CategoryPolicy.php
Normal file
39
app/Policies/CategoryPolicy.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\Category;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class CategoryPolicy
|
||||||
|
{
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(User $user, Category $category): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(User $user, Category $category): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(User $user, Category $category): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function canManage(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->hasRole('admin') || $user->hasPermission('templates.manage');
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Policies/NotificationPolicy.php
Normal file
34
app/Policies/NotificationPolicy.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\Notification;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class NotificationPolicy
|
||||||
|
{
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(User $user, Notification $notification): bool
|
||||||
|
{
|
||||||
|
return $user->id === $notification->user_id || $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(User $user, Notification $notification): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(User $user, Notification $notification): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function canManage(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->hasRole('admin') || $user->hasPermission('notifications.manage');
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Policies/TemplatePolicy.php
Normal file
39
app/Policies/TemplatePolicy.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\Template;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class TemplatePolicy
|
||||||
|
{
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(User $user, Template $template): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(User $user, Template $template): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(User $user, Template $template): bool
|
||||||
|
{
|
||||||
|
return $this->canManage($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function canManage(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->hasRole('admin') || $user->hasPermission('templates.manage');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Models\Notification;
|
||||||
use App\Models\Permission;
|
use App\Models\Permission;
|
||||||
use App\Models\Role;
|
use App\Models\Role;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\Wallet;
|
use App\Models\Wallet;
|
||||||
use App\Models\WalletTransaction;
|
use App\Models\WalletTransaction;
|
||||||
use App\Observers\UserObserver;
|
use App\Observers\UserObserver;
|
||||||
|
use App\Policies\NotificationPolicy;
|
||||||
use App\Policies\PermissionPolicy;
|
use App\Policies\PermissionPolicy;
|
||||||
use App\Policies\RolePolicy;
|
use App\Policies\RolePolicy;
|
||||||
use App\Policies\UserPolicy;
|
use App\Policies\UserPolicy;
|
||||||
@@ -43,5 +45,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
Gate::policy(Permission::class, PermissionPolicy::class);
|
Gate::policy(Permission::class, PermissionPolicy::class);
|
||||||
Gate::policy(Wallet::class, WalletPolicy::class);
|
Gate::policy(Wallet::class, WalletPolicy::class);
|
||||||
Gate::policy(WalletTransaction::class, WalletTransactionPolicy::class);
|
Gate::policy(WalletTransaction::class, WalletTransactionPolicy::class);
|
||||||
|
Gate::policy(Notification::class, NotificationPolicy::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
app/Services/NotificationService.php
Normal file
28
app/Services/NotificationService.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Enums\NotificationType;
|
||||||
|
use App\Models\Notification;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class NotificationService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed>|null $data
|
||||||
|
*/
|
||||||
|
public function send(User $user, NotificationType $type, string $title, string $body, ?array $data = null): Notification
|
||||||
|
{
|
||||||
|
return $user->notifications()->create([
|
||||||
|
'type' => $type,
|
||||||
|
'title' => $title,
|
||||||
|
'body' => $body,
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function markAllAsRead(User $user): void
|
||||||
|
{
|
||||||
|
$user->notifications()->whereNull('read_at')->update(['read_at' => now()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
104
app/Services/TemplateFillService.php
Normal file
104
app/Services/TemplateFillService.php
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Enums\TemplateKeyType;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use PhpOffice\PhpPresentation\IOFactory;
|
||||||
|
use PhpOffice\PhpPresentation\PhpPresentation;
|
||||||
|
use PhpOffice\PhpPresentation\Shape\Drawing\File as FileDrawing;
|
||||||
|
use PhpOffice\PhpPresentation\Shape\Drawing\Gd as GdDrawing;
|
||||||
|
use PhpOffice\PhpPresentation\Shape\RichText;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
|
class TemplateFillService
|
||||||
|
{
|
||||||
|
public function fill(TemplateGeneration $generation): string
|
||||||
|
{
|
||||||
|
$template = $generation->template;
|
||||||
|
|
||||||
|
$sourcePath = Storage::disk('local')->path($template->file_path);
|
||||||
|
$presentation = IOFactory::load($sourcePath);
|
||||||
|
|
||||||
|
$values = $generation->values ?? [];
|
||||||
|
|
||||||
|
foreach ($template->keys as $key) {
|
||||||
|
if (! array_key_exists($key->key, $values)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
match ($key->type) {
|
||||||
|
TemplateKeyType::Text => $this->fillText($presentation, $key->key, (string) $values[$key->key]),
|
||||||
|
TemplateKeyType::Image => $this->fillImage($presentation, $key->shape_name, Storage::disk('local')->path($values[$key->key])),
|
||||||
|
TemplateKeyType::Chart => throw new RuntimeException('پرکردن کلید از نوع چارت هنوز پشتیبانی نمیشود.'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
$outputRelativePath = 'templates/generations/'.$generation->uuid.'.pptx';
|
||||||
|
$outputAbsolutePath = Storage::disk('local')->path($outputRelativePath);
|
||||||
|
|
||||||
|
Storage::disk('local')->makeDirectory('templates/generations');
|
||||||
|
|
||||||
|
$writer = IOFactory::createWriter($presentation, 'PowerPoint2007');
|
||||||
|
$writer->save($outputAbsolutePath);
|
||||||
|
|
||||||
|
return $outputRelativePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fillText(PhpPresentation $presentation, string $key, string $value): void
|
||||||
|
{
|
||||||
|
$placeholder = '{{'.$key.'}}';
|
||||||
|
|
||||||
|
foreach ($presentation->getAllSlides() as $slide) {
|
||||||
|
foreach ($slide->getShapeCollection() as $shape) {
|
||||||
|
if (! $shape instanceof RichText) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($shape->getParagraphs() as $paragraph) {
|
||||||
|
foreach ($paragraph->getRichTextElements() as $element) {
|
||||||
|
if (str_contains($element->getText(), $placeholder)) {
|
||||||
|
$element->setText(str_replace($placeholder, $value, $element->getText()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fillImage(PhpPresentation $presentation, ?string $shapeName, string $imagePath): void
|
||||||
|
{
|
||||||
|
if ($shapeName === null || $shapeName === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($presentation->getAllSlides() as $slide) {
|
||||||
|
foreach ($slide->getShapeCollection() as $shape) {
|
||||||
|
if ($shape->getName() !== $shapeName) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($shape instanceof GdDrawing) {
|
||||||
|
$this->replaceGdImage($shape, $imagePath);
|
||||||
|
} elseif ($shape instanceof FileDrawing) {
|
||||||
|
$shape->setPath($imagePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function replaceGdImage(GdDrawing $shape, string $imagePath): void
|
||||||
|
{
|
||||||
|
$info = getimagesize($imagePath);
|
||||||
|
$image = imagecreatefromstring(file_get_contents($imagePath));
|
||||||
|
|
||||||
|
if ($info === false || $image === false) {
|
||||||
|
throw new RuntimeException('فایل تصویر ارسالی معتبر نیست.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$shape->setImageResource($image);
|
||||||
|
$shape->setMimeType($info['mime']);
|
||||||
|
$shape->setRenderingFunction(str_replace('/', '', $info['mime']));
|
||||||
|
}
|
||||||
|
}
|
||||||
24
app/Traits/ApiResponse.php
Normal file
24
app/Traits/ApiResponse.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
trait ApiResponse
|
||||||
|
{
|
||||||
|
protected function success(string $message, array $data = [], int $status = 200): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'message' => $message,
|
||||||
|
'data' => $data,
|
||||||
|
], $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function error(string $message, array $errors = [], int $status = 422): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'message' => $message,
|
||||||
|
'errors' => $errors,
|
||||||
|
], $status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,8 @@
|
|||||||
"filament/filament": "^4.0",
|
"filament/filament": "^4.0",
|
||||||
"laravel/framework": "^13.8",
|
"laravel/framework": "^13.8",
|
||||||
"laravel/sanctum": "^4.3",
|
"laravel/sanctum": "^4.3",
|
||||||
"laravel/tinker": "^3.0"
|
"laravel/tinker": "^3.0",
|
||||||
|
"phpoffice/phppresentation": "^1.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.23",
|
"fakerphp/faker": "^1.23",
|
||||||
|
|||||||
618
composer.lock
generated
618
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "c479d2908801be9c7f146d6a1c4662b8",
|
"content-hash": "228c4071ac2afaa94e16b892dc1fbdc4",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "blade-ui-kit/blade-heroicons",
|
"name": "blade-ui-kit/blade-heroicons",
|
||||||
@@ -447,6 +447,85 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-03-20T21:10:52+00:00"
|
"time": "2026-03-20T21:10:52+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "composer/pcre",
|
||||||
|
"version": "3.3.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/composer/pcre.git",
|
||||||
|
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
||||||
|
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.4 || ^8.0"
|
||||||
|
},
|
||||||
|
"conflict": {
|
||||||
|
"phpstan/phpstan": "<1.11.10"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpstan/phpstan": "^1.12 || ^2",
|
||||||
|
"phpstan/phpstan-strict-rules": "^1 || ^2",
|
||||||
|
"phpunit/phpunit": "^8 || ^9"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"phpstan": {
|
||||||
|
"includes": [
|
||||||
|
"extension.neon"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-main": "3.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Composer\\Pcre\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jordi Boggiano",
|
||||||
|
"email": "j.boggiano@seld.be",
|
||||||
|
"homepage": "http://seld.be"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
|
||||||
|
"keywords": [
|
||||||
|
"PCRE",
|
||||||
|
"preg",
|
||||||
|
"regex",
|
||||||
|
"regular expression"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/composer/pcre/issues",
|
||||||
|
"source": "https://github.com/composer/pcre/tree/3.3.2"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://packagist.com",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/composer",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-11-12T16:29:46+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "danharrin/date-format-converter",
|
"name": "danharrin/date-format-converter",
|
||||||
"version": "v0.3.1",
|
"version": "v0.3.1",
|
||||||
@@ -3386,6 +3465,191 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-04-30T23:56:43+00:00"
|
"time": "2026-04-30T23:56:43+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "maennchen/zipstream-php",
|
||||||
|
"version": "3.2.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/maennchen/ZipStream-PHP.git",
|
||||||
|
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
||||||
|
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-mbstring": "*",
|
||||||
|
"ext-zlib": "*",
|
||||||
|
"php-64bit": "^8.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"brianium/paratest": "^7.7",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.86",
|
||||||
|
"guzzlehttp/guzzle": "^7.5",
|
||||||
|
"mikey179/vfsstream": "^1.6",
|
||||||
|
"php-coveralls/php-coveralls": "^2.5",
|
||||||
|
"phpunit/phpunit": "^12.0",
|
||||||
|
"vimeo/psalm": "^6.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"guzzlehttp/psr7": "^2.4",
|
||||||
|
"psr/http-message": "^2.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"ZipStream\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Paul Duncan",
|
||||||
|
"email": "pabs@pablotron.org"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jonatan Männchen",
|
||||||
|
"email": "jonatan@maennchen.ch"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jesse Donat",
|
||||||
|
"email": "donatj@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "András Kolesár",
|
||||||
|
"email": "kolesar@kolesar.hu"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
|
||||||
|
"keywords": [
|
||||||
|
"stream",
|
||||||
|
"zip"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/maennchen/ZipStream-PHP/issues",
|
||||||
|
"source": "https://github.com/maennchen/ZipStream-PHP/tree/3.2.2"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/maennchen",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-04-11T18:38:28+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "markbaker/complex",
|
||||||
|
"version": "3.0.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/MarkBaker/PHPComplex.git",
|
||||||
|
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
|
||||||
|
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.2 || ^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.3",
|
||||||
|
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Complex\\": "classes/src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Mark Baker",
|
||||||
|
"email": "mark@lange.demon.co.uk"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP Class for working with complex numbers",
|
||||||
|
"homepage": "https://github.com/MarkBaker/PHPComplex",
|
||||||
|
"keywords": [
|
||||||
|
"complex",
|
||||||
|
"mathematics"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/MarkBaker/PHPComplex/issues",
|
||||||
|
"source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.2"
|
||||||
|
},
|
||||||
|
"time": "2022-12-06T16:21:08+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "markbaker/matrix",
|
||||||
|
"version": "3.0.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/MarkBaker/PHPMatrix.git",
|
||||||
|
"reference": "728434227fe21be27ff6d86621a1b13107a2562c"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/728434227fe21be27ff6d86621a1b13107a2562c",
|
||||||
|
"reference": "728434227fe21be27ff6d86621a1b13107a2562c",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.1 || ^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.3",
|
||||||
|
"phpdocumentor/phpdocumentor": "2.*",
|
||||||
|
"phploc/phploc": "^4.0",
|
||||||
|
"phpmd/phpmd": "2.*",
|
||||||
|
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
||||||
|
"sebastian/phpcpd": "^4.0",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Matrix\\": "classes/src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Mark Baker",
|
||||||
|
"email": "mark@demon-angel.eu"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP Class for working with matrices",
|
||||||
|
"homepage": "https://github.com/MarkBaker/PHPMatrix",
|
||||||
|
"keywords": [
|
||||||
|
"mathematics",
|
||||||
|
"matrix",
|
||||||
|
"vector"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/MarkBaker/PHPMatrix/issues",
|
||||||
|
"source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.1"
|
||||||
|
},
|
||||||
|
"time": "2022-12-02T22:17:43+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "monolog/monolog",
|
"name": "monolog/monolog",
|
||||||
"version": "3.10.0",
|
"version": "3.10.0",
|
||||||
@@ -4133,6 +4397,279 @@
|
|||||||
},
|
},
|
||||||
"time": "2025-09-24T15:06:41+00:00"
|
"time": "2025-09-24T15:06:41+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "pclzip/pclzip",
|
||||||
|
"version": "2.8.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/ivanlanin/pclzip.git",
|
||||||
|
"reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/ivanlanin/pclzip/zipball/19dd1de9d3f5fc4d7d70175b4c344dee329f45fd",
|
||||||
|
"reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"classmap": [
|
||||||
|
"pclzip.lib.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"LGPL-2.1"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Vincent Blavet"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A PHP library that offers compression and extraction functions for Zip formatted archives",
|
||||||
|
"homepage": "http://www.phpconcept.net/pclzip",
|
||||||
|
"keywords": [
|
||||||
|
"php",
|
||||||
|
"zip"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/ivanlanin/pclzip/issues",
|
||||||
|
"source": "https://github.com/ivanlanin/pclzip/tree/master"
|
||||||
|
},
|
||||||
|
"time": "2014-06-05T11:42:24+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "phpoffice/common",
|
||||||
|
"version": "1.0.5",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHPOffice/Common.git",
|
||||||
|
"reference": "5a2eeb82d4dfce4ce2163819063ba6f5a80c3e91"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHPOffice/Common/zipball/5a2eeb82d4dfce4ce2163819063ba6f5a80c3e91",
|
||||||
|
"reference": "5a2eeb82d4dfce4ce2163819063ba6f5a80c3e91",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"pclzip/pclzip": "^2.8",
|
||||||
|
"php": ">=7.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpmd/phpmd": "2.*",
|
||||||
|
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
|
||||||
|
"phpunit/phpunit": ">=7"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"PhpOffice\\Common\\": "src/Common/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"LGPL-3.0-only"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Mark Baker"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Franck Lefevre",
|
||||||
|
"homepage": "http://rootslabs.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHPOffice Common",
|
||||||
|
"homepage": "http://phpoffice.github.io",
|
||||||
|
"keywords": [
|
||||||
|
"common",
|
||||||
|
"component",
|
||||||
|
"office",
|
||||||
|
"php"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHPOffice/Common/issues",
|
||||||
|
"source": "https://github.com/PHPOffice/Common/tree/1.0.5"
|
||||||
|
},
|
||||||
|
"time": "2025-02-28T12:39:45+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "phpoffice/phppresentation",
|
||||||
|
"version": "1.2.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHPOffice/PHPPresentation.git",
|
||||||
|
"reference": "b9cdcd413e2d463ba3198f912f32716adc88f340"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHPOffice/PHPPresentation/zipball/b9cdcd413e2d463ba3198f912f32716adc88f340",
|
||||||
|
"reference": "b9cdcd413e2d463ba3198f912f32716adc88f340",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-xml": "*",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"php": "^7.1|^8.0",
|
||||||
|
"phpoffice/common": "^1",
|
||||||
|
"phpoffice/phpspreadsheet": "^1.9 || ^2.0 || ^3.0 || ^4.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dompdf/dompdf": "^3.1",
|
||||||
|
"phpmd/phpmd": "2.*",
|
||||||
|
"phpstan/phpstan": "^0.12.88 || ^1.0.0",
|
||||||
|
"phpunit/phpunit": ">=7.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-gd": "Required to add images"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"PhpOffice\\PhpPresentation\\": "src/PhpPresentation/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"LGPL-3.0-only"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Mark Baker"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Franck Lefevre",
|
||||||
|
"homepage": "http://rootslabs.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Ivan Lanin",
|
||||||
|
"homepage": "http://ivan.lanin.org"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHPPresentation - Read, Create and Write Presentations documents in PHP",
|
||||||
|
"homepage": "http://phpoffice.github.io",
|
||||||
|
"keywords": [
|
||||||
|
"LibreOffice",
|
||||||
|
"PowerPoint",
|
||||||
|
"odp",
|
||||||
|
"php",
|
||||||
|
"ppt",
|
||||||
|
"pptx",
|
||||||
|
"presentations"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHPOffice/PHPPresentation/issues",
|
||||||
|
"source": "https://github.com/PHPOffice/PHPPresentation/tree/1.2.0"
|
||||||
|
},
|
||||||
|
"time": "2025-06-06T10:27:25+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "phpoffice/phpspreadsheet",
|
||||||
|
"version": "4.5.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
|
||||||
|
"reference": "2ea9786632e6fac1aee601b6e426bcc723d8ce13"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/2ea9786632e6fac1aee601b6e426bcc723d8ce13",
|
||||||
|
"reference": "2ea9786632e6fac1aee601b6e426bcc723d8ce13",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"composer/pcre": "^1||^2||^3",
|
||||||
|
"ext-ctype": "*",
|
||||||
|
"ext-dom": "*",
|
||||||
|
"ext-fileinfo": "*",
|
||||||
|
"ext-gd": "*",
|
||||||
|
"ext-iconv": "*",
|
||||||
|
"ext-libxml": "*",
|
||||||
|
"ext-mbstring": "*",
|
||||||
|
"ext-simplexml": "*",
|
||||||
|
"ext-xml": "*",
|
||||||
|
"ext-xmlreader": "*",
|
||||||
|
"ext-xmlwriter": "*",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"ext-zlib": "*",
|
||||||
|
"maennchen/zipstream-php": "^2.1 || ^3.0",
|
||||||
|
"markbaker/complex": "^3.0",
|
||||||
|
"markbaker/matrix": "^3.0",
|
||||||
|
"php": "^8.1",
|
||||||
|
"psr/http-client": "^1.0",
|
||||||
|
"psr/http-factory": "^1.0",
|
||||||
|
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dealerdirect/phpcodesniffer-composer-installer": "dev-main",
|
||||||
|
"dompdf/dompdf": "^2.0 || ^3.0",
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.2",
|
||||||
|
"mitoteam/jpgraph": "^10.3",
|
||||||
|
"mpdf/mpdf": "^8.1.1",
|
||||||
|
"phpcompatibility/php-compatibility": "^9.3",
|
||||||
|
"phpstan/phpstan": "^1.1 || ^2.0",
|
||||||
|
"phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0",
|
||||||
|
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
|
||||||
|
"phpunit/phpunit": "^10.5",
|
||||||
|
"squizlabs/php_codesniffer": "^3.7",
|
||||||
|
"tecnickcom/tcpdf": "^6.5"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"dompdf/dompdf": "Option for rendering PDF with PDF Writer",
|
||||||
|
"ext-intl": "PHP Internationalization Functions",
|
||||||
|
"mitoteam/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers",
|
||||||
|
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
|
||||||
|
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Maarten Balliauw",
|
||||||
|
"homepage": "https://blog.maartenballiauw.be"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mark Baker",
|
||||||
|
"homepage": "https://markbakeruk.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Franck Lefevre",
|
||||||
|
"homepage": "https://rootslabs.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Erik Tilt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Adrien Crivelli"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
|
||||||
|
"homepage": "https://github.com/PHPOffice/PhpSpreadsheet",
|
||||||
|
"keywords": [
|
||||||
|
"OpenXML",
|
||||||
|
"excel",
|
||||||
|
"gnumeric",
|
||||||
|
"ods",
|
||||||
|
"php",
|
||||||
|
"spreadsheet",
|
||||||
|
"xls",
|
||||||
|
"xlsx"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
|
||||||
|
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/4.5.0"
|
||||||
|
},
|
||||||
|
"time": "2025-07-24T05:15:59+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpoption/phpoption",
|
"name": "phpoption/phpoption",
|
||||||
"version": "1.9.5",
|
"version": "1.9.5",
|
||||||
@@ -8687,85 +9224,6 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-03-29T15:46:14+00:00"
|
"time": "2026-03-29T15:46:14+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "composer/pcre",
|
|
||||||
"version": "3.3.2",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/composer/pcre.git",
|
|
||||||
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
|
||||||
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": "^7.4 || ^8.0"
|
|
||||||
},
|
|
||||||
"conflict": {
|
|
||||||
"phpstan/phpstan": "<1.11.10"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpstan/phpstan": "^1.12 || ^2",
|
|
||||||
"phpstan/phpstan-strict-rules": "^1 || ^2",
|
|
||||||
"phpunit/phpunit": "^8 || ^9"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"phpstan": {
|
|
||||||
"includes": [
|
|
||||||
"extension.neon"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-main": "3.x-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Composer\\Pcre\\": "src"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Jordi Boggiano",
|
|
||||||
"email": "j.boggiano@seld.be",
|
|
||||||
"homepage": "http://seld.be"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
|
|
||||||
"keywords": [
|
|
||||||
"PCRE",
|
|
||||||
"preg",
|
|
||||||
"regex",
|
|
||||||
"regular expression"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/composer/pcre/issues",
|
|
||||||
"source": "https://github.com/composer/pcre/tree/3.3.2"
|
|
||||||
},
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"url": "https://packagist.com",
|
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://github.com/composer",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
|
||||||
"type": "tidelift"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"time": "2024-11-12T16:29:46+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "composer/xdebug-handler",
|
"name": "composer/xdebug-handler",
|
||||||
"version": "3.0.5",
|
"version": "3.0.5",
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('categories', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('slug')->unique();
|
||||||
|
$table->text('description')->nullable();
|
||||||
|
$table->boolean('is_active')->default(true);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('categories');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('templates', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('category_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('title');
|
||||||
|
$table->string('slug')->unique();
|
||||||
|
$table->text('description')->nullable();
|
||||||
|
$table->string('file_path');
|
||||||
|
$table->string('thumbnail_path')->nullable();
|
||||||
|
$table->boolean('is_active')->default(true);
|
||||||
|
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('templates');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('template_generations', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('template_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->uuid('uuid')->unique();
|
||||||
|
$table->string('status')->default('pending');
|
||||||
|
$table->json('values')->nullable();
|
||||||
|
$table->string('output_path')->nullable();
|
||||||
|
$table->string('error_message')->nullable();
|
||||||
|
$table->foreignId('requested_by')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->index(['template_id', 'status']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('template_generations');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('template_keys', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('template_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('key');
|
||||||
|
$table->string('label');
|
||||||
|
$table->string('type');
|
||||||
|
$table->string('shape_name')->nullable();
|
||||||
|
$table->boolean('is_required')->default(true);
|
||||||
|
$table->unsignedInteger('sort_order')->default(0);
|
||||||
|
$table->string('description')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['template_id', 'key']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('template_keys');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('notifications', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('type');
|
||||||
|
$table->string('title');
|
||||||
|
$table->text('body');
|
||||||
|
$table->json('data')->nullable();
|
||||||
|
$table->timestamp('read_at')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->index(['user_id', 'created_at']);
|
||||||
|
$table->index(['user_id', 'read_at']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('notifications');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,9 +1,46 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\Api\AuthController;
|
use App\Http\Controllers\Api\AuthController;
|
||||||
|
use App\Http\Controllers\Api\CategoryController;
|
||||||
|
use App\Http\Controllers\Api\NotificationController;
|
||||||
|
use App\Http\Controllers\Api\ProfileController;
|
||||||
|
use App\Http\Controllers\Api\TemplateController;
|
||||||
|
use App\Http\Controllers\Api\TemplateGenerationController;
|
||||||
|
use App\Http\Controllers\Api\WalletController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::prefix('auth')->group(function (): void {
|
Route::prefix('auth')->group(function (): void {
|
||||||
Route::post('register', [AuthController::class, 'register']);
|
Route::post('register', [AuthController::class, 'register']);
|
||||||
Route::post('login', [AuthController::class, 'login']);
|
Route::post('login', [AuthController::class, 'login']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::get('categories', [CategoryController::class, 'index']);
|
||||||
|
|
||||||
|
Route::prefix('templates')->group(function (): void {
|
||||||
|
Route::get('/', [TemplateController::class, 'index']);
|
||||||
|
Route::get('{template:slug}', [TemplateController::class, 'show']);
|
||||||
|
|
||||||
|
Route::middleware('auth:sanctum')->group(function (): void {
|
||||||
|
Route::post('{template:slug}/generate', [TemplateGenerationController::class, 'store']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::middleware('auth:sanctum')->group(function (): void {
|
||||||
|
Route::get('profile', [ProfileController::class, 'show']);
|
||||||
|
Route::put('profile', [ProfileController::class, 'update']);
|
||||||
|
|
||||||
|
Route::prefix('wallet')->group(function (): void {
|
||||||
|
Route::get('/', [WalletController::class, 'show']);
|
||||||
|
Route::get('transactions', [WalletController::class, 'transactions']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::prefix('notifications')->group(function (): void {
|
||||||
|
Route::get('/', [NotificationController::class, 'index']);
|
||||||
|
Route::post('read-all', [NotificationController::class, 'markAllAsRead']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::prefix('generations')->group(function (): void {
|
||||||
|
Route::get('{generation:uuid}', [TemplateGenerationController::class, 'show']);
|
||||||
|
Route::get('{generation:uuid}/download', [TemplateGenerationController::class, 'download'])->name('api.generations.download');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -157,6 +157,231 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"/profile": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Show profile",
|
||||||
|
"description": "Get the authenticated user profile",
|
||||||
|
"operationId": "c6a79007a56511faa6f48397a2d15867",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Profile fetched successfully",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "اطلاعات پروفایل با موفقیت دریافت شد."
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"properties": {
|
||||||
|
"user": {
|
||||||
|
"$ref": "#/components/schemas/User"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthenticated"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"sanctum": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"put": {
|
||||||
|
"tags": [
|
||||||
|
"Profile"
|
||||||
|
],
|
||||||
|
"summary": "Update profile",
|
||||||
|
"description": "Update the authenticated user profile",
|
||||||
|
"operationId": "74599296b1816be41ad4228975229966",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "علی رضایی"
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "ali"
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "email",
|
||||||
|
"example": "ali@example.com"
|
||||||
|
},
|
||||||
|
"mobile": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "09123456789"
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "password",
|
||||||
|
"example": "password123"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Profile updated successfully",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "پروفایل با موفقیت بهروزرسانی شد."
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"properties": {
|
||||||
|
"user": {
|
||||||
|
"$ref": "#/components/schemas/User"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthenticated"
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Validation error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"sanctum": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/wallet": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Wallet"
|
||||||
|
],
|
||||||
|
"summary": "Show wallet",
|
||||||
|
"description": "Get the authenticated user wallet",
|
||||||
|
"operationId": "4f659600ab1fd5e3ab27775fea03ec91",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Wallet fetched successfully",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "اطلاعات کیف پول با موفقیت دریافت شد."
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"properties": {
|
||||||
|
"wallet": {
|
||||||
|
"$ref": "#/components/schemas/Wallet"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthenticated"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"sanctum": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/wallet/transactions": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Wallet"
|
||||||
|
],
|
||||||
|
"summary": "List wallet transactions",
|
||||||
|
"description": "Get the authenticated user wallet transactions",
|
||||||
|
"operationId": "3ea6e910cbeabfdd2ca4db13b8d358b2",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "per_page",
|
||||||
|
"in": "query",
|
||||||
|
"description": "Items per page",
|
||||||
|
"schema": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Wallet transactions fetched successfully",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"properties": {
|
||||||
|
"message": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "تراکنشهای کیف پول با موفقیت دریافت شد."
|
||||||
|
},
|
||||||
|
"data": {
|
||||||
|
"properties": {
|
||||||
|
"transactions": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/components/schemas/WalletTransaction"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthenticated"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"sanctum": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
@@ -190,6 +415,65 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "object"
|
"type": "object"
|
||||||
|
},
|
||||||
|
"Wallet": {
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 1
|
||||||
|
},
|
||||||
|
"balance": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 500000
|
||||||
|
},
|
||||||
|
"is_active": {
|
||||||
|
"type": "boolean",
|
||||||
|
"example": true
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"WalletTransaction": {
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 1
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "credit"
|
||||||
|
},
|
||||||
|
"type_label": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "واریز"
|
||||||
|
},
|
||||||
|
"amount": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 100000
|
||||||
|
},
|
||||||
|
"balance_before": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 400000
|
||||||
|
},
|
||||||
|
"balance_after": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 500000
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "شارژ کیف پول",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"type": "object"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -197,6 +481,14 @@
|
|||||||
{
|
{
|
||||||
"name": "Auth",
|
"name": "Auth",
|
||||||
"description": "Authentication endpoints"
|
"description": "Authentication endpoints"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Profile",
|
||||||
|
"description": "Profile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Wallet",
|
||||||
|
"description": "Wallet"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user