- 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
This commit is contained in:
65
app/Http/Controllers/SynonymController.php
Normal file
65
app/Http/Controllers/SynonymController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user