Test API Endpoint for users

This commit is contained in:
Jascha Sticher 2021-05-05 13:46:14 +02:00
parent 95798a2eba
commit 07626669da
3 changed files with 52 additions and 0 deletions

View File

@ -61,6 +61,14 @@ class UserRepo
return User::query()->with('roles', 'avatar')->orderBy('name', 'asc')->get();
}
/**
* Get all users as Builder for API
*/
public function getUsersBuilder(): Builder
{
$query = User::query()->select(['*']);
return $query;
}
/**
* Get all the users with their permissions in a paginated format.
*/

View File

@ -0,0 +1,42 @@
<?php
namespace BookStack\Http\Controllers\Api;
use BookStack\Exceptions\PermissionsException;
use BookStack\Auth\User;
use BookStack\Auth\UserRepo;
use Exception;
use Illuminate\Http\Request;
class UserApiController extends ApiController
{
protected $user;
protected $userRepo;
# TBD: Endpoints to create / update users
# protected $rules = [
# 'create' => [
# ],
# 'update' => [
# ],
# ];
public function __construct(User $user, UserRepo $userRepo)
{
$this->user = $user;
$this->userRepo = $userRepo;
}
/**
* Get a listing of pages visible to the user.
*/
public function list()
{
$users = $this->userRepo->getUsersBuilder();
return $this->apiListingResponse($users, [
'id', 'name', 'slug',
'email', 'created_at', 'updated_at',
]);
}
}

View File

@ -44,3 +44,5 @@ Route::post('shelves', 'BookshelfApiController@create');
Route::get('shelves/{id}', 'BookshelfApiController@read');
Route::put('shelves/{id}', 'BookshelfApiController@update');
Route::delete('shelves/{id}', 'BookshelfApiController@delete');
Route::get('users', 'UserApiController@list');