Manage calls and the inbox through the API
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
58
app/Http/Requests/Api/V1/CallRequest.php
Normal file
58
app/Http/Requests/Api/V1/CallRequest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Api\V1;
|
||||
|
||||
use App\Enums\CallStatus;
|
||||
use App\Models\Call;
|
||||
use App\Rules\Translatable;
|
||||
use App\Rules\UniqueTranslatedSlug;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* The panel's call form, as rules. `technology_ids` is replaced whole when
|
||||
* sent.
|
||||
*/
|
||||
class CallRequest extends FormRequest
|
||||
{
|
||||
public const SENIORITIES = ['any', 'junior', 'mid', 'senior'];
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$call = $this->route('call');
|
||||
$creating = ! $call instanceof Call;
|
||||
$sometimes = $creating ? 'required' : 'sometimes';
|
||||
|
||||
return [
|
||||
'title' => [$sometimes, new Translatable(requireDefaultLocale: $creating, max: 255)],
|
||||
'slug' => [
|
||||
$sometimes,
|
||||
new Translatable(requireDefaultLocale: $creating, max: 255),
|
||||
new UniqueTranslatedSlug(Call::class, $call?->id),
|
||||
],
|
||||
'description' => ['sometimes', 'nullable', new Translatable],
|
||||
'what_you_get' => ['sometimes', 'nullable', new Translatable],
|
||||
|
||||
'status' => ['sometimes', Rule::enum(CallStatus::class)],
|
||||
'hours_per_week' => ['sometimes', 'nullable', 'integer', 'min:1', 'max:40'],
|
||||
'duration_weeks' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
||||
'seniority' => ['sometimes', 'nullable', Rule::in(self::SENIORITIES)],
|
||||
'opens_at' => ['sometimes', 'nullable', 'date'],
|
||||
'closes_at' => ['sometimes', 'nullable', 'date', 'after_or_equal:opens_at'],
|
||||
|
||||
'project_id' => ['sometimes', 'nullable', 'integer', Rule::exists('projects', 'id')->whereNull('deleted_at')],
|
||||
'technology_ids' => ['sometimes', 'array'],
|
||||
'technology_ids.*' => ['integer', 'distinct', Rule::exists('technologies', 'id')],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user