Skip to content

Commit

Permalink
Merge pull request #193 from dbarzin/dev
Browse files Browse the repository at this point in the history
Add /api/users
  • Loading branch information
dbarzin authored Oct 17, 2024
2 parents 4eab6e4 + b6255f9 commit bf6f0e3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
55 changes: 55 additions & 0 deletions app/Http/Controllers/API/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;

class UserController extends Controller
{
public function index()
{
abort_if(Auth::User()->role !== 4, Response::HTTP_FORBIDDEN, '403 Forbidden');

$users = User::all();

return response()->json($users);
}

public function store(Request $request)
{
abort_if(Auth::User()->role !== 4, Response::HTTP_FORBIDDEN, '403 Forbidden');

$user = Document::create($user->all());

return response()->json($user, 201);
}

public function show(User $user)
{
abort_if(Auth::User()->role !== 4, Response::HTTP_FORBIDDEN, '403 Forbidden');

return response()->json($user);
}

public function update(Request $request, User $user)
{
abort_if(Auth::User()->role !== 4, Response::HTTP_FORBIDDEN, '403 Forbidden');

$user->update($request->all());

return response()->json();
}

public function destroy(User $user)
{
abort_if(Auth::User()->role !== 4, Response::HTTP_FORBIDDEN, '403 Forbidden');

$user->delete();

return response()->json();
}
}
1 change: 1 addition & 0 deletions app/Models/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Control extends Model
'action_plan',
'realisation_date',
'plan_date',
'periodicity'
];

// Control status :
Expand Down
1 change: 1 addition & 0 deletions app/Models/Measure.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Measure extends Model
'input',
'attributes',
'model',
'periodicity'
];

// Return the domain associated to this measure
Expand Down
2 changes: 2 additions & 0 deletions docs/api.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ L'environnement Docker prend en charge cette fonctionnalité nativement, via l'[

- /api/controls

- /api/users

- /api/documents

### Actions gérées par le contrôleur de ressources
Expand Down
2 changes: 2 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ The Docker environment supports this functionality natively, via the [entrypoint

- /api/controls

- /api/users

- /api/documents

### Actions managed by the resource controller
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
Route::apiResource('controls', ControlController::class);
Route::apiResource('attributes', AttributeController::class);
Route::apiResource('documents', DocumentController::class);
Route::apiResource('users', UserController::class);
});
});

0 comments on commit bf6f0e3

Please sign in to comment.