Docs
This commit is contained in:
@@ -10,8 +10,23 @@ use Khofmann\Response\Response;
|
||||
use Khofmann\ApiError\ApiError;
|
||||
use Khofmann\Request\Request;
|
||||
|
||||
/**
|
||||
* User image route handlers
|
||||
*/
|
||||
class Image extends Api
|
||||
{
|
||||
/**
|
||||
* Image POST handler
|
||||
*
|
||||
* Set a new user image.
|
||||
*
|
||||
* Returns updated user.
|
||||
*
|
||||
* @param mixed $id User ID
|
||||
*
|
||||
* @throws 404 User not found
|
||||
* @throws 500 Failed to update user image
|
||||
*/
|
||||
public function post($id): void
|
||||
{
|
||||
// Fetch all inputs.
|
||||
@@ -33,6 +48,16 @@ class Image extends Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Image POST handler
|
||||
*
|
||||
* Set a new user image. User is retrieved using the authentication `token`.
|
||||
*
|
||||
* Returns updated user.
|
||||
*
|
||||
* @throws 404 User not found
|
||||
* @throws 500 Failed to update user image
|
||||
*/
|
||||
public function postSelf(): void
|
||||
{
|
||||
// Fetch all inputs.
|
||||
|
||||
@@ -9,8 +9,20 @@ use Khofmann\Response\Response;
|
||||
use Khofmann\ApiError\ApiError;
|
||||
use Khofmann\Input\Input;
|
||||
|
||||
/**
|
||||
* User posts route handlers
|
||||
*/
|
||||
class Posts extends Api
|
||||
{
|
||||
/**
|
||||
* Posts GET handler
|
||||
*
|
||||
* Lists posts for a user. Optional parameters are `l` (limit of returned list), `p` (page, i.e. offset), `s` (sort order).
|
||||
*
|
||||
* Returns list of posts.
|
||||
*
|
||||
* @throws 404 User not found
|
||||
*/
|
||||
public function get($id): void
|
||||
{
|
||||
// Fetch and constrain all parameters.
|
||||
|
||||
@@ -10,8 +10,18 @@ use Khofmann\Response\Response;
|
||||
use Khofmann\ApiError\ApiError;
|
||||
use Khofmann\Request\Request;
|
||||
|
||||
/**
|
||||
* Users route handlers
|
||||
*/
|
||||
class Users extends Api
|
||||
{
|
||||
/**
|
||||
* Users GET handler
|
||||
*
|
||||
* Lists users. Optional parameters are `l` (limit of returned list) and `p` (page, i.e. offset).
|
||||
*
|
||||
* Returns list of users.
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
// Fetch and constrain all parameters.
|
||||
@@ -22,6 +32,17 @@ class Users extends Api
|
||||
Response::json(User::list($page, $limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* User GET handler
|
||||
*
|
||||
* Get a single user.
|
||||
*
|
||||
* Returns user.
|
||||
*
|
||||
* @param mixed $id User ID
|
||||
*
|
||||
* @throws 404 User not found
|
||||
*/
|
||||
public function get($id): void
|
||||
{
|
||||
// Try and get a user, 404 if not found.
|
||||
@@ -37,6 +58,18 @@ class Users extends Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Users PATCH handler
|
||||
*
|
||||
* Update a user.
|
||||
*
|
||||
* Returns updated user.
|
||||
*
|
||||
* @param mixed $id User ID
|
||||
*
|
||||
* @throws 404 User not found
|
||||
* @throws 500 Failed to update user
|
||||
*/
|
||||
public function patch($id): void
|
||||
{
|
||||
// Fetch all inputs.
|
||||
@@ -59,6 +92,16 @@ class Users extends Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Users PATCH handler
|
||||
*
|
||||
* Update a user. User is retrieved using the authentication `token`.
|
||||
*
|
||||
* Returns updated user.
|
||||
*
|
||||
* @throws 404 User not found
|
||||
* @throws 500 Failed to update user
|
||||
*/
|
||||
public function patchSelf(): void
|
||||
{
|
||||
// Fetch all inputs.
|
||||
@@ -82,11 +125,24 @@ class Users extends Api
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Users DELETE handler
|
||||
*
|
||||
* Deletes a user. Optional parameter is `l` (limit of list for which the returned pages is calculated).
|
||||
*
|
||||
* Returns deleted user and resulting amount of pages for a given limit.
|
||||
*
|
||||
* @param mixed $id User ID
|
||||
*
|
||||
* @throws 404 User not found
|
||||
*/
|
||||
public function delete($id): void
|
||||
{
|
||||
// Fetch and constrain all parameters.
|
||||
$limit = constrain(0, 30, intval(Input::get("l", 10)));
|
||||
// Try to delete user, 404 if not found.
|
||||
try {
|
||||
Response::json(User::getByID($id)->delete());
|
||||
Response::json(User::getByID($id)->delete($limit));
|
||||
} catch (Exception $err) {
|
||||
switch ($err->getMessage()) {
|
||||
case "NotFound":
|
||||
|
||||
Reference in New Issue
Block a user