Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-server
Commits
5a904643
Commit
5a904643
authored
Nov 02, 2020
by
François Agneray
Browse files
Add user list endpoint (list all users)
parent
75d13d23
Changes
3
Show whitespace changes
Inline
Side-by-side
app/dependencies.php
View file @
5a904643
...
...
@@ -76,6 +76,10 @@ $container->set('App\Action\ProjectAction', function (ContainerInterface $c) {
return
new
App\Action\ProjectAction
(
$c
->
get
(
'em'
));
});
$container
->
set
(
'App\Action\UserListAction'
,
function
(
ContainerInterface
$c
)
{
return
new
App\Action\UserListAction
(
$c
->
get
(
'em'
));
});
$container
->
set
(
'App\Action\GroupListAction'
,
function
(
ContainerInterface
$c
)
{
return
new
App\Action\GroupListAction
(
$c
->
get
(
'em'
));
});
...
...
app/routes.php
View file @
5a904643
...
...
@@ -18,6 +18,7 @@ $app->map([OPTIONS, GET, PUT, DELETE], '/database/{id}', App\Action\DatabaseActi
$app
->
map
([
OPTIONS
,
GET
],
'/database/{id}/table'
,
App\Action\TableListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
POST
],
'/project'
,
App\Action\ProjectListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
PUT
,
DELETE
],
'/project/{name}'
,
App\Action\ProjectAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
],
'/user'
,
App\Action\UserListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
POST
],
'/group'
,
App\Action\GroupListAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
POST
],
'/group/{id}'
,
App\Action\GroupAction
::
class
);
$app
->
map
([
OPTIONS
,
GET
,
POST
],
'/instance'
,
App\Action\InstanceListAction
::
class
);
...
...
src/Action/UserListAction.php
0 → 100644
View file @
5a904643
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare
(
strict_types
=
1
);
namespace
App\Action
;
use
Psr\Http\Message\ServerRequestInterface
as
Request
;
use
Psr\Http\Message\ResponseInterface
as
Response
;
use
Slim\Exception\HttpBadRequestException
;
use
App\Entity\User
;
final
class
UserListAction
extends
AbstractAction
{
/**
* `GET` Returns a list of all users listed in the metamodel
*
* @param ServerRequestInterface $request PSR-7 This object represents the HTTP request
* @param ResponseInterface $response PSR-7 This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public
function
__invoke
(
Request
$request
,
Response
$response
,
array
$args
):
Response
{
if
(
$request
->
getMethod
()
===
OPTIONS
)
{
return
$response
->
withHeader
(
'Access-Control-Allow-Methods'
,
'GET, OPTIONS'
);
}
if
(
$request
->
getMethod
()
===
GET
)
{
$users
=
$this
->
em
->
getRepository
(
'App\Entity\User'
)
->
findAll
();
$payload
=
json_encode
(
$users
);
}
$response
->
getBody
()
->
write
(
$payload
);
return
$response
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment