license: built full stack, test and documentation
This commit is contained in:
33
backend/app/Http/Requests/IndexLicenseRequest.php
Normal file
33
backend/app/Http/Requests/IndexLicenseRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class IndexLicenseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Rotta pubblica: l'elenco delle licenze è informazione pubblica.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* `scope` filtra le select dei form: `record` per artifact/model (solo
|
||||
* licenze aperte), `media` per i file caricati (tutte). `active` esclude
|
||||
* le licenze ritirate dagli admin.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'scope' => ['nullable', Rule::in(['record', 'media'])],
|
||||
'active' => ['nullable', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
41
backend/app/Http/Requests/StoreLicenseRequest.php
Normal file
41
backend/app/Http/Requests/StoreLicenseRequest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\LicenseKind;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreLicenseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* L'autorizzazione (solo Admin) è gestita dal middleware di rotta.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:200', 'unique:licenses,name'],
|
||||
'acronym' => ['required', 'string', 'max:50', 'unique:licenses,acronym'],
|
||||
// Solo id della SPDX License List ufficiale: per marchi e rights
|
||||
// statement (che non vi compaiono) deve restare NULL.
|
||||
'spdx_id' => ['nullable', 'string', 'max:50', 'unique:licenses,spdx_id'],
|
||||
'kind' => ['required', Rule::enum(LicenseKind::class)],
|
||||
'description' => ['nullable', 'string'],
|
||||
'uri' => ['nullable', 'url', 'max:2000'],
|
||||
'file' => ['nullable', 'string', 'max:512'],
|
||||
'for_record' => ['sometimes', 'boolean'],
|
||||
'for_media' => ['sometimes', 'boolean'],
|
||||
'sort_order' => ['sometimes', 'integer', 'min:0'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
43
backend/app/Http/Requests/UpdateLicenseRequest.php
Normal file
43
backend/app/Http/Requests/UpdateLicenseRequest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\LicenseKind;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateLicenseRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* L'autorizzazione (solo Admin) è gestita dal middleware di rotta.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiornamento parziale: ogni campo è validato solo se presente.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$id = $this->route('license')->id;
|
||||
|
||||
return [
|
||||
'name' => ['sometimes', 'required', 'string', 'max:200', Rule::unique('licenses', 'name')->ignore($id)],
|
||||
'acronym' => ['sometimes', 'required', 'string', 'max:50', Rule::unique('licenses', 'acronym')->ignore($id)],
|
||||
'spdx_id' => ['nullable', 'string', 'max:50', Rule::unique('licenses', 'spdx_id')->ignore($id)],
|
||||
'kind' => ['sometimes', 'required', Rule::enum(LicenseKind::class)],
|
||||
'description' => ['nullable', 'string'],
|
||||
'uri' => ['nullable', 'url', 'max:2000'],
|
||||
'file' => ['nullable', 'string', 'max:512'],
|
||||
'for_record' => ['sometimes', 'boolean'],
|
||||
'for_media' => ['sometimes', 'boolean'],
|
||||
'sort_order' => ['sometimes', 'integer', 'min:0'],
|
||||
'active' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user