feature test su institution
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreInstitutionCategoryRequest;
|
||||
use App\Http\Requests\UpdateInstitutionCategoryRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Lists\InstitutionCategory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* CRUD del lookup categorie di istituzione (scrittura riservata agli Admin).
|
||||
*
|
||||
* NB gli id 2/3/4/6 sono allineati al legacy e usati dall'ETL: cancellarne uno
|
||||
* in uso è bloccato (409). Nessun soft delete su questo lookup.
|
||||
*/
|
||||
class InstitutionCategoryController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
/**
|
||||
* Elenco delle categorie.
|
||||
*/
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
return $this->collectionResponse(InstitutionCategory::orderBy('value')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Crea una categoria.
|
||||
*/
|
||||
public function store(StoreInstitutionCategoryRequest $request): JsonResponse
|
||||
{
|
||||
$category = InstitutionCategory::create($request->validated());
|
||||
|
||||
return $this->createdResponse($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dettaglio di una categoria.
|
||||
*/
|
||||
public function show(InstitutionCategory $institutionCategory): JsonResponse
|
||||
{
|
||||
return $this->okResponse($institutionCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiorna una categoria.
|
||||
*/
|
||||
public function update(UpdateInstitutionCategoryRequest $request, InstitutionCategory $institutionCategory): JsonResponse
|
||||
{
|
||||
$institutionCategory->update($request->validated());
|
||||
|
||||
return $this->updatedResponse($institutionCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina una categoria (se non assegnata ad alcuna istituzione).
|
||||
*/
|
||||
public function destroy(InstitutionCategory $institutionCategory): JsonResponse
|
||||
{
|
||||
if ($institutionCategory->isInUse()) {
|
||||
return $this->conflictResponse('Cannot delete: category assigned to at least one institution.');
|
||||
}
|
||||
|
||||
$institutionCategory->delete();
|
||||
|
||||
return $this->deletedResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indica se la categoria è in uso (bloccata per l'eliminazione).
|
||||
*/
|
||||
public function usage(InstitutionCategory $institutionCategory): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'in_use' => $institutionCategory->isInUse(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user