Permalink
Browse files

Adds list endpoint, w/ tests and swagger defaults

  • Loading branch information...
jacobemerick committed Jan 26, 2019
1 parent eef513c commit 7ed34afa604dae4663e1547e18d0c4ad9c780c0a
Showing with 499 additions and 3 deletions.
  1. +3 −0 bootstrap.php
  2. +56 −1 src/Controller/Event.php
  3. +3 −0 swagger.json
  4. +437 −2 tests/unit/Controller/EventTest.php
@@ -90,6 +90,9 @@
$talus->addController('getEvent', function ($req, $res) use ($di) {
return (new Controller\Event($di))->getEvent($req, $res);
});
$talus->addController('getEvents', function ($req, $res) use ($di) {
return (new Controller\Event($di))->getEvents($req, $res);
});
$talus->addController('getTypes', function ($req, $res) use ($di) {
return (new Controller\Type($di))->getTypes($req, $res);
@@ -42,5 +42,60 @@ public function getEvent(Request $request, Response $response)
return $response;
}
public function getEvents() {}
/**
* @param Request $request
* @param Response $response
* @return Response
*/
public function getEvents(Request $request, Response $response)
{
$limit = 0;
$offset = 0;
$user = '';
$type = '';
$order = '';
$isAscending = true;
$query = $request->getAttribute('swagger')->getParams();
if (array_key_exists('per_page', $query)) {
$limit = $query['per_page']['value'];
}
if (array_key_exists('page', $query)) {
$offset = ($query['page']['value'] - 1) * $limit;
}
if (array_key_exists('user', $query)) {
$user = $query['user']['value'];
}
if (array_key_exists('type', $query)) {
$type = $query['type']['value'];
}
if (array_key_exists('sort', $query)) {
$order = $query['sort']['value'];
if (substr($order, 0, 1) == '-') {
$isAscending = false;
$order = substr($order, 1);
}
}
$events = $this->container
->get('eventModel')
->getEvents(
$limit,
$offset,
$type,
$user,
$order,
$isAscending
);
$events = array_map(
$this->container->get('eventSerializer'),
$events
);
$events = json_encode($events);
$response->getBody()->write($events);
return $response;
}
}
@@ -177,18 +177,21 @@
"name": "page",
"in": "query",
"description": "Results page to return",
"default": 1,
"type": "integer"
},
"PageSize": {
"name": "per_page",
"in": "query",
"description": "Results per response",
"default": 10,
"type": "integer"
},
"SortOrder": {
"name": "order",
"in": "query",
"description": "Comma-separated list of order options",
"default": "date",
"type": "string"
},
"TypeFilter": {
Oops, something went wrong.

0 comments on commit 7ed34af

Please sign in to comment.