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\Resources\UserResource;
|
||||
use App\Models\User;
|
||||
use App\Traits\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -14,6 +15,8 @@ use OpenApi\Attributes as OA;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
#[OA\Post(
|
||||
path: '/auth/register',
|
||||
description: 'Register a new user account',
|
||||
@@ -64,12 +67,9 @@ class AuthController extends Controller
|
||||
|
||||
$token = $user->createToken('auth-token')->plainTextToken;
|
||||
|
||||
return response()->json([
|
||||
'message' => 'ثبتنام با موفقیت انجام شد.',
|
||||
'data' => [
|
||||
'user' => new UserResource($user),
|
||||
'token' => $token,
|
||||
],
|
||||
return $this->success('ثبتنام با موفقیت انجام شد.', [
|
||||
'user' => new UserResource($user),
|
||||
'token' => $token,
|
||||
], 201);
|
||||
}
|
||||
|
||||
@@ -121,22 +121,16 @@ class AuthController extends Controller
|
||||
->first();
|
||||
|
||||
if (! $user || ! Hash::check($request->validated('password'), $user->password)) {
|
||||
return response()->json([
|
||||
'message' => 'اطلاعات ورود نادرست است.',
|
||||
'errors' => [
|
||||
'login' => ['ایمیل یا نام کاربری یا رمز عبور اشتباه است.'],
|
||||
],
|
||||
], 422);
|
||||
return $this->error('اطلاعات ورود نادرست است.', [
|
||||
'login' => ['ایمیل یا نام کاربری یا رمز عبور اشتباه است.'],
|
||||
]);
|
||||
}
|
||||
|
||||
$token = $user->createToken('auth-token')->plainTextToken;
|
||||
|
||||
return response()->json([
|
||||
'message' => 'ورود با موفقیت انجام شد.',
|
||||
'data' => [
|
||||
'user' => new UserResource($user),
|
||||
'token' => $token,
|
||||
],
|
||||
return $this->success('ورود با موفقیت انجام شد.', [
|
||||
'user' => new UserResource($user),
|
||||
'token' => $token,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -147,7 +141,7 @@ class AuthController extends Controller
|
||||
$counter = 1;
|
||||
|
||||
while (User::query()->where('username', $username)->exists()) {
|
||||
$username = $base.$counter;
|
||||
$username = $base . $counter;
|
||||
$counter++;
|
||||
}
|
||||
|
||||
|
||||
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\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
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 HasMany<Notification, $this>
|
||||
*/
|
||||
public function notifications(): HasMany
|
||||
{
|
||||
return $this->hasMany(Notification::class)->latest();
|
||||
}
|
||||
|
||||
public function hasRole(string|array $roles): bool
|
||||
{
|
||||
$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;
|
||||
|
||||
use App\Models\Notification;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\WalletTransaction;
|
||||
use App\Observers\UserObserver;
|
||||
use App\Policies\NotificationPolicy;
|
||||
use App\Policies\PermissionPolicy;
|
||||
use App\Policies\RolePolicy;
|
||||
use App\Policies\UserPolicy;
|
||||
@@ -43,5 +45,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
Gate::policy(Permission::class, PermissionPolicy::class);
|
||||
Gate::policy(Wallet::class, WalletPolicy::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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user