feature test su institution
This commit is contained in:
69
backend/app/Http/Controllers/InstitutionLinkController.php
Normal file
69
backend/app/Http/Controllers/InstitutionLinkController.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreInstitutionLinkRequest;
|
||||
use App\Http\Requests\UpdateInstitutionLinkRequest;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Institution;
|
||||
use App\Models\InstitutionLink;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* Risorse web di un'istituzione (sito ufficiale, ticketing, social, ...).
|
||||
*
|
||||
* Risorsa annidata e scoped sotto `institutions/{institution}`: il link deve
|
||||
* appartenere all'istituzione del path. Nessun soft delete (solo Institution lo ha).
|
||||
*/
|
||||
class InstitutionLinkController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
/**
|
||||
* Elenco dei link di un'istituzione, ordinati.
|
||||
*/
|
||||
public function index(Institution $institution): JsonResponse
|
||||
{
|
||||
$links = $institution->links()->orderBy('sort_order')->get();
|
||||
|
||||
return $this->collectionResponse($links);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiunge un link all'istituzione.
|
||||
*/
|
||||
public function store(StoreInstitutionLinkRequest $request, Institution $institution): JsonResponse
|
||||
{
|
||||
$link = $institution->links()->create($request->validated());
|
||||
|
||||
return $this->createdResponse($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dettaglio di un link.
|
||||
*/
|
||||
public function show(Institution $institution, InstitutionLink $link): JsonResponse
|
||||
{
|
||||
return $this->okResponse($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggiorna un link.
|
||||
*/
|
||||
public function update(UpdateInstitutionLinkRequest $request, Institution $institution, InstitutionLink $link): JsonResponse
|
||||
{
|
||||
$link->update($request->validated());
|
||||
|
||||
return $this->updatedResponse($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina un link.
|
||||
*/
|
||||
public function destroy(Institution $institution, InstitutionLink $link): JsonResponse
|
||||
{
|
||||
$link->delete();
|
||||
|
||||
return $this->deletedResponse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user