feat: add ApiResponse trait for standardized API responses
chore: update composer dependencies to include phppresentation chore: update composer.lock after adding phppresentation feat: create categories migration for category management feat: create templates migration for template storage feat: create template generations migration for tracking template usage feat: create template keys migration for template customization feat: create notifications migration for user notifications feat: update API routes for categories, templates, and user profile management docs: update API documentation to include new endpoints for profile and wallet
This commit is contained in:
50
app/Http/Requests/Api/GenerateTemplateRequest.php
Normal file
50
app/Http/Requests/Api/GenerateTemplateRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api;
|
||||
|
||||
use App\Enums\TemplateKeyType;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class GenerateTemplateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
/** @var Template $template */
|
||||
$template = $this->route('template');
|
||||
|
||||
$rules = [];
|
||||
|
||||
foreach ($template->keys as $key) {
|
||||
$fieldRules = [$key->is_required ? 'required' : 'nullable'];
|
||||
|
||||
$fieldRules[] = match ($key->type) {
|
||||
TemplateKeyType::Text => 'string',
|
||||
TemplateKeyType::Image => 'file|image',
|
||||
TemplateKeyType::Chart => 'prohibited',
|
||||
};
|
||||
|
||||
$rules['values.'.$key->key] = $fieldRules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'*.prohibited' => 'کلید :attribute از نوع چارت است و فعلاً پشتیبانی نمیشود.',
|
||||
];
|
||||
}
|
||||
}
|
||||
50
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal file
50
app/Http/Requests/Profile/UpdateProfileRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Profile;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateProfileRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$userId = $this->user()->id;
|
||||
|
||||
return [
|
||||
'name' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
'username' => ['sometimes', 'required', 'string', 'max:255', Rule::unique('users', 'username')->ignore($userId)],
|
||||
'email' => ['sometimes', 'required', 'string', 'email', 'max:255', Rule::unique('users', 'email')->ignore($userId)],
|
||||
'mobile' => ['sometimes', 'required', 'string', 'regex:/^09\d{9}$/', Rule::unique('users', 'mobile')->ignore($userId)],
|
||||
'password' => ['sometimes', 'required', 'string', 'min:8'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => 'نام و نام خانوادگی الزامی است.',
|
||||
'username.required' => 'نام کاربری الزامی است.',
|
||||
'username.unique' => 'این نام کاربری قبلاً استفاده شده است.',
|
||||
'email.required' => 'ایمیل الزامی است.',
|
||||
'email.email' => 'فرمت ایمیل صحیح نیست.',
|
||||
'email.unique' => 'این ایمیل قبلاً ثبت شده است.',
|
||||
'mobile.required' => 'شماره موبایل الزامی است.',
|
||||
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست.',
|
||||
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
|
||||
'password.required' => 'رمز عبور الزامی است.',
|
||||
'password.min' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user