115 lines
2.9 KiB
PHP
115 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Resources\LogResource;
|
|
use App\Models\Log;
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class LogController extends Controller
|
|
{
|
|
private const PAGINATED_COUNT = 20;
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/logs",
|
|
* summary="Get all logs (paginated, only admin)",
|
|
* tags={"Logs"},
|
|
* security={{"bearerAuth": {}}},
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="List of logs",
|
|
* @OA\JsonContent(
|
|
* type="array",
|
|
* @OA\Items(ref="#/components/schemas/LogResource")
|
|
* )
|
|
* ),
|
|
* @OA\Response(
|
|
* response=403,
|
|
* description="Forbidden"
|
|
* )
|
|
* )
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->authorize('viewAny', Log::class);
|
|
return LogResource::collection(Log::paginate());
|
|
}
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/logs/{id}",
|
|
* summary="Get a specific log (only admin)",
|
|
* tags={"Logs"},
|
|
* security={{"bearerAuth": {}}},
|
|
* @OA\Parameter(
|
|
* name="id",
|
|
* in="path",
|
|
* required=true,
|
|
* description="ID of the log",
|
|
* @OA\Schema(type="integer", example=1)
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="Log retrieved successfully",
|
|
* @OA\JsonContent(ref="#/components/schemas/LogResource")
|
|
* ),
|
|
* @OA\Response(
|
|
* response=403,
|
|
* description="Forbidden"
|
|
* ),
|
|
* @OA\Response(
|
|
* response=404,
|
|
* description="Log not found"
|
|
* )
|
|
* )
|
|
*/
|
|
public function show(Log $log)
|
|
{
|
|
$this->authorize('view', $log);
|
|
return $log;
|
|
}
|
|
|
|
/**
|
|
* @OA\Delete(
|
|
* path="/api/logs/{id}",
|
|
* summary="Delete a specific log (only admin)",
|
|
* tags={"Logs"},
|
|
* security={{"bearerAuth": {}}},
|
|
* @OA\Parameter(
|
|
* name="id",
|
|
* in="path",
|
|
* required=true,
|
|
* description="ID of the log",
|
|
* @OA\Schema(type="integer", example=1)
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="Log deleted successfully",
|
|
* @OA\JsonContent(
|
|
* @OA\Property(property="message", type="string", example="This log is successfully deleted")
|
|
* )
|
|
* ),
|
|
* @OA\Response(
|
|
* response=403,
|
|
* description="Forbidden"
|
|
* ),
|
|
* @OA\Response(
|
|
* response=404,
|
|
* description="Log not found"
|
|
* )
|
|
* )
|
|
*/
|
|
public function destroy(Log $log)
|
|
{
|
|
$this->authorize('delete', $log);
|
|
|
|
$log->delete();
|
|
return response()->json([
|
|
'message' => 'This log is successfully deleted'
|
|
]);
|
|
}
|
|
}
|