File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/MinuteBookController.php
Back
<?php namespace App\Http\Controllers; use App\Rules\ArrayInput; use App\Models\MinuteBook; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use App\Http\Requests\MinuteBookRequest; use App\Http\Services\MinuteBookService; use Carbon\Carbon; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Validator; class MinuteBookController extends Controller { private MinuteBookService $minuteBookService; public function __construct() { $this->minuteBookService = new MinuteBookService(); // $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/minute-book", * summary="Get a list of all items", * description="Get a list of all items", * operationId="GetAllMinuteBooks", * security={{"bearerAuth":{}}}, * tags={"Minute Book"}, * @OA\Parameter( * name="date", * in="query", * description="Filtrar por data", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="type", * in="query", * description="Filtrar por tipo: ocorrência, abrigo, BDT, entrada_manual", * required=false, * @OA\Schema(type="string") * ), * @OA\Response( * response="200", * description="OK", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * ) */ public function index(Request $request): JsonResponse { return $this->response($this->minuteBookService->index($request)); } /** * @OA\Post( * path="/api/minute-book", * summary="Add a new item", * description="Add a new item", * operationId="AddNewMinuteBook", * security={{"bearerAuth":{}}}, * tags={"Minute Book"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"title", "description", "date"}, * @OA\Property( * property="title", * type="string", * description="Título" * ), * @OA\Property( * property="description", * type="string", * example="Descrição", * description="Descrição" * ), * @OA\Property( * property="date", * type="string", * example="2024-01-01", * description="Data" * ), * ) * ), * ), * @OA\Response( * response="201", * description="Created", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function store(MinuteBookRequest $request): JsonResponse { return $this->response($this->minuteBookService->store($request)); } /** * @OA\Get( * path="/api/minute-book/{minute_book_id}", * summary="Get details from a item", * description="Get details from a item", * operationId="GetMinuteBookDetails", * security={{"bearerAuth":{}}}, * tags={"Minute Book"}, * @OA\Parameter( * name="minute_book_id", * in="path", * required=true, * description="MinuteBook ID", * @OA\Schema(type="string") * ), * @OA\Response( * response="200", * description="OK", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="404", * description="Not found", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Not found."), * ) * ), * ) */ public function show(Request $request, MinuteBook $minuteBook): JsonResponse { return $this->response($this->minuteBookService->show($request, $minuteBook)); } /** * @OA\Put( * path="/api/minute-book/{minute_book_id}", * summary="Update a item", * description="Update a item", * operationId="UpdateMinuteBook", * security={{"bearerAuth":{}}}, * tags={"Minute Book"}, * @OA\Parameter( * name="minute_book_id", * in="path", * required=true, * description="MinuteBook ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"title", "description", "date"}, * @OA\Property( * property="title", * type="string", * description="Título" * ), * @OA\Property( * property="description", * type="string", * example="Descrição", * description="Descrição" * ), * @OA\Property( * property="date", * type="string", * example="2024-01-01", * description="Data" * ), * ) * ), * ), * @OA\Response( * response="201", * description="OK", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function update(MinuteBookRequest $request, MinuteBook $minuteBook): JsonResponse { return $this->response($this->minuteBookService->update($request, $minuteBook)); } /** * @OA\Delete( * path="/api/minute-book/{minute_book_id}", * summary="Delete a item", * description="Delete a item", * operationId="DeleteMinuteBook", * security={{"bearerAuth":{}}}, * tags={"Minute Book"}, * @OA\Parameter( * name="minute_book_id", * in="path", * required=true, * description="MinuteBook ID", * @OA\Schema(type="string") * ), * @OA\Response( * response="204", * description="No content", * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="404", * description="Not found", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Not found."), * ) * ), * ) */ public function destroy(MinuteBook $minuteBook): JsonResponse { return $this->response($this->minuteBookService->destroy($minuteBook)); } /** * @OA\Post( * path="/api/minute-book/destroy-many", * summary="Delete multiple items", * description="Delete multiple items", * operationId="DeleteManyMinuteBooks", * security={{"bearerAuth":{}}}, * tags={"Minute Book"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"categories"}, * @OA\Property( * property="categories", * type="array", * description="Ids of categories to delete", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * ), * @OA\Response( * response="204", * description="No content", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function destroyMany(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'categories' => ['required', new ArrayInput()], 'categories.*' => ['exists:categories,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->minuteBookService->destroyMany($request)); } /** * @OA\Get( * path="/api/minute-book/livro-ata", * summary="Get aggregated records for a specific date", * description="Retorna dados agregados de múltiplas origens (ocorrências, movimentações, boletins, abrigos, nupdecs, etc.) para a data informada. Caso a data não seja informada, retorna os registros do dia corrente.", * operationId="GetBookOfRecords", * security={{"bearerAuth":{}}}, * tags={"Minute Book"}, * @OA\Parameter( * name="date", * in="query", * description="Data para filtrar os registros (formato: YYYY-MM-DD). Caso não seja informada, é utilizado a data de hoje.", * required=false, * @OA\Schema( * type="string", * format="date" * ) * ), * @OA\Response( * response="200", * description="Successful retrieval of records", * @OA\JsonContent( * @OA\Property(property="ocorrencias_criadas", type="array", @OA\Items(type="object")), * @OA\Property(property="movimentacoes_ocorrencias", type="array", @OA\Items(type="object")), * @OA\Property(property="boletins_transporte", type="array", @OA\Items(type="object")), * @OA\Property(property="abrigo", type="array", @OA\Items(type="object")), * @OA\Property(property="nupedecs", type="array", @OA\Items(type="object")), * @OA\Property(property="nupdecs_activities", type="array", @OA\Items(type="object")), * @OA\Property(property="nupdecs_actuations", type="array", @OA\Items(type="object")), * @OA\Property(property="families", type="array", @OA\Items(type="object")), * @OA\Property(property="transportations", type="array", @OA\Items(type="object")), * @OA\Property(property="questionnaires_donations", type="array", @OA\Items(type="object")), * @OA\Property(property="acontecimentos", type="array", @OA\Items(type="object")) * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized.") * ) * ) * ) */ public function bookOfRecords(Request $request): JsonResponse { $request->validate([ 'date' => 'sometimes|nullable|date_format:Y-m-d', ]); $date = $request->get('date') ?? Carbon::today()->format('Y-m-d'); $cacheKey = 'book_of_records_' . md5($date); $cacheInMinutes = now()->addMinutes(10); //10 minutes $serviceResponse = Cache::remember($cacheKey, $cacheInMinutes, function () use ($date) { return $this->minuteBookService->bookOfRecords($date); }); return $this->response($serviceResponse); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings