82 lines
1.9 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Http\Controllers\Api\Common;
use App\Abstracts\Http\ApiController;
use App\Http\Requests\Common\Report as Request;
2022-06-01 10:15:55 +03:00
use App\Http\Resources\Common\Report as Resource;
2019-11-16 10:21:14 +03:00
use App\Jobs\Common\CreateReport;
use App\Jobs\Common\DeleteReport;
use App\Jobs\Common\UpdateReport;
use App\Models\Common\Report;
class Reports extends ApiController
{
/**
* Display a listing of the resource.
*
2022-06-01 10:15:55 +03:00
* @return \Illuminate\Http\JsonResponse
2019-11-16 10:21:14 +03:00
*/
public function index()
{
$reports = Report::collect();
2022-06-01 10:15:55 +03:00
return Resource::collection($reports);
2019-11-16 10:21:14 +03:00
}
/**
* Display the specified resource.
*
* @param Report $report
2022-06-01 10:15:55 +03:00
* @return \Illuminate\Http\JsonResponse
2019-11-16 10:21:14 +03:00
*/
public function show(Report $report)
{
2022-06-01 10:15:55 +03:00
return new Resource($report);
2019-11-16 10:21:14 +03:00
}
/**
* Store a newly created resource in storage.
*
* @param $request
2022-06-01 10:15:55 +03:00
* @return \Illuminate\Http\JsonResponse
2019-11-16 10:21:14 +03:00
*/
public function store(Request $request)
{
$report = $this->dispatch(new CreateReport($request));
2022-06-01 10:15:55 +03:00
return $this->created(route('api.reports.show', $report->id), new Resource($report));
2019-11-16 10:21:14 +03:00
}
/**
* Update the specified resource in storage.
*
* @param $report
* @param $request
2022-06-01 10:15:55 +03:00
* @return \Illuminate\Http\JsonResponse
2019-11-16 10:21:14 +03:00
*/
public function update(Report $report, Request $request)
{
$report = $this->dispatch(new UpdateReport($report, $request));
2022-06-01 10:15:55 +03:00
return new Resource($report->fresh());
2019-11-16 10:21:14 +03:00
}
/**
* Remove the specified resource from storage.
*
* @param Report $report
2022-06-01 10:15:55 +03:00
* @return \Illuminate\Http\Response
2019-11-16 10:21:14 +03:00
*/
public function destroy(Report $report)
{
try {
$this->dispatch(new DeleteReport($report));
2022-06-01 10:15:55 +03:00
return $this->noContent();
2019-11-16 10:21:14 +03:00
} catch(\Exception $e) {
2022-06-01 10:15:55 +03:00
$this->errorUnauthorized($e->getMessage());
2019-11-16 10:21:14 +03:00
}
}
}