Compare commits
38 Commits
1c408130d0
...
feat/persi
| Author | SHA1 | Date | |
|---|---|---|---|
| f31f87aaf6 | |||
| ac11fbeaa6 | |||
| d2873ebcc1 | |||
| 84fe0e5d18 | |||
| 936f789ac8 | |||
| 46ae711a20 | |||
| fe2090a5af | |||
| e58dcd8581 | |||
| 0a7b7fea17 | |||
| 4a3c109bf3 | |||
| 774e1cd887 | |||
| e4fe203d44 | |||
| ae974c2afa | |||
| cf0e6f82fd | |||
| ca43502ffb | |||
| d1d42b38d1 | |||
| c2319a55cb | |||
| 12d149e5d9 | |||
| 3029f80d16 | |||
| 97fc7855ca | |||
| f8de292f12 | |||
| c57cf9bcb9 | |||
| 0607b45491 | |||
| 34ce6d810f | |||
| 8ddce5e792 | |||
| e2a6d50cb6 | |||
| 12b10db063 | |||
| e34744ad99 | |||
| 10a63b46bf | |||
| 6fff2d0285 | |||
| ca44e5b0db | |||
| dee1c3ab16 | |||
| 7cb4459fd4 | |||
| 0ddd54dc66 | |||
| 802326336a | |||
| 07d80b8740 | |||
| 0b99ab2119 | |||
| 6eae917540 |
28
.dockerignore
Normal file
28
.dockerignore
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
.git
|
||||||
|
.github
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
!.env.production.example
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
vendor
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
|
||||||
|
storage/logs/*
|
||||||
|
storage/framework/cache/data/*
|
||||||
|
storage/framework/sessions/*
|
||||||
|
storage/framework/views/*
|
||||||
|
bootstrap/cache/*.php
|
||||||
|
|
||||||
|
tests
|
||||||
|
coverage
|
||||||
|
.phpunit.cache
|
||||||
|
|
||||||
|
Dockerfile
|
||||||
|
docker-compose*.yml
|
||||||
|
README.md
|
||||||
@@ -3,6 +3,7 @@ APP_ENV=local
|
|||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
FRONTEND_URL=http://localhost:3000
|
||||||
|
|
||||||
APP_LOCALE=fa
|
APP_LOCALE=fa
|
||||||
APP_FALLBACK_LOCALE=en
|
APP_FALLBACK_LOCALE=en
|
||||||
|
|||||||
68
.env.production.example
Normal file
68
.env.production.example
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
APP_NAME=Hoshpoint
|
||||||
|
APP_ENV=production
|
||||||
|
APP_KEY=
|
||||||
|
APP_DEBUG=false
|
||||||
|
APP_URL=https://hoshpoint-api.treenix.ir
|
||||||
|
HTTP_PORT=8080
|
||||||
|
|
||||||
|
APP_LOCALE=fa
|
||||||
|
APP_FALLBACK_LOCALE=en
|
||||||
|
APP_FAKER_LOCALE=fa_IR
|
||||||
|
|
||||||
|
APP_MAINTENANCE_DRIVER=file
|
||||||
|
BCRYPT_ROUNDS=12
|
||||||
|
|
||||||
|
LOG_CHANNEL=stderr
|
||||||
|
LOG_STACK=stderr
|
||||||
|
LOG_DEPRECATIONS_CHANNEL=null
|
||||||
|
LOG_LEVEL=info
|
||||||
|
|
||||||
|
DB_CONNECTION=mariadb
|
||||||
|
DB_HOST=mariadb
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=hoshpoint_backend
|
||||||
|
DB_USERNAME=hoshpoint
|
||||||
|
DB_PASSWORD=change-me
|
||||||
|
|
||||||
|
MARIADB_DATABASE=hoshpoint_backend
|
||||||
|
MARIADB_USER=hoshpoint
|
||||||
|
MARIADB_PASSWORD=change-me
|
||||||
|
MARIADB_ROOT_PASSWORD=change-root-password
|
||||||
|
|
||||||
|
SESSION_DRIVER=database
|
||||||
|
SESSION_LIFETIME=120
|
||||||
|
SESSION_ENCRYPT=false
|
||||||
|
SESSION_PATH=/
|
||||||
|
SESSION_DOMAIN=null
|
||||||
|
SESSION_SECURE_COOKIE=true
|
||||||
|
SESSION_HTTP_ONLY=true
|
||||||
|
SESSION_SAME_SITE=lax
|
||||||
|
|
||||||
|
BROADCAST_CONNECTION=log
|
||||||
|
FILESYSTEM_DISK=local
|
||||||
|
QUEUE_CONNECTION=database
|
||||||
|
CACHE_STORE=database
|
||||||
|
|
||||||
|
MEMCACHED_HOST=memcached
|
||||||
|
|
||||||
|
REDIS_CLIENT=phpredis
|
||||||
|
REDIS_HOST=redis
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_MAILER=log
|
||||||
|
MAIL_SCHEME=null
|
||||||
|
MAIL_HOST=127.0.0.1
|
||||||
|
MAIL_PORT=2525
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_FROM_ADDRESS=hello@example.com
|
||||||
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
AWS_BUCKET=
|
||||||
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
78
Dockerfile
Normal file
78
Dockerfile
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
FROM php:8.4-fpm-bookworm AS app
|
||||||
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
|
ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||||
|
ENV COMPOSER_PROCESS_TIMEOUT=600
|
||||||
|
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends \
|
||||||
|
default-mysql-client \
|
||||||
|
default-libmysqlclient-dev \
|
||||||
|
git \
|
||||||
|
libfreetype6-dev \
|
||||||
|
libicu-dev \
|
||||||
|
libjpeg62-turbo-dev \
|
||||||
|
libpng-dev \
|
||||||
|
libzip-dev \
|
||||||
|
unzip \
|
||||||
|
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||||
|
&& docker-php-ext-install -j"$(nproc)" bcmath gd intl pcntl pdo_mysql zip \
|
||||||
|
&& apt-mark manual libzip4 libicu72 libjpeg62-turbo libpng16-16 libfreetype6 \
|
||||||
|
&& apt-get purge -y --auto-remove \
|
||||||
|
default-libmysqlclient-dev \
|
||||||
|
libfreetype6-dev \
|
||||||
|
libicu-dev \
|
||||||
|
libjpeg62-turbo-dev \
|
||||||
|
libpng-dev \
|
||||||
|
libzip-dev \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY docker/php/composer.phar /usr/local/bin/composer
|
||||||
|
RUN chmod +x /usr/local/bin/composer
|
||||||
|
|
||||||
|
COPY docker/php/php.ini /usr/local/etc/php/conf.d/99-production.ini
|
||||||
|
COPY docker/php/opcache.ini /usr/local/etc/php/conf.d/99-opcache.ini
|
||||||
|
|
||||||
|
COPY composer.json composer.lock ./
|
||||||
|
RUN composer install \
|
||||||
|
--no-dev \
|
||||||
|
--no-autoloader \
|
||||||
|
--no-scripts \
|
||||||
|
--prefer-dist \
|
||||||
|
--no-interaction \
|
||||||
|
&& composer check-platform-reqs --no-dev
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN composer dump-autoload --no-dev --optimize --no-scripts \
|
||||||
|
&& php artisan package:discover --ansi \
|
||||||
|
&& APP_KEY=base64:dGVtcG9yYXJ5a2V5Zm9yZG9ja2VyYnVpbGRvbmx5= php artisan l5-swagger:generate --no-interaction \
|
||||||
|
&& mkdir -p \
|
||||||
|
storage/app/public \
|
||||||
|
storage/framework/cache/data \
|
||||||
|
storage/framework/sessions \
|
||||||
|
storage/framework/views \
|
||||||
|
storage/logs \
|
||||||
|
storage/api-docs \
|
||||||
|
bootstrap/cache \
|
||||||
|
&& rm -rf public/storage \
|
||||||
|
&& ln -s ../storage/app/public public/storage \
|
||||||
|
&& chown -R www-data:www-data storage bootstrap/cache
|
||||||
|
|
||||||
|
COPY docker/entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint
|
||||||
|
|
||||||
|
EXPOSE 9000
|
||||||
|
|
||||||
|
ENTRYPOINT ["docker-entrypoint"]
|
||||||
|
CMD ["php-fpm"]
|
||||||
|
|
||||||
|
FROM nginx:1.27-alpine AS nginx
|
||||||
|
|
||||||
|
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
COPY --from=app /var/www/html/public /var/www/html/public
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# npm build (run locally before docker build):
|
||||||
|
# npm ci && npm run build
|
||||||
95
README.md
95
README.md
@@ -1 +1,96 @@
|
|||||||
### Hoshpoint
|
### Hoshpoint
|
||||||
|
|
||||||
|
## اجرای پروژه با Docker در Production
|
||||||
|
|
||||||
|
ابتدا Docker Desktop را اجرا کنید و فایل env پروداکشن را بسازید:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp .env.production.example .env.production
|
||||||
|
php artisan key:generate --show
|
||||||
|
```
|
||||||
|
|
||||||
|
خروجی را کپی کنید و داخل `.env.production` بگذارید (خط `APP_KEY` نباید خالی بماند):
|
||||||
|
|
||||||
|
```env
|
||||||
|
APP_KEY=base64:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
|
||||||
|
```
|
||||||
|
|
||||||
|
سپس `APP_URL`، `HTTP_PORT`، `DB_PASSWORD`، `MARIADB_PASSWORD` و `MARIADB_ROOT_PASSWORD` را هم تغییر دهید. مقدار پیشفرض `HTTP_PORT=8080` است.
|
||||||
|
|
||||||
|
برای build کردن imageها:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production build
|
||||||
|
```
|
||||||
|
|
||||||
|
اول دیتابیس را بالا بیاورید:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production up -d mariadb
|
||||||
|
```
|
||||||
|
|
||||||
|
بعد migrationها را اجرا کنید:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production run --rm app php artisan migrate --force --seed
|
||||||
|
```
|
||||||
|
|
||||||
|
حالا همه سرویسها را بالا بیاورید:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
سایت از طریق پورت تنظیمشده در `HTTP_PORT` در دسترس است. مقدار پیشفرض:
|
||||||
|
|
||||||
|
```text
|
||||||
|
http://localhost:8080
|
||||||
|
```
|
||||||
|
|
||||||
|
Swagger:
|
||||||
|
|
||||||
|
```text
|
||||||
|
http://localhost:8080/api/documentation
|
||||||
|
```
|
||||||
|
|
||||||
|
برای دیدن وضعیت سرویسها:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production ps
|
||||||
|
```
|
||||||
|
|
||||||
|
برای دیدن لاگها:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
برای اجرای دستورهای Artisan داخل کانتینر:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production exec app php artisan about
|
||||||
|
```
|
||||||
|
|
||||||
|
برای متوقف کردن سرویسها:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production down
|
||||||
|
```
|
||||||
|
|
||||||
|
برای حذف کامل دیتای دیتابیس و volumeها، فقط وقتی مطمئن هستید:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production down -v
|
||||||
|
```
|
||||||
|
|
||||||
|
## خطای `No application encryption key has been specified`
|
||||||
|
|
||||||
|
یعنی `APP_KEY` در `.env.production` خالی است.
|
||||||
|
|
||||||
|
1. مقدار `APP_KEY` را در `.env.production` تنظیم کنید.
|
||||||
|
2. سرویسها را restart کنید:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose --env-file .env.production restart app queue scheduler
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
21
app/Contracts/PaymentGateway.php
Normal file
21
app/Contracts/PaymentGateway.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Contracts;
|
||||||
|
|
||||||
|
use App\Models\WalletDeposit;
|
||||||
|
|
||||||
|
interface PaymentGateway
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Start a payment for the given deposit and return the URL the user should be
|
||||||
|
* redirected to in order to complete it.
|
||||||
|
*/
|
||||||
|
public function initiate(WalletDeposit $deposit): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify a gateway callback for the given deposit.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $callbackPayload
|
||||||
|
*/
|
||||||
|
public function verify(WalletDeposit $deposit, array $callbackPayload): bool;
|
||||||
|
}
|
||||||
25
app/Enums/AiProviderDriver.php
Normal file
25
app/Enums/AiProviderDriver.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum AiProviderDriver: string
|
||||||
|
{
|
||||||
|
case OpenAi = 'openai';
|
||||||
|
case GapGpt = 'gapgpt';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::OpenAi => 'OpenAI (GPT)',
|
||||||
|
self::GapGpt => 'GapGPT',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function defaultBaseUrl(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::OpenAi => 'https://api.openai.com/v1',
|
||||||
|
self::GapGpt => 'https://api.gapgpt.app/v1',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
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 => 'قالب',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
15
app/Enums/PaymentGatewayDriver.php
Normal file
15
app/Enums/PaymentGatewayDriver.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum PaymentGatewayDriver: string
|
||||||
|
{
|
||||||
|
case Fake = 'fake';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Fake => 'درگاه آزمایشی',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
17
app/Enums/TemplateGenerationSource.php
Normal file
17
app/Enums/TemplateGenerationSource.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum TemplateGenerationSource: string
|
||||||
|
{
|
||||||
|
case Template = 'template';
|
||||||
|
case AiText = 'ai_text';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Template => 'قالب آماده',
|
||||||
|
self::AiText => 'ساخت با هوش مصنوعی از متن',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
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 => 'چارت',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
21
app/Enums/WalletDepositStatus.php
Normal file
21
app/Enums/WalletDepositStatus.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum WalletDepositStatus: string
|
||||||
|
{
|
||||||
|
case Pending = 'pending';
|
||||||
|
case Paid = 'paid';
|
||||||
|
case Failed = 'failed';
|
||||||
|
case Expired = 'expired';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Pending => 'در انتظار پرداخت',
|
||||||
|
self::Paid => 'پرداختشده',
|
||||||
|
self::Failed => 'ناموفق',
|
||||||
|
self::Expired => 'منقضیشده',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
17
app/Enums/WalletTransactionType.php
Normal file
17
app/Enums/WalletTransactionType.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum WalletTransactionType: string
|
||||||
|
{
|
||||||
|
case Credit = 'credit';
|
||||||
|
case Debit = 'debit';
|
||||||
|
|
||||||
|
public function label(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Credit => 'واریز',
|
||||||
|
self::Debit => 'برداشت',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
54
app/Filament/Resources/AiProviders/AiProviderResource.php
Normal file
54
app/Filament/Resources/AiProviders/AiProviderResource.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\AiProviders;
|
||||||
|
|
||||||
|
use App\Filament\Resources\AiProviders\Pages\CreateAiProvider;
|
||||||
|
use App\Filament\Resources\AiProviders\Pages\EditAiProvider;
|
||||||
|
use App\Filament\Resources\AiProviders\Pages\ListAiProviders;
|
||||||
|
use App\Filament\Resources\AiProviders\Schemas\AiProviderForm;
|
||||||
|
use App\Filament\Resources\AiProviders\Tables\AiProvidersTable;
|
||||||
|
use App\Models\AiProvider;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class AiProviderResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = AiProvider::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedSparkles;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'هوش مصنوعی';
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'name';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'سرویس هوش مصنوعی';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'سرویسهای هوش مصنوعی';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'سرویسهای AI';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 30;
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return AiProviderForm::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return AiProvidersTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListAiProviders::route('/'),
|
||||||
|
'create' => CreateAiProvider::route('/create'),
|
||||||
|
'edit' => EditAiProvider::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\AiProviders\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\AiProviders\AiProviderResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateAiProvider extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = AiProviderResource::class;
|
||||||
|
}
|
||||||
19
app/Filament/Resources/AiProviders/Pages/EditAiProvider.php
Normal file
19
app/Filament/Resources/AiProviders/Pages/EditAiProvider.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\AiProviders\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\AiProviders\AiProviderResource;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditAiProvider extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = AiProviderResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/AiProviders/Pages/ListAiProviders.php
Normal file
19
app/Filament/Resources/AiProviders/Pages/ListAiProviders.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\AiProviders\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\AiProviders\AiProviderResource;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListAiProviders extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = AiProviderResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\AiProviders\Schemas;
|
||||||
|
|
||||||
|
use App\Enums\AiProviderDriver;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
|
use Filament\Schemas\Components\Utilities\Get;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class AiProviderForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
TextInput::make('name')
|
||||||
|
->label('نام')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
Select::make('driver')
|
||||||
|
->label('سرویسدهنده')
|
||||||
|
->options([
|
||||||
|
AiProviderDriver::OpenAi->value => AiProviderDriver::OpenAi->label(),
|
||||||
|
AiProviderDriver::GapGpt->value => AiProviderDriver::GapGpt->label(),
|
||||||
|
])
|
||||||
|
->default(AiProviderDriver::OpenAi->value)
|
||||||
|
->live()
|
||||||
|
->required(),
|
||||||
|
TextInput::make('model')
|
||||||
|
->label('مدل')
|
||||||
|
->helperText('مثال: gpt-4o-mini')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
TextInput::make('base_url')
|
||||||
|
->label('آدرس API (Base URL)')
|
||||||
|
->url()
|
||||||
|
->placeholder(fn (Get $get): string => AiProviderDriver::from($get('driver') ?? AiProviderDriver::OpenAi->value)->defaultBaseUrl())
|
||||||
|
->helperText('در صورت خالی بودن، آدرس پیشفرض همان سرویسدهنده استفاده میشود.')
|
||||||
|
->maxLength(255),
|
||||||
|
TextInput::make('api_key')
|
||||||
|
->label('API Key')
|
||||||
|
->password()
|
||||||
|
->revealable()
|
||||||
|
->autocomplete('new-password')
|
||||||
|
->required(fn (string $operation): bool => $operation === 'create')
|
||||||
|
->saved(fn (?string $state): bool => filled($state))
|
||||||
|
->maxLength(1000),
|
||||||
|
Toggle::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->default(true),
|
||||||
|
Toggle::make('is_default')
|
||||||
|
->label('پیشفرض')
|
||||||
|
->helperText('هنگام تولید محتوا در صورت وجود چند سرویس فعال، این سرویس اولویت دارد.'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\AiProviders\Tables;
|
||||||
|
|
||||||
|
use App\Enums\AiProviderDriver;
|
||||||
|
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 AiProvidersTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('name')
|
||||||
|
->label('نام')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('driver')
|
||||||
|
->label('سرویسدهنده')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (AiProviderDriver $state): string => $state->label()),
|
||||||
|
TextColumn::make('model')
|
||||||
|
->label('مدل')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('base_url')
|
||||||
|
->label('آدرس API')
|
||||||
|
->formatStateUsing(fn (?string $state, $record): string => $state ?: $record->driver->defaultBaseUrl())
|
||||||
|
->toggleable(),
|
||||||
|
IconColumn::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->boolean(),
|
||||||
|
IconColumn::make('is_default')
|
||||||
|
->label('پیشفرض')
|
||||||
|
->boolean(),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ ایجاد')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
TernaryFilter::make('is_active')
|
||||||
|
->label('وضعیت')
|
||||||
|
->placeholder('همه')
|
||||||
|
->trueLabel('فعال')
|
||||||
|
->falseLabel('غیرفعال'),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
EditAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
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('تاریخ ایجاد')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->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('تاریخ ایجاد')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->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(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ class PermissionsTable
|
|||||||
->searchable(),
|
->searchable(),
|
||||||
TextColumn::make('created_at')
|
TextColumn::make('created_at')
|
||||||
->label('تاریخ ایجاد')
|
->label('تاریخ ایجاد')
|
||||||
->dateTime()
|
->jalaliDateTime()
|
||||||
->sortable()
|
->sortable()
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class RolesTable
|
|||||||
->searchable(),
|
->searchable(),
|
||||||
TextColumn::make('created_at')
|
TextColumn::make('created_at')
|
||||||
->label('تاریخ ایجاد')
|
->label('تاریخ ایجاد')
|
||||||
->dateTime()
|
->jalaliDateTime()
|
||||||
->sortable()
|
->sortable()
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations\Actions;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
|
||||||
|
class DownloadGenerationAction
|
||||||
|
{
|
||||||
|
public static function make(): Action
|
||||||
|
{
|
||||||
|
return Action::make('download')
|
||||||
|
->label('دانلود')
|
||||||
|
->icon(Heroicon::OutlinedArrowDownTray)
|
||||||
|
->color('success')
|
||||||
|
->visible(fn (TemplateGeneration $record): bool => $record->status === TemplateGenerationStatus::Completed && filled($record->output_path))
|
||||||
|
->url(fn (TemplateGeneration $record): string => route('admin.generations.download', $record->uuid))
|
||||||
|
->openUrlInNewTab();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations\Actions;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Jobs\GenerateTemplateJob;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-runs the pptx fill step for a failed generation using its already-stored
|
||||||
|
* values (including any AI-generated text), without calling the AI service again.
|
||||||
|
*/
|
||||||
|
class RetryGenerationAction
|
||||||
|
{
|
||||||
|
public static function make(): Action
|
||||||
|
{
|
||||||
|
return Action::make('retry')
|
||||||
|
->label('تلاش دوباره')
|
||||||
|
->icon(Heroicon::OutlinedArrowPath)
|
||||||
|
->color('warning')
|
||||||
|
->requiresConfirmation()
|
||||||
|
->modalDescription('فایل پاورپوینت با همان محتوایی که قبلاً (از جمله متنهای تولیدشده با هوش مصنوعی) ذخیره شده، دوباره ساخته میشود. نیازی به تماس مجدد با هوش مصنوعی نیست.')
|
||||||
|
->visible(fn (TemplateGeneration $record): bool => $record->status === TemplateGenerationStatus::Failed)
|
||||||
|
->action(function (TemplateGeneration $record): void {
|
||||||
|
$record->update([
|
||||||
|
'status' => TemplateGenerationStatus::Pending,
|
||||||
|
'error_message' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
GenerateTemplateJob::dispatch($record);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('درخواست دوباره ارسال شد')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations\Schemas;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use Filament\Infolists\Components\KeyValueEntry;
|
||||||
|
use Filament\Infolists\Components\TextEntry;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class TemplateGenerationInfolist
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
TextEntry::make('title')
|
||||||
|
->label('نام فایل')
|
||||||
|
->placeholder('—')
|
||||||
|
->columnSpanFull(),
|
||||||
|
TextEntry::make('uuid')
|
||||||
|
->label('شناسه')
|
||||||
|
->copyable(),
|
||||||
|
TextEntry::make('template.title')
|
||||||
|
->label('قالب'),
|
||||||
|
TextEntry::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',
|
||||||
|
}),
|
||||||
|
TextEntry::make('requester.name')
|
||||||
|
->label('درخواستدهنده')
|
||||||
|
->placeholder('—'),
|
||||||
|
TextEntry::make('error_message')
|
||||||
|
->label('پیام خطا')
|
||||||
|
->placeholder('—')
|
||||||
|
->columnSpanFull(),
|
||||||
|
KeyValueEntry::make('values')
|
||||||
|
->label('محتوای ذخیرهشده (از جمله متنهای تولیدشده با هوش مصنوعی)')
|
||||||
|
->keyLabel('کلید')
|
||||||
|
->valueLabel('مقدار')
|
||||||
|
->columnSpanFull(),
|
||||||
|
TextEntry::make('created_at')
|
||||||
|
->label('تاریخ ایجاد')
|
||||||
|
->jalaliDateTime(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\TemplateGenerations\Tables;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Actions\DownloadGenerationAction;
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Actions\RetryGenerationAction;
|
||||||
|
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('title')
|
||||||
|
->label('نام فایل')
|
||||||
|
->searchable()
|
||||||
|
->sortable()
|
||||||
|
->description(fn ($record): string => $record->uuid)
|
||||||
|
->wrap(),
|
||||||
|
TextColumn::make('uuid')
|
||||||
|
->label('شناسه')
|
||||||
|
->searchable()
|
||||||
|
->copyable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
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('تاریخ')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->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(),
|
||||||
|
DownloadGenerationAction::make(),
|
||||||
|
RetryGenerationAction::make(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?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\Schemas\TemplateGenerationInfolist;
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Tables\TemplateGenerationsTable;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
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 infolist(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return TemplateGenerationInfolist::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Actions;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Enums\TemplateKeyType;
|
||||||
|
use App\Jobs\GenerateTemplateJob;
|
||||||
|
use App\Models\AiProvider;
|
||||||
|
use App\Models\Template;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use App\Services\Ai\OpenAiCompatibleTextGenerator;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Forms\Components\FileUpload;
|
||||||
|
use Filament\Forms\Components\Textarea;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class GenerateWithAiAction
|
||||||
|
{
|
||||||
|
public static function make(): Action
|
||||||
|
{
|
||||||
|
return Action::make('generateWithAi')
|
||||||
|
->label('تولید با هوش مصنوعی')
|
||||||
|
->icon(Heroicon::OutlinedSparkles)
|
||||||
|
->color('info')
|
||||||
|
->schema(function (Template $record): array {
|
||||||
|
$components = [
|
||||||
|
Textarea::make('topic')
|
||||||
|
->label('موضوع / محتوای خام')
|
||||||
|
->helperText('هوش مصنوعی بر اساس این متن، کلیدهای متنی قالب را تکمیل میکند.')
|
||||||
|
->required()
|
||||||
|
->rows(4),
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($record->keys->where('type', TemplateKeyType::Image) as $key) {
|
||||||
|
$components[] = FileUpload::make("images.{$key->key}")
|
||||||
|
->label($key->label)
|
||||||
|
->image()
|
||||||
|
->disk('local')
|
||||||
|
->directory('templates/generations/inputs')
|
||||||
|
->required($key->is_required);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $components;
|
||||||
|
})
|
||||||
|
->action(function (array $data, Template $record): void {
|
||||||
|
$provider = AiProvider::query()
|
||||||
|
->where('is_active', true)
|
||||||
|
->orderByDesc('is_default')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $provider) {
|
||||||
|
Notification::make()
|
||||||
|
->title('هیچ سرویس هوش مصنوعی فعالی تنظیم نشده است.')
|
||||||
|
->body('ابتدا از بخش «سرویسهای AI» یک سرویس فعال تعریف کنید.')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$values = app(OpenAiCompatibleTextGenerator::class)->generateForTemplate($record, $data['topic'], $provider);
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
Notification::make()
|
||||||
|
->title('خطا در تولید محتوا با هوش مصنوعی')
|
||||||
|
->body($exception->getMessage())
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data['images'] ?? [] as $key => $path) {
|
||||||
|
if ($path) {
|
||||||
|
$values[$key] = $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$generation = TemplateGeneration::query()->create([
|
||||||
|
'template_id' => $record->id,
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'status' => TemplateGenerationStatus::Pending,
|
||||||
|
'values' => $values,
|
||||||
|
'requested_by' => auth()->id(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
GenerateTemplateJob::dispatch($generation);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('درخواست تولید ثبت شد')
|
||||||
|
->body('نتیجه را میتوانید در تب «تولیدها» مشاهده کنید.')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Filament/Resources/Templates/Pages/EditTemplate.php
Normal file
25
app/Filament/Resources/Templates/Pages/EditTemplate.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\TemplateResource;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Actions\ForceDeleteAction;
|
||||||
|
use Filament\Actions\RestoreAction;
|
||||||
|
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(),
|
||||||
|
RestoreAction::make(),
|
||||||
|
ForceDeleteAction::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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
21
app/Filament/Resources/Templates/Pages/ViewTemplate.php
Normal file
21
app/Filament/Resources/Templates/Pages/ViewTemplate.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\Actions\GenerateWithAiAction;
|
||||||
|
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 [
|
||||||
|
GenerateWithAiAction::make(),
|
||||||
|
EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\RelationManagers;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Actions\DownloadGenerationAction;
|
||||||
|
use App\Filament\Resources\TemplateGenerations\Actions\RetryGenerationAction;
|
||||||
|
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('title')
|
||||||
|
->label('نام فایل')
|
||||||
|
->searchable()
|
||||||
|
->wrap(),
|
||||||
|
TextColumn::make('uuid')
|
||||||
|
->label('شناسه')
|
||||||
|
->searchable()
|
||||||
|
->copyable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
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('تاریخ')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->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([
|
||||||
|
DownloadGenerationAction::make(),
|
||||||
|
RetryGenerationAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?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('فقط نام کلید را وارد کنید، بدون آکولاد. مثلاً اگر داخل پاورپوینت نوشتهاید {Main Title}، اینجا فقط Main Title را وارد کنید؛ آکولاد را خود سیستم موقع جایگزینی اضافه میکند. برای عکس/چارت بهجای این، نام شکل (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),
|
||||||
|
Toggle::make('is_repeatable')
|
||||||
|
->label('تکرارشونده (برای ساخت با هوش مصنوعی)')
|
||||||
|
->helperText('اگر فعال باشد، این کلید در اسلاید تکرارشونده قرار دارد و برای هر اسلاید تولیدشده با هوش مصنوعی مقدار جداگانه دریافت میکند.')
|
||||||
|
->default(false)
|
||||||
|
->visible(fn (Get $get): bool => $get('type') === TemplateKeyType::Text->value),
|
||||||
|
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(),
|
||||||
|
IconColumn::make('is_repeatable')
|
||||||
|
->label('تکرارشونده')
|
||||||
|
->boolean(),
|
||||||
|
TextColumn::make('sort_order')
|
||||||
|
->label('ترتیب')
|
||||||
|
->sortable(),
|
||||||
|
])
|
||||||
|
->defaultSort('sort_order')
|
||||||
|
->headerActions([
|
||||||
|
CreateAction::make(),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
EditAction::make(),
|
||||||
|
DeleteAction::make(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
app/Filament/Resources/Templates/Schemas/TemplateForm.php
Normal file
70
app/Filament/Resources/Templates/Schemas/TemplateForm.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?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\Components\Utilities\Get;
|
||||||
|
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')
|
||||||
|
->visibility('public')
|
||||||
|
->image()
|
||||||
|
->imageEditor(),
|
||||||
|
Toggle::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->default(true),
|
||||||
|
Toggle::make('is_ai_enabled')
|
||||||
|
->label('امکان ساخت با هوش مصنوعی از متن')
|
||||||
|
->helperText('در صورت فعال بودن، این قالب در فرم «ساخت پاورپوینت از متن» به کاربران پیشنهاد داده میشود.')
|
||||||
|
->default(false)
|
||||||
|
->live(),
|
||||||
|
TextInput::make('ai_repeatable_slide_number')
|
||||||
|
->label('شماره اسلاید تکرارشونده')
|
||||||
|
->helperText('شماره اسلایدی از فایل پاورپوینت که برای هر بخش محتوای تولیدشده با هوش مصنوعی شبیهسازی میشود (مثلاً 2).')
|
||||||
|
->numeric()
|
||||||
|
->integer()
|
||||||
|
->minValue(1)
|
||||||
|
->visible(fn (Get $get): bool => (bool) $get('is_ai_enabled'))
|
||||||
|
->required(fn (Get $get): bool => (bool) $get('is_ai_enabled')),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Schemas;
|
||||||
|
|
||||||
|
use Filament\Infolists\Components\IconEntry;
|
||||||
|
use Filament\Infolists\Components\ImageEntry;
|
||||||
|
use Filament\Infolists\Components\TextEntry;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class TemplateInfolist
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
ImageEntry::make('thumbnail_path')
|
||||||
|
->label('تصویر بندانگشتی')
|
||||||
|
->disk('public')
|
||||||
|
->visibility('public')
|
||||||
|
->height(180)
|
||||||
|
->placeholder('بدون تصویر')
|
||||||
|
->columnSpanFull(),
|
||||||
|
TextEntry::make('title')
|
||||||
|
->label('عنوان'),
|
||||||
|
TextEntry::make('slug')
|
||||||
|
->label('شناسه')
|
||||||
|
->copyable(),
|
||||||
|
TextEntry::make('category.name')
|
||||||
|
->label('دستهبندی')
|
||||||
|
->placeholder('—'),
|
||||||
|
TextEntry::make('description')
|
||||||
|
->label('توضیحات')
|
||||||
|
->placeholder('—')
|
||||||
|
->columnSpanFull(),
|
||||||
|
IconEntry::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->boolean(),
|
||||||
|
IconEntry::make('is_ai_enabled')
|
||||||
|
->label('ساخت با هوش مصنوعی')
|
||||||
|
->boolean(),
|
||||||
|
TextEntry::make('ai_repeatable_slide_number')
|
||||||
|
->label('شماره اسلاید تکرارشونده')
|
||||||
|
->placeholder('—'),
|
||||||
|
TextEntry::make('generations_count')
|
||||||
|
->label('تعداد تولیدها')
|
||||||
|
->state(fn ($record): int => $record->generations()->count()),
|
||||||
|
TextEntry::make('creator.name')
|
||||||
|
->label('ایجادکننده')
|
||||||
|
->placeholder('—'),
|
||||||
|
TextEntry::make('created_at')
|
||||||
|
->label('تاریخ ایجاد')
|
||||||
|
->jalaliDateTime(),
|
||||||
|
TextEntry::make('updated_at')
|
||||||
|
->label('آخرین بروزرسانی')
|
||||||
|
->jalaliDateTime(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
76
app/Filament/Resources/Templates/Tables/TemplatesTable.php
Normal file
76
app/Filament/Resources/Templates/Tables/TemplatesTable.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Templates\Tables;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Templates\Actions\GenerateWithAiAction;
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Actions\DeleteBulkAction;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Actions\ForceDeleteAction;
|
||||||
|
use Filament\Actions\ForceDeleteBulkAction;
|
||||||
|
use Filament\Actions\RestoreAction;
|
||||||
|
use Filament\Actions\RestoreBulkAction;
|
||||||
|
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\Filters\TrashedFilter;
|
||||||
|
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('تاریخ ایجاد')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('category_id')
|
||||||
|
->label('دستهبندی')
|
||||||
|
->relationship('category', 'name'),
|
||||||
|
TernaryFilter::make('is_active')
|
||||||
|
->label('وضعیت')
|
||||||
|
->placeholder('همه')
|
||||||
|
->trueLabel('فعال')
|
||||||
|
->falseLabel('غیرفعال'),
|
||||||
|
TrashedFilter::make()
|
||||||
|
->label('وضعیت حذف'),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
ViewAction::make(),
|
||||||
|
EditAction::make(),
|
||||||
|
GenerateWithAiAction::make(),
|
||||||
|
DeleteAction::make(),
|
||||||
|
RestoreAction::make(),
|
||||||
|
ForceDeleteAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
RestoreBulkAction::make(),
|
||||||
|
ForceDeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
80
app/Filament/Resources/Templates/TemplateResource.php
Normal file
80
app/Filament/Resources/Templates/TemplateResource.php
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?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\Schemas\TemplateInfolist;
|
||||||
|
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 Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
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 infolist(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return TemplateInfolist::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return TemplatesTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()
|
||||||
|
->withoutGlobalScopes([SoftDeletingScope::class]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\Users\Schemas;
|
namespace App\Filament\Resources\Users\Schemas;
|
||||||
|
|
||||||
|
use App\Support\Mobile;
|
||||||
use Filament\Forms\Components\CheckboxList;
|
use Filament\Forms\Components\CheckboxList;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
@@ -25,6 +26,15 @@ class UserForm
|
|||||||
TextInput::make('mobile')
|
TextInput::make('mobile')
|
||||||
->label('شماره موبایل')
|
->label('شماره موبایل')
|
||||||
->tel()
|
->tel()
|
||||||
|
->helperText('مثال درست: 09123456789')
|
||||||
|
->dehydrateStateUsing(fn (?string $state): ?string => Mobile::normalize($state))
|
||||||
|
->rules([
|
||||||
|
fn (): \Closure => function (string $attribute, mixed $value, \Closure $fail): void {
|
||||||
|
if (filled($value) && ! preg_match(Mobile::REGEX, (string) Mobile::normalize((string) $value))) {
|
||||||
|
$fail('فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
])
|
||||||
->unique(ignoreRecord: true)
|
->unique(ignoreRecord: true)
|
||||||
->maxLength(20),
|
->maxLength(20),
|
||||||
TextInput::make('password')
|
TextInput::make('password')
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class UsersTable
|
|||||||
->searchable(),
|
->searchable(),
|
||||||
TextColumn::make('created_at')
|
TextColumn::make('created_at')
|
||||||
->label('تاریخ ایجاد')
|
->label('تاریخ ایجاد')
|
||||||
->dateTime()
|
->jalaliDateTime()
|
||||||
->sortable()
|
->sortable()
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\WalletTransactions\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\WalletTransactions\WalletTransactionResource;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListWalletTransactions extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = WalletTransactionResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\WalletTransactions\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\WalletTransactions\WalletTransactionResource;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewWalletTransaction extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = WalletTransactionResource::class;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\WalletTransactions\Tables;
|
||||||
|
|
||||||
|
use App\Enums\WalletTransactionType;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class WalletTransactionsTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('id')
|
||||||
|
->label('#')
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('wallet.user.name')
|
||||||
|
->label('کاربر')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('wallet.user.mobile')
|
||||||
|
->label('موبایل')
|
||||||
|
->searchable()
|
||||||
|
->toggleable(),
|
||||||
|
TextColumn::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (WalletTransactionType $state): string => $state->label())
|
||||||
|
->color(fn (WalletTransactionType $state): string => $state === WalletTransactionType::Credit ? 'success' : 'danger'),
|
||||||
|
TextColumn::make('amount')
|
||||||
|
->label('مبلغ')
|
||||||
|
->sortable()
|
||||||
|
->formatStateUsing(fn (int $state): string => number_format($state).' تومان'),
|
||||||
|
TextColumn::make('balance_after')
|
||||||
|
->label('موجودی بعد')
|
||||||
|
->formatStateUsing(fn (int $state): string => number_format($state).' تومان'),
|
||||||
|
TextColumn::make('description')
|
||||||
|
->label('توضیحات')
|
||||||
|
->limit(50)
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('creator.name')
|
||||||
|
->label('ثبتکننده')
|
||||||
|
->placeholder('سیستم'),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->sortable(),
|
||||||
|
])
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->options([
|
||||||
|
WalletTransactionType::Credit->value => WalletTransactionType::Credit->label(),
|
||||||
|
WalletTransactionType::Debit->value => WalletTransactionType::Debit->label(),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
ViewAction::make(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\WalletTransactions;
|
||||||
|
|
||||||
|
use App\Filament\Resources\WalletTransactions\Pages\ListWalletTransactions;
|
||||||
|
use App\Filament\Resources\WalletTransactions\Pages\ViewWalletTransaction;
|
||||||
|
use App\Filament\Resources\WalletTransactions\Tables\WalletTransactionsTable;
|
||||||
|
use App\Models\WalletTransaction;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class WalletTransactionResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = WalletTransaction::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowsRightLeft;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'مالی';
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'id';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'تراکنش';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'تراکنشها';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'تراکنشها';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 11;
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return WalletTransactionsTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListWalletTransactions::route('/'),
|
||||||
|
'view' => ViewWalletTransaction::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;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Wallets/Pages/EditWallet.php
Normal file
19
app/Filament/Resources/Wallets/Pages/EditWallet.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Wallets\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Wallets\WalletResource;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditWallet extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = WalletResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ViewAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
11
app/Filament/Resources/Wallets/Pages/ListWallets.php
Normal file
11
app/Filament/Resources/Wallets/Pages/ListWallets.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Wallets\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Wallets\WalletResource;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListWallets extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = WalletResource::class;
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Wallets/Pages/ViewWallet.php
Normal file
19
app/Filament/Resources/Wallets/Pages/ViewWallet.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Wallets\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Wallets\WalletResource;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewWallet extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = WalletResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Wallets\RelationManagers;
|
||||||
|
|
||||||
|
use App\Enums\WalletTransactionType;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\SelectFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class TransactionsRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'transactions';
|
||||||
|
|
||||||
|
protected static ?string $title = 'تراکنشها';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'تراکنش';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'تراکنشها';
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (WalletTransactionType $state): string => $state->label())
|
||||||
|
->color(fn (WalletTransactionType $state): string => $state === WalletTransactionType::Credit ? 'success' : 'danger'),
|
||||||
|
TextColumn::make('amount')
|
||||||
|
->label('مبلغ')
|
||||||
|
->formatStateUsing(fn (int $state): string => number_format($state).' تومان'),
|
||||||
|
TextColumn::make('balance_before')
|
||||||
|
->label('قبل')
|
||||||
|
->formatStateUsing(fn (int $state): string => number_format($state)),
|
||||||
|
TextColumn::make('balance_after')
|
||||||
|
->label('بعد')
|
||||||
|
->formatStateUsing(fn (int $state): string => number_format($state)),
|
||||||
|
TextColumn::make('description')
|
||||||
|
->label('توضیحات')
|
||||||
|
->limit(40),
|
||||||
|
TextColumn::make('creator.name')
|
||||||
|
->label('ثبتکننده')
|
||||||
|
->placeholder('سیستم'),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('تاریخ')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->sortable(),
|
||||||
|
])
|
||||||
|
->defaultSort('created_at', 'desc')
|
||||||
|
->filters([
|
||||||
|
SelectFilter::make('type')
|
||||||
|
->label('نوع')
|
||||||
|
->options([
|
||||||
|
WalletTransactionType::Credit->value => WalletTransactionType::Credit->label(),
|
||||||
|
WalletTransactionType::Debit->value => WalletTransactionType::Debit->label(),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->recordActions([])
|
||||||
|
->toolbarActions([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Wallets/Schemas/WalletForm.php
Normal file
19
app/Filament/Resources/Wallets/Schemas/WalletForm.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Wallets\Schemas;
|
||||||
|
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
|
||||||
|
class WalletForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
Toggle::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->default(true),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
112
app/Filament/Resources/Wallets/Tables/WalletsTable.php
Normal file
112
app/Filament/Resources/Wallets/Tables/WalletsTable.php
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Wallets\Tables;
|
||||||
|
|
||||||
|
use App\Models\Wallet;
|
||||||
|
use App\Services\WalletService;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Actions\ViewAction;
|
||||||
|
use Filament\Forms\Components\Textarea;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Columns\IconColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Filters\TernaryFilter;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class WalletsTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('user.name')
|
||||||
|
->label('کاربر')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('user.email')
|
||||||
|
->label('ایمیل')
|
||||||
|
->searchable()
|
||||||
|
->toggleable(),
|
||||||
|
TextColumn::make('user.mobile')
|
||||||
|
->label('موبایل')
|
||||||
|
->searchable()
|
||||||
|
->toggleable(),
|
||||||
|
TextColumn::make('balance')
|
||||||
|
->label('موجودی (تومان)')
|
||||||
|
->numeric()
|
||||||
|
->sortable()
|
||||||
|
->formatStateUsing(fn (int $state): string => number_format($state).' تومان'),
|
||||||
|
IconColumn::make('is_active')
|
||||||
|
->label('فعال')
|
||||||
|
->boolean(),
|
||||||
|
TextColumn::make('updated_at')
|
||||||
|
->label('آخرین بروزرسانی')
|
||||||
|
->jalaliDateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->defaultSort('balance', 'desc')
|
||||||
|
->filters([
|
||||||
|
TernaryFilter::make('is_active')
|
||||||
|
->label('وضعیت')
|
||||||
|
->placeholder('همه')
|
||||||
|
->trueLabel('فعال')
|
||||||
|
->falseLabel('غیرفعال'),
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
ViewAction::make(),
|
||||||
|
EditAction::make(),
|
||||||
|
self::adjustAction('credit', 'واریز', Heroicon::OutlinedPlusCircle, 'success'),
|
||||||
|
self::adjustAction('debit', 'برداشت', Heroicon::OutlinedMinusCircle, 'danger'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function adjustAction(string $type, string $label, Heroicon $icon, string $color): Action
|
||||||
|
{
|
||||||
|
return Action::make($type)
|
||||||
|
->label($label)
|
||||||
|
->icon($icon)
|
||||||
|
->color($color)
|
||||||
|
->schema([
|
||||||
|
TextInput::make('amount')
|
||||||
|
->label('مبلغ (تومان)')
|
||||||
|
->numeric()
|
||||||
|
->required()
|
||||||
|
->minValue(1)
|
||||||
|
->integer(),
|
||||||
|
Textarea::make('description')
|
||||||
|
->label('توضیحات')
|
||||||
|
->maxLength(500)
|
||||||
|
->rows(2),
|
||||||
|
])
|
||||||
|
->action(function (Wallet $record, array $data, WalletService $walletService) use ($type): void {
|
||||||
|
$amount = (int) $data['amount'];
|
||||||
|
$description = filled($data['description'] ?? null) ? $data['description'] : null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$transaction = $type === 'credit'
|
||||||
|
? $walletService->credit($record, $amount, $description, auth()->user())
|
||||||
|
: $walletService->debit($record, $amount, $description, auth()->user());
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title($type === 'credit' ? 'واریز انجام شد' : 'برداشت انجام شد')
|
||||||
|
->body('موجودی جدید: '.number_format($transaction->balance_after).' تومان')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
report($exception);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title($type === 'credit' ? 'واریز ناموفق بود' : 'برداشت ناموفق بود')
|
||||||
|
->body($exception->getMessage() ?: 'خطای نامشخص هنگام ثبت تراکنش.')
|
||||||
|
->danger()
|
||||||
|
->persistent()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
67
app/Filament/Resources/Wallets/WalletResource.php
Normal file
67
app/Filament/Resources/Wallets/WalletResource.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Wallets;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Wallets\Pages\EditWallet;
|
||||||
|
use App\Filament\Resources\Wallets\Pages\ListWallets;
|
||||||
|
use App\Filament\Resources\Wallets\Pages\ViewWallet;
|
||||||
|
use App\Filament\Resources\Wallets\RelationManagers\TransactionsRelationManager;
|
||||||
|
use App\Filament\Resources\Wallets\Schemas\WalletForm;
|
||||||
|
use App\Filament\Resources\Wallets\Tables\WalletsTable;
|
||||||
|
use App\Models\Wallet;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use UnitEnum;
|
||||||
|
|
||||||
|
class WalletResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Wallet::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedWallet;
|
||||||
|
|
||||||
|
protected static string|UnitEnum|null $navigationGroup = 'مالی';
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'id';
|
||||||
|
|
||||||
|
protected static ?string $modelLabel = 'کیف پول';
|
||||||
|
|
||||||
|
protected static ?string $pluralModelLabel = 'کیف پولها';
|
||||||
|
|
||||||
|
protected static ?string $navigationLabel = 'کیف پولها';
|
||||||
|
|
||||||
|
protected static ?int $navigationSort = 10;
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return WalletForm::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return WalletsTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
TransactionsRelationManager::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListWallets::route('/'),
|
||||||
|
'view' => ViewWallet::route('/{record}'),
|
||||||
|
'edit' => EditWallet::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function canCreate(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Http/Controllers/Admin/GenerationDownloadController.php
Normal file
23
app/Http/Controllers/Admin/GenerationDownloadController.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
|
|
||||||
|
class GenerationDownloadController extends Controller
|
||||||
|
{
|
||||||
|
public function __invoke(Request $request, TemplateGeneration $generation): StreamedResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
abort_unless($user && ($user->hasRole('admin') || $user->hasPermission('templates.manage')), 403);
|
||||||
|
abort_if($generation->status !== TemplateGenerationStatus::Completed || ! $generation->output_path, 404);
|
||||||
|
|
||||||
|
return Storage::disk('local')->download($generation->output_path, $generation->downloadFilename().'.pptx');
|
||||||
|
}
|
||||||
|
}
|
||||||
150
app/Http/Controllers/Api/AuthController.php
Normal file
150
app/Http/Controllers/Api/AuthController.php
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
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;
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
|
class AuthController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
#[OA\Post(
|
||||||
|
path: '/auth/register',
|
||||||
|
description: 'Register a new user account',
|
||||||
|
summary: 'Register',
|
||||||
|
tags: ['Auth'],
|
||||||
|
requestBody: new OA\RequestBody(
|
||||||
|
required: true,
|
||||||
|
content: new OA\JsonContent(
|
||||||
|
required: ['name', 'mobile', 'email', 'password'],
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'name', type: 'string', example: 'علی رضایی'),
|
||||||
|
new OA\Property(property: 'mobile', type: 'string', example: '09123456789'),
|
||||||
|
new OA\Property(property: 'email', type: 'string', format: 'email', example: 'ali@example.com'),
|
||||||
|
new OA\Property(property: 'password', type: 'string', format: 'password', example: 'password123'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
responses: [
|
||||||
|
new OA\Response(
|
||||||
|
response: 201,
|
||||||
|
description: 'Registered 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'),
|
||||||
|
new OA\Property(property: 'token', type: 'string'),
|
||||||
|
],
|
||||||
|
type: 'object'
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new OA\Response(response: 422, description: 'Validation error'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function register(RegisterRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = User::query()->create([
|
||||||
|
'name' => $request->validated('name'),
|
||||||
|
'username' => $this->generateUsername($request->validated('email')),
|
||||||
|
'mobile' => $request->validated('mobile'),
|
||||||
|
'email' => $request->validated('email'),
|
||||||
|
'password' => $request->validated('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$token = $user->createToken('auth-token')->plainTextToken;
|
||||||
|
|
||||||
|
return $this->success('ثبتنام با موفقیت انجام شد.', [
|
||||||
|
'user' => new UserResource($user),
|
||||||
|
'token' => $token,
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Post(
|
||||||
|
path: '/auth/login',
|
||||||
|
description: 'Login with email or username',
|
||||||
|
summary: 'Login',
|
||||||
|
tags: ['Auth'],
|
||||||
|
requestBody: new OA\RequestBody(
|
||||||
|
required: true,
|
||||||
|
content: new OA\JsonContent(
|
||||||
|
required: ['login', 'password'],
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'login', description: 'Email or username', type: 'string', example: 'ali@example.com'),
|
||||||
|
new OA\Property(property: 'password', type: 'string', format: 'password', example: 'password123'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
responses: [
|
||||||
|
new OA\Response(
|
||||||
|
response: 200,
|
||||||
|
description: 'Logged in 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'),
|
||||||
|
new OA\Property(property: 'token', type: 'string'),
|
||||||
|
],
|
||||||
|
type: 'object'
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new OA\Response(response: 422, description: 'Invalid credentials'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function login(LoginRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$login = $request->validated('login');
|
||||||
|
|
||||||
|
$user = User::query()
|
||||||
|
->where(function ($query) use ($login): void {
|
||||||
|
$query->where('email', $login)
|
||||||
|
->orWhere('username', $login);
|
||||||
|
})
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $user || ! Hash::check($request->validated('password'), $user->password)) {
|
||||||
|
return $this->error('اطلاعات ورود نادرست است.', [
|
||||||
|
'login' => ['ایمیل یا نام کاربری یا رمز عبور اشتباه است.'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$token = $user->createToken('auth-token')->plainTextToken;
|
||||||
|
|
||||||
|
return $this->success('ورود با موفقیت انجام شد.', [
|
||||||
|
'user' => new UserResource($user),
|
||||||
|
'token' => $token,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateUsername(string $email): string
|
||||||
|
{
|
||||||
|
$base = Str::slug(Str::before($email, '@'), '') ?: 'user';
|
||||||
|
$username = $base;
|
||||||
|
$counter = 1;
|
||||||
|
|
||||||
|
while (User::query()->where('username', $username)->exists()) {
|
||||||
|
$username = $base . $counter;
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $username;
|
||||||
|
}
|
||||||
|
}
|
||||||
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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
181
app/Http/Controllers/Api/NotificationController.php
Normal file
181
app/Http/Controllers/Api/NotificationController.php
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Api\UpdateNotificationPreferencesRequest;
|
||||||
|
use App\Http\Resources\NotificationPreferenceResource;
|
||||||
|
use App\Http\Resources\NotificationResource;
|
||||||
|
use App\Models\NotificationPreference;
|
||||||
|
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('همه نوتیفیکیشنها خوانده شد.');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Get(
|
||||||
|
path: '/notifications/preferences',
|
||||||
|
description: 'Get the authenticated user notification preferences',
|
||||||
|
summary: 'Show notification preferences',
|
||||||
|
security: [['sanctum' => []]],
|
||||||
|
tags: ['Notifications'],
|
||||||
|
responses: [
|
||||||
|
new OA\Response(
|
||||||
|
response: 200,
|
||||||
|
description: 'Notification preferences 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: 'preferences', ref: '#/components/schemas/NotificationPreference'),
|
||||||
|
],
|
||||||
|
type: 'object'
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new OA\Response(response: 401, description: 'Unauthenticated'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function preferences(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$preferences = $this->firstOrCreatePreferences($request);
|
||||||
|
|
||||||
|
return $this->success('تنظیمات اعلانها با موفقیت دریافت شد.', [
|
||||||
|
'preferences' => new NotificationPreferenceResource($preferences),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Put(
|
||||||
|
path: '/notifications/preferences',
|
||||||
|
description: 'Update the authenticated user notification preferences',
|
||||||
|
summary: 'Update notification preferences',
|
||||||
|
security: [['sanctum' => []]],
|
||||||
|
tags: ['Notifications'],
|
||||||
|
requestBody: new OA\RequestBody(
|
||||||
|
required: true,
|
||||||
|
content: new OA\JsonContent(ref: '#/components/schemas/NotificationPreference')
|
||||||
|
),
|
||||||
|
responses: [
|
||||||
|
new OA\Response(
|
||||||
|
response: 200,
|
||||||
|
description: 'Notification preferences 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: 'preferences', ref: '#/components/schemas/NotificationPreference'),
|
||||||
|
],
|
||||||
|
type: 'object'
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new OA\Response(response: 401, description: 'Unauthenticated'),
|
||||||
|
new OA\Response(response: 422, description: 'Validation error'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function updatePreferences(UpdateNotificationPreferencesRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$preferences = $this->firstOrCreatePreferences($request);
|
||||||
|
|
||||||
|
$preferences->update($request->validated());
|
||||||
|
|
||||||
|
return $this->success('تنظیمات اعلانها با موفقیت بهروزرسانی شد.', [
|
||||||
|
'preferences' => new NotificationPreferenceResource($preferences->fresh()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function firstOrCreatePreferences(Request $request): NotificationPreference
|
||||||
|
{
|
||||||
|
return $request->user()->notificationPreference()->firstOrCreate([], [
|
||||||
|
'comment_on_presentation' => true,
|
||||||
|
'form_reply' => false,
|
||||||
|
'new_follower' => false,
|
||||||
|
'news_announcements' => false,
|
||||||
|
'weekly_product_updates' => true,
|
||||||
|
'weekly_blog_digest' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
201
app/Http/Controllers/Api/ProfileController.php
Normal file
201
app/Http/Controllers/Api/ProfileController.php
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Profile\ChangePasswordRequest;
|
||||||
|
use App\Http\Requests\Profile\DeleteAccountRequest;
|
||||||
|
use App\Http\Requests\Profile\UpdateProfileRequest;
|
||||||
|
use App\Http\Resources\UserResource;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
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();
|
||||||
|
|
||||||
|
$data = $request->safe()->except('avatar');
|
||||||
|
|
||||||
|
if ($request->hasFile('avatar')) {
|
||||||
|
if ($user->avatar_path) {
|
||||||
|
Storage::disk('public')->delete($user->avatar_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['avatar_path'] = $request->file('avatar')->store('avatars', 'public');
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->update($data);
|
||||||
|
|
||||||
|
return $this->success('پروفایل با موفقیت بهروزرسانی شد.', [
|
||||||
|
'user' => new UserResource($user->fresh()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Put(
|
||||||
|
path: '/profile/password',
|
||||||
|
description: 'Change the authenticated user password',
|
||||||
|
summary: 'Change password',
|
||||||
|
security: [['sanctum' => []]],
|
||||||
|
tags: ['Profile'],
|
||||||
|
requestBody: new OA\RequestBody(
|
||||||
|
required: true,
|
||||||
|
content: new OA\JsonContent(
|
||||||
|
required: ['current_password', 'password', 'password_confirmation'],
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'current_password', type: 'string', format: 'password'),
|
||||||
|
new OA\Property(property: 'password', type: 'string', format: 'password'),
|
||||||
|
new OA\Property(property: 'password_confirmation', type: 'string', format: 'password'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
responses: [
|
||||||
|
new OA\Response(
|
||||||
|
response: 200,
|
||||||
|
description: 'Password changed 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'),
|
||||||
|
new OA\Response(response: 422, description: 'Validation error'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function changePassword(ChangePasswordRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$user->update(['password' => $request->validated('password')]);
|
||||||
|
|
||||||
|
$currentTokenId = $user->currentAccessToken()?->id;
|
||||||
|
|
||||||
|
if ($currentTokenId) {
|
||||||
|
$user->tokens()->where('id', '!=', $currentTokenId)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success('رمز عبور با موفقیت تغییر کرد.');
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Delete(
|
||||||
|
path: '/profile',
|
||||||
|
description: 'Delete the authenticated user account. Requires the current password for confirmation.',
|
||||||
|
summary: 'Delete account',
|
||||||
|
security: [['sanctum' => []]],
|
||||||
|
tags: ['Profile'],
|
||||||
|
requestBody: new OA\RequestBody(
|
||||||
|
required: true,
|
||||||
|
content: new OA\JsonContent(
|
||||||
|
required: ['password'],
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'password', type: 'string', format: 'password', example: 'password123'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
responses: [
|
||||||
|
new OA\Response(
|
||||||
|
response: 200,
|
||||||
|
description: 'Account deleted 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 destroy(DeleteAccountRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
if ($user->avatar_path) {
|
||||||
|
Storage::disk('public')->delete($user->avatar_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->tokens()->delete();
|
||||||
|
$user->delete();
|
||||||
|
|
||||||
|
return $this->success('حساب کاربری با موفقیت حذف شد.');
|
||||||
|
}
|
||||||
|
}
|
||||||
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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
278
app/Http/Controllers/Api/TemplateGenerationController.php
Normal file
278
app/Http/Controllers/Api/TemplateGenerationController.php
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationSource;
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Enums\TemplateKeyType;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Api\GenerateAiPresentationRequest;
|
||||||
|
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\Support\Jalali;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
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,
|
||||||
|
'title' => $this->buildGenerationTitle($template, $request),
|
||||||
|
'status' => TemplateGenerationStatus::Pending,
|
||||||
|
'values' => $storedValues,
|
||||||
|
'requested_by' => $request->user()->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
GenerateTemplateJob::dispatch($generation);
|
||||||
|
|
||||||
|
return $this->success('درخواست تولید پاورپوینت ثبت شد.', [
|
||||||
|
'generation' => new TemplateGenerationResource($generation),
|
||||||
|
], 202);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Post(
|
||||||
|
path: '/templates/{slug}/generate-from-text',
|
||||||
|
description: 'Start generating a presentation from free-form text using AI',
|
||||||
|
summary: 'Generate presentation from text (AI)',
|
||||||
|
security: [['sanctum' => []]],
|
||||||
|
tags: ['Templates'],
|
||||||
|
parameters: [
|
||||||
|
new OA\Parameter(name: 'slug', description: 'Template slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
|
||||||
|
],
|
||||||
|
requestBody: new OA\RequestBody(
|
||||||
|
required: true,
|
||||||
|
content: new OA\JsonContent(
|
||||||
|
required: ['title', 'language', 'slide_count', 'text'],
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'title', type: 'string', example: 'گزارش فروش سال ۱۴۰۴'),
|
||||||
|
new OA\Property(property: 'language', type: 'string', example: 'fa'),
|
||||||
|
new OA\Property(property: 'slide_count', type: 'integer', example: 10),
|
||||||
|
new OA\Property(property: 'text', type: 'string', example: 'متن، عناوین، بولتها و قوانین موردنظر...'),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
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 storeFromText(GenerateAiPresentationRequest $request, Template $template): JsonResponse
|
||||||
|
{
|
||||||
|
$generation = TemplateGeneration::query()->create([
|
||||||
|
'template_id' => $template->id,
|
||||||
|
'uuid' => (string) Str::uuid(),
|
||||||
|
'source' => TemplateGenerationSource::AiText,
|
||||||
|
'title' => $request->validated('title'),
|
||||||
|
'language' => $request->validated('language'),
|
||||||
|
'slide_count' => $request->validated('slide_count'),
|
||||||
|
'source_text' => $request->validated('text'),
|
||||||
|
'status' => TemplateGenerationStatus::Pending,
|
||||||
|
'requested_by' => $request->user()->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
GenerateTemplateJob::dispatch($generation);
|
||||||
|
|
||||||
|
return $this->success('درخواست تولید پاورپوینت ثبت شد.', [
|
||||||
|
'generation' => new TemplateGenerationResource($generation),
|
||||||
|
], 202);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Get(
|
||||||
|
path: '/generations',
|
||||||
|
description: 'List the authenticated user presentation generations (both template-based and AI-generated)',
|
||||||
|
summary: 'List my presentations',
|
||||||
|
security: [['sanctum' => []]],
|
||||||
|
tags: ['Templates'],
|
||||||
|
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: 'Generations 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: 'generations',
|
||||||
|
type: 'array',
|
||||||
|
items: new OA\Items(ref: '#/components/schemas/TemplateGeneration')
|
||||||
|
),
|
||||||
|
],
|
||||||
|
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);
|
||||||
|
|
||||||
|
$generations = TemplateGeneration::query()
|
||||||
|
->with('template')
|
||||||
|
->where('requested_by', $request->user()->id)
|
||||||
|
->latest()
|
||||||
|
->paginate($perPage);
|
||||||
|
|
||||||
|
return $this->success('پاورپوینتهای شما با موفقیت دریافت شد.', [
|
||||||
|
'generations' => TemplateGenerationResource::collection($generations)->response()->getData(true),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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->downloadFilename().'.pptx');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildGenerationTitle(Template $template, Request $request): string
|
||||||
|
{
|
||||||
|
$label = $request->user()?->name ?: 'کاربر';
|
||||||
|
|
||||||
|
return sprintf('%s - %s - %s', $template->title, $label, Jalali::date(now()));
|
||||||
|
}
|
||||||
|
}
|
||||||
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),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
89
app/Http/Controllers/Api/WalletDepositController.php
Normal file
89
app/Http/Controllers/Api/WalletDepositController.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\Api\InitiateDepositRequest;
|
||||||
|
use App\Http\Resources\WalletDepositResource;
|
||||||
|
use App\Models\WalletDeposit;
|
||||||
|
use App\Services\WalletDepositService;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
|
class WalletDepositController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function __construct(private readonly WalletDepositService $walletDepositService) {}
|
||||||
|
|
||||||
|
#[OA\Post(
|
||||||
|
path: '/wallet/deposits',
|
||||||
|
description: 'Initiate a wallet top-up and get a payment redirect URL',
|
||||||
|
summary: 'Initiate wallet deposit',
|
||||||
|
security: [['sanctum' => []]],
|
||||||
|
tags: ['Wallet'],
|
||||||
|
requestBody: new OA\RequestBody(
|
||||||
|
required: true,
|
||||||
|
content: new OA\JsonContent(
|
||||||
|
required: ['amount'],
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'amount', type: 'integer', example: 500000),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
responses: [
|
||||||
|
new OA\Response(
|
||||||
|
response: 201,
|
||||||
|
description: 'Deposit initiated successfully',
|
||||||
|
content: new OA\JsonContent(
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'message', type: 'string', example: 'درخواست شارژ کیف پول ثبت شد.'),
|
||||||
|
new OA\Property(
|
||||||
|
property: 'data',
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'deposit', ref: '#/components/schemas/WalletDeposit'),
|
||||||
|
new OA\Property(property: 'payment_url', type: 'string'),
|
||||||
|
],
|
||||||
|
type: 'object'
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
new OA\Response(response: 401, description: 'Unauthenticated'),
|
||||||
|
new OA\Response(response: 422, description: 'Validation error'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function store(InitiateDepositRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$result = $this->walletDepositService->initiate($request->user(), $request->validated('amount'));
|
||||||
|
|
||||||
|
return $this->success('درخواست شارژ کیف پول ثبت شد.', [
|
||||||
|
'deposit' => new WalletDepositResource($result['deposit']),
|
||||||
|
'payment_url' => $result['payment_url'],
|
||||||
|
], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[OA\Get(
|
||||||
|
path: '/wallet/deposits/{deposit}/callback',
|
||||||
|
description: 'Public callback the payment gateway redirects to after a payment attempt',
|
||||||
|
summary: 'Wallet deposit callback',
|
||||||
|
tags: ['Wallet'],
|
||||||
|
parameters: [
|
||||||
|
new OA\Parameter(name: 'deposit', description: 'Deposit id', in: 'path', required: true, schema: new OA\Schema(type: 'integer')),
|
||||||
|
],
|
||||||
|
responses: [
|
||||||
|
new OA\Response(response: 302, description: 'Redirects to the frontend wallet page with a status query param'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
public function callback(WalletDeposit $deposit, Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$success = $this->walletDepositService->handleCallback($deposit, $request->query());
|
||||||
|
|
||||||
|
return redirect()->away(
|
||||||
|
rtrim((string) config('app.frontend_url'), '/').'/wallet?status='.($success ? 'success' : 'failed')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
app/Http/Requests/Api/GenerateAiPresentationRequest.php
Normal file
57
app/Http/Requests/Api/GenerateAiPresentationRequest.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Api;
|
||||||
|
|
||||||
|
use App\Models\Template;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
|
class GenerateAiPresentationRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title' => ['required', 'string', 'max:255'],
|
||||||
|
'language' => ['required', 'string', 'in:fa,en,ar'],
|
||||||
|
'slide_count' => ['required', 'integer', 'min:3', 'max:30'],
|
||||||
|
'text' => ['required', 'string', 'min:20'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withValidator(Validator $validator): void
|
||||||
|
{
|
||||||
|
$validator->after(function (Validator $validator): void {
|
||||||
|
/** @var Template $template */
|
||||||
|
$template = $this->route('template');
|
||||||
|
|
||||||
|
if (! $template->is_ai_enabled) {
|
||||||
|
$validator->errors()->add('template', 'این قالب برای ساخت پاورپوینت با هوش مصنوعی فعال نیست.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'title.required' => 'عنوان پاورپوینت الزامی است.',
|
||||||
|
'language.required' => 'زبان ارائه الزامی است.',
|
||||||
|
'language.in' => 'زبان انتخابشده پشتیبانی نمیشود.',
|
||||||
|
'slide_count.required' => 'تعداد اسلاید الزامی است.',
|
||||||
|
'slide_count.min' => 'تعداد اسلاید باید حداقل :min باشد.',
|
||||||
|
'slide_count.max' => 'تعداد اسلاید باید حداکثر :max باشد.',
|
||||||
|
'text.required' => 'متن ورودی الزامی است.',
|
||||||
|
'text.min' => 'متن ورودی باید حداقل :min کاراکتر باشد.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
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 از نوع چارت است و فعلاً پشتیبانی نمیشود.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Http/Requests/Api/InitiateDepositRequest.php
Normal file
35
app/Http/Requests/Api/InitiateDepositRequest.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Api;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class InitiateDepositRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'amount' => ['required', 'integer', 'min:10000'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'amount.required' => 'مبلغ شارژ الزامی است.',
|
||||||
|
'amount.integer' => 'مبلغ باید عدد باشد.',
|
||||||
|
'amount.min' => 'حداقل مبلغ شارژ :min تومان است.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Api;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdateNotificationPreferencesRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
private const FIELDS = [
|
||||||
|
'comment_on_presentation',
|
||||||
|
'form_reply',
|
||||||
|
'new_follower',
|
||||||
|
'news_announcements',
|
||||||
|
'weekly_product_updates',
|
||||||
|
'weekly_blog_digest',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept "true"/"false"/"1"/"0"/1/0 strings from the frontend and coerce them to
|
||||||
|
* real booleans before validation so the toggles actually persist.
|
||||||
|
*/
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
$normalized = [];
|
||||||
|
|
||||||
|
foreach (self::FIELDS as $field) {
|
||||||
|
if ($this->has($field)) {
|
||||||
|
$normalized[$field] = filter_var($this->input($field), FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE) ?? false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($normalized !== []) {
|
||||||
|
$this->merge($normalized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return array_fill_keys(self::FIELDS, ['sometimes', 'boolean']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'*.boolean' => 'مقدار این تنظیم باید بله یا خیر باشد.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Http/Requests/Auth/LoginRequest.php
Normal file
35
app/Http/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Auth;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class LoginRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'login' => ['required', 'string'],
|
||||||
|
'password' => ['required', 'string'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'login.required' => 'ایمیل یا نام کاربری الزامی است.',
|
||||||
|
'password.required' => 'رمز عبور الزامی است.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
52
app/Http/Requests/Auth/RegisterRequest.php
Normal file
52
app/Http/Requests/Auth/RegisterRequest.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Auth;
|
||||||
|
|
||||||
|
use App\Support\Mobile;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class RegisterRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
if ($this->has('mobile')) {
|
||||||
|
$this->merge(['mobile' => Mobile::normalize($this->input('mobile'))]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => ['required', 'string', 'max:255'],
|
||||||
|
'mobile' => ['required', 'string', 'regex:'.Mobile::REGEX, 'unique:users,mobile'],
|
||||||
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
|
||||||
|
'password' => ['required', 'string', 'min:8'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name.required' => 'نام و نام خانوادگی الزامی است.',
|
||||||
|
'mobile.required' => 'شماره موبایل الزامی است.',
|
||||||
|
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789',
|
||||||
|
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
|
||||||
|
'email.required' => 'ایمیل الزامی است.',
|
||||||
|
'email.email' => 'فرمت ایمیل صحیح نیست.',
|
||||||
|
'email.unique' => 'این ایمیل قبلاً ثبت شده است.',
|
||||||
|
'password.required' => 'رمز عبور الزامی است.',
|
||||||
|
'password.min' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Requests/Profile/ChangePasswordRequest.php
Normal file
38
app/Http/Requests/Profile/ChangePasswordRequest.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Profile;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ChangePasswordRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'current_password' => ['required', 'string', 'current_password'],
|
||||||
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'current_password.required' => 'رمز عبور فعلی الزامی است.',
|
||||||
|
'current_password.current_password' => 'رمز عبور فعلی صحیح نیست.',
|
||||||
|
'password.required' => 'رمز عبور جدید الزامی است.',
|
||||||
|
'password.min' => 'رمز عبور جدید باید حداقل ۸ کاراکتر باشد.',
|
||||||
|
'password.confirmed' => 'تکرار رمز عبور جدید مطابقت ندارد.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/Http/Requests/Profile/DeleteAccountRequest.php
Normal file
34
app/Http/Requests/Profile/DeleteAccountRequest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Profile;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class DeleteAccountRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'password' => ['required', 'string', 'current_password'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'password.required' => 'برای حذف حساب کاربری، وارد کردن رمز عبور الزامی است.',
|
||||||
|
'password.current_password' => 'رمز عبور واردشده صحیح نیست.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
69
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal file
69
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\Profile;
|
||||||
|
|
||||||
|
use App\Support\Mobile;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
class UpdateProfileRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
if ($this->has('mobile')) {
|
||||||
|
$this->merge(['mobile' => Mobile::normalize($this->input('mobile'))]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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:'.Mobile::REGEX, Rule::unique('users', 'mobile')->ignore($userId)],
|
||||||
|
'password' => ['sometimes', 'required', 'string', 'min:8'],
|
||||||
|
'avatar' => ['sometimes', 'nullable', 'image', 'max:3072'],
|
||||||
|
'is_public' => ['sometimes', 'nullable', 'boolean'],
|
||||||
|
'social_links' => ['sometimes', 'nullable', 'array'],
|
||||||
|
'social_links.instagram' => ['nullable', 'string', 'max:255'],
|
||||||
|
'social_links.telegram' => ['nullable', 'string', 'max:255'],
|
||||||
|
'social_links.linkedin' => ['nullable', 'string', 'max:255'],
|
||||||
|
'social_links.twitter' => ['nullable', 'string', 'max:255'],
|
||||||
|
'social_links.website' => ['nullable', 'string', 'max:255'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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' => 'فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789',
|
||||||
|
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
|
||||||
|
'password.required' => 'رمز عبور الزامی است.',
|
||||||
|
'password.min' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
|
||||||
|
'avatar.image' => 'فایل ارسالی باید تصویر باشد.',
|
||||||
|
'avatar.max' => 'حداکثر حجم تصویر ۳ مگابایت است.',
|
||||||
|
'social_links.array' => 'ساختار شبکههای اجتماعی نامعتبر است.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
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,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Resources/NotificationPreferenceResource.php
Normal file
38
app/Http/Resources/NotificationPreferenceResource.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use App\Models\NotificationPreference;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
|
#[OA\Schema(
|
||||||
|
schema: 'NotificationPreference',
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'comment_on_presentation', type: 'boolean', example: true),
|
||||||
|
new OA\Property(property: 'form_reply', type: 'boolean', example: false),
|
||||||
|
new OA\Property(property: 'new_follower', type: 'boolean', example: false),
|
||||||
|
new OA\Property(property: 'news_announcements', type: 'boolean', example: false),
|
||||||
|
new OA\Property(property: 'weekly_product_updates', type: 'boolean', example: true),
|
||||||
|
new OA\Property(property: 'weekly_blog_digest', type: 'boolean', example: false),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
/** @mixin NotificationPreference */
|
||||||
|
class NotificationPreferenceResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'comment_on_presentation' => $this->comment_on_presentation,
|
||||||
|
'form_reply' => $this->form_reply,
|
||||||
|
'new_follower' => $this->new_follower,
|
||||||
|
'news_announcements' => $this->news_announcements,
|
||||||
|
'weekly_product_updates' => $this->weekly_product_updates,
|
||||||
|
'weekly_blog_digest' => $this->weekly_blog_digest,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
61
app/Http/Resources/TemplateGenerationResource.php
Normal file
61
app/Http/Resources/TemplateGenerationResource.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?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: 'title', type: 'string', example: 'گزارش فروش سال ۱۴۰۴'),
|
||||||
|
new OA\Property(property: 'source', type: 'string', example: 'ai_text'),
|
||||||
|
new OA\Property(property: 'source_label', type: 'string', example: 'ساخت با هوش مصنوعی از متن'),
|
||||||
|
new OA\Property(property: 'language', type: 'string', example: 'fa', nullable: true),
|
||||||
|
new OA\Property(property: 'slide_count', type: 'integer', example: 10, nullable: true),
|
||||||
|
new OA\Property(
|
||||||
|
property: 'template',
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'title', type: 'string'),
|
||||||
|
new OA\Property(property: 'slug', type: 'string'),
|
||||||
|
],
|
||||||
|
type: 'object',
|
||||||
|
nullable: true
|
||||||
|
),
|
||||||
|
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,
|
||||||
|
'title' => $this->title ?: $this->template?->title,
|
||||||
|
'source' => $this->source->value,
|
||||||
|
'source_label' => $this->source->label(),
|
||||||
|
'language' => $this->language,
|
||||||
|
'slide_count' => $this->slide_count,
|
||||||
|
'template' => $this->template ? [
|
||||||
|
'title' => $this->template->title,
|
||||||
|
'slug' => $this->template->slug,
|
||||||
|
] : null,
|
||||||
|
'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')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
45
app/Http/Resources/UserResource.php
Normal file
45
app/Http/Resources/UserResource.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
|
#[OA\Schema(
|
||||||
|
schema: 'User',
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'id', type: 'integer', example: 1),
|
||||||
|
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: 'avatar_url', type: 'string', example: 'https://example.com/storage/avatars/1.png', nullable: true),
|
||||||
|
new OA\Property(property: 'is_public', type: 'boolean', example: false),
|
||||||
|
new OA\Property(property: 'social_links', type: 'object', example: ['instagram' => 'https://instagram.com/handle'], nullable: true),
|
||||||
|
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
/** @mixin User */
|
||||||
|
class UserResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'name' => $this->name,
|
||||||
|
'username' => $this->username,
|
||||||
|
'email' => $this->email,
|
||||||
|
'mobile' => $this->mobile,
|
||||||
|
'avatar_url' => $this->avatar_path ? Storage::disk('public')->url($this->avatar_path) : null,
|
||||||
|
'is_public' => $this->is_public,
|
||||||
|
'social_links' => $this->social_links ?: null,
|
||||||
|
'created_at' => $this->created_at?->toIso8601String(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
38
app/Http/Resources/WalletDepositResource.php
Normal file
38
app/Http/Resources/WalletDepositResource.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use App\Models\WalletDeposit;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use OpenApi\Attributes as OA;
|
||||||
|
|
||||||
|
#[OA\Schema(
|
||||||
|
schema: 'WalletDeposit',
|
||||||
|
properties: [
|
||||||
|
new OA\Property(property: 'id', type: 'integer', example: 1),
|
||||||
|
new OA\Property(property: 'amount', type: 'integer', example: 500000),
|
||||||
|
new OA\Property(property: 'status', type: 'string', example: 'pending'),
|
||||||
|
new OA\Property(property: 'status_label', type: 'string', example: 'در انتظار پرداخت'),
|
||||||
|
new OA\Property(property: 'gateway', type: 'string', example: 'fake'),
|
||||||
|
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||||
|
]
|
||||||
|
)]
|
||||||
|
/** @mixin WalletDeposit */
|
||||||
|
class WalletDepositResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'amount' => $this->amount,
|
||||||
|
'status' => $this->status->value,
|
||||||
|
'status_label' => $this->status->label(),
|
||||||
|
'gateway' => $this->gateway,
|
||||||
|
'created_at' => $this->created_at?->toIso8601String(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
65
app/Jobs/GenerateTemplateJob.php
Normal file
65
app/Jobs/GenerateTemplateJob.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Enums\TemplateGenerationSource;
|
||||||
|
use App\Enums\TemplateGenerationStatus;
|
||||||
|
use App\Models\AiProvider;
|
||||||
|
use App\Models\TemplateGeneration;
|
||||||
|
use App\Services\Ai\OpenAiCompatibleTextGenerator;
|
||||||
|
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 RuntimeException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class GenerateTemplateJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public function __construct(private readonly TemplateGeneration $generation) {}
|
||||||
|
|
||||||
|
public function handle(TemplateFillService $templateFillService, OpenAiCompatibleTextGenerator $outlineGenerator): void
|
||||||
|
{
|
||||||
|
$this->generation->update(['status' => TemplateGenerationStatus::Processing]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$outputPath = $this->generation->source === TemplateGenerationSource::AiText
|
||||||
|
? $this->fillFromAiText($templateFillService, $outlineGenerator)
|
||||||
|
: $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(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fillFromAiText(TemplateFillService $templateFillService, OpenAiCompatibleTextGenerator $outlineGenerator): string
|
||||||
|
{
|
||||||
|
$provider = AiProvider::resolveActiveDefault();
|
||||||
|
|
||||||
|
if (! $provider) {
|
||||||
|
throw new RuntimeException('هیچ سرویس هوش مصنوعی فعالی تنظیم نشده است.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$outline = $outlineGenerator->generateOutline(
|
||||||
|
$this->generation->template,
|
||||||
|
(string) $this->generation->title,
|
||||||
|
(string) $this->generation->source_text,
|
||||||
|
(int) $this->generation->slide_count,
|
||||||
|
(string) $this->generation->language,
|
||||||
|
$provider,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $templateFillService->fillAiGeneration($this->generation, $outline);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/Models/AiProvider.php
Normal file
39
app/Models/AiProvider.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\AiProviderDriver;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
#[Fillable(['name', 'driver', 'model', 'base_url', 'api_key', 'is_active', 'is_default'])]
|
||||||
|
#[Hidden(['api_key'])]
|
||||||
|
class AiProvider extends Model
|
||||||
|
{
|
||||||
|
public static function resolveActiveDefault(): ?self
|
||||||
|
{
|
||||||
|
return static::query()
|
||||||
|
->where('is_active', true)
|
||||||
|
->orderByDesc('is_default')
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolvedBaseUrl(): string
|
||||||
|
{
|
||||||
|
return $this->base_url ?: $this->driver->defaultBaseUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'driver' => AiProviderDriver::class,
|
||||||
|
'api_key' => 'encrypted',
|
||||||
|
'is_active' => 'boolean',
|
||||||
|
'is_default' => 'boolean',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
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',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Models/NotificationPreference.php
Normal file
42
app/Models/NotificationPreference.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
#[Fillable([
|
||||||
|
'user_id',
|
||||||
|
'comment_on_presentation',
|
||||||
|
'form_reply',
|
||||||
|
'new_follower',
|
||||||
|
'news_announcements',
|
||||||
|
'weekly_product_updates',
|
||||||
|
'weekly_blog_digest',
|
||||||
|
])]
|
||||||
|
class NotificationPreference extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<User, $this>
|
||||||
|
*/
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'comment_on_presentation' => 'boolean',
|
||||||
|
'form_reply' => 'boolean',
|
||||||
|
'new_follower' => 'boolean',
|
||||||
|
'news_announcements' => 'boolean',
|
||||||
|
'weekly_product_updates' => 'boolean',
|
||||||
|
'weekly_blog_digest' => 'boolean',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
70
app/Models/Template.php
Normal file
70
app/Models/Template.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?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;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
#[Fillable([
|
||||||
|
'category_id',
|
||||||
|
'title',
|
||||||
|
'slug',
|
||||||
|
'description',
|
||||||
|
'file_path',
|
||||||
|
'thumbnail_path',
|
||||||
|
'is_active',
|
||||||
|
'is_ai_enabled',
|
||||||
|
'ai_repeatable_slide_number',
|
||||||
|
'created_by',
|
||||||
|
])]
|
||||||
|
class Template extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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',
|
||||||
|
'is_ai_enabled' => 'boolean',
|
||||||
|
'ai_repeatable_slide_number' => 'integer',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user