This commit is contained in:
2024-07-29 22:06:57 +02:00
parent 5ce2215e44
commit 6a62ae58fc
22 changed files with 670 additions and 7 deletions
+42 -1
View File
@@ -11,8 +11,16 @@ use Khofmann\Models\User\User;
use Khofmann\Request\Request;
use Khofmann\Response\Response;
/**
* Posts route handlers
*/
class Posts extends Api
{
/**
* Posts GET handler
*
* Lists posts. Optional parameters are `l` (limit of returned list) and `p` (page, i.e. offset).
*/
public function get()
{
// Fetch and constrain all parameters.
@@ -24,6 +32,15 @@ class Posts extends Api
Response::json(Post::list($page, $limit, $authed));
}
/**
* Posts POST handler
*
* Create a new posts. Required inputs are `content`. Optional parameter is `l` (limit of list for which the returned pages is calculated).
*
* Returns created post and resulting amount of pages for a given limit.
*
* @throws 400 Missing fields
*/
public function post(): void
{
// Fetch all required inputs.
@@ -47,6 +64,19 @@ class Posts extends Api
}
}
/**
* Posts PATCH handler
*
* Update a posts.
*
* Returns updated post.
*
* @param mixed $id ID of post to update
*
* @throws 401 Not authorized (trying to edit a different users post if not admin)
* @throws 404 Post not found
* @throws 500 Failed to update user
*/
public function patch($id): void
{
// Fetch all inputs.
@@ -75,9 +105,20 @@ class Posts extends Api
}
}
/**
* Posts DELETE handler
*
* Delete a post. Optional parameter is `l` (limit of list for which the returned pages is calculated).
*
* Returns deleted post and resulting amount of pages for a given limit.
*
* @param mixed $id ID of posts to delete
*
* @throws 404 Post not found
*/
public function delete($id): void
{
// Fetch ax(0, intval(Input::get("p", 0)));
// Fetch and constrain all parameters.
$limit = constrain(0, 30, intval(Input::get("l", 10)));
// Try delete, 404 if post was not found.
try {