Some checks failed
continuous-integration/drone/push Build is failing
- Complete GGZ Ecademy Laravel backend application - RESTful API for learning products, members, filters - Authentication and authorization system - Database migrations and seeders - Custom CRUD generator commands - Email notification system - Integration with frontend applications
66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\SynonymService;
|
|
use App\Http\Requests\Learning\SynonymStore;
|
|
|
|
class SynonymController extends Controller
|
|
{
|
|
|
|
private $synonymService;
|
|
|
|
public function __construct(SynonymService $synonymService)
|
|
{
|
|
$this->synonymService = $synonymService;
|
|
$this->middleware('auth:sanctum', [
|
|
'except' => [
|
|
'index',
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$synonyms = $this->synonymService->getAll();
|
|
|
|
return response()->json($synonyms, 201);
|
|
}
|
|
|
|
public function store(SynonymStore $request)
|
|
{
|
|
$isSuperAdmin = auth()->user()->hasRole('super_admin');
|
|
$isAdmin = auth()->user()->hasRole('admin');
|
|
$isOperator = auth()->user()->hasRole('operator');
|
|
|
|
if (!$isSuperAdmin && !$isAdmin && !$isOperator) {
|
|
return response()->json(['message' => 'You have no rights to do this'], 401);
|
|
}
|
|
|
|
$synonym = $this->synonymService->save($request->all());
|
|
|
|
return response()->json($synonym, 201);
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$synonym = $this->synonymService->get($id);
|
|
|
|
return response()->json($synonym);
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$isSuperAdmin = auth()->user()->hasRole('super_admin');
|
|
$isAdmin = auth()->user()->hasRole('admin');
|
|
$isOperator = auth()->user()->hasRole('operator');
|
|
|
|
if (!$isSuperAdmin && !$isAdmin && !$isOperator) {
|
|
return response()->json(['message' => 'You have no rights to do this'], 401);
|
|
}
|
|
|
|
$this->synonymService->delete($id);
|
|
return response()->json(null, 204);
|
|
}
|
|
}
|