summaryrefslogtreecommitdiff
path: root/src/api/posts.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/posts.rs')
-rw-r--r--src/api/posts.rs97
1 files changed, 95 insertions, 2 deletions
diff --git a/src/api/posts.rs b/src/api/posts.rs
index 6aa074f..f1cdab3 100644
--- a/src/api/posts.rs
+++ b/src/api/posts.rs
@@ -5,10 +5,28 @@ use axum::{
};
use serde::Deserialize;
-use crate::types::{
+use crate::{types::{
extract::{AuthorizedUser, Check, CheckResult, Json},
http::ResponseCode,
post::Post,
+}, public::docs::{EndpointDocumentation, EndpointMethod}};
+
+pub const POSTS_CREATE: EndpointDocumentation = EndpointDocumentation {
+ uri: "/api/posts/create",
+ method: EndpointMethod::Post,
+ description: "Creates a new post",
+ body: Some(r#"
+ {
+ "content" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
+ }
+ "#),
+ responses: &[
+ (201, "Successfully created post"),
+ (400, "Body does not match parameters"),
+ (401, "Unauthorized"),
+ (500, "Failed to create post")
+ ],
+ cookie: Some("auth"),
};
#[derive(Deserialize)]
@@ -43,6 +61,24 @@ async fn create(
ResponseCode::Created.json(&json)
}
+pub const POSTS_PAGE: EndpointDocumentation = EndpointDocumentation {
+ uri: "/api/posts/page",
+ method: EndpointMethod::Post,
+ description: "Load a section of posts from newest to oldest",
+ body: Some(r#"
+ {
+ "page": 0
+ }
+ "#),
+ responses: &[
+ (200, "Returns posts in <span>application/json<span>"),
+ (400, "Body does not match parameters"),
+ (401, "Unauthorized"),
+ (500, "Failed to fetch posts")
+ ],
+ cookie: Some("auth"),
+};
+
#[derive(Deserialize)]
struct PostPageRequest {
page: u64,
@@ -69,10 +105,29 @@ async fn page(
ResponseCode::Success.json(&json)
}
+pub const POSTS_USER: EndpointDocumentation = EndpointDocumentation {
+ uri: "/api/posts/user",
+ method: EndpointMethod::Post,
+ description: "Load a section of posts from newest to oldest from a specific user",
+ body: Some(r#"
+ {
+ "user_id": 3,
+ "page": 0
+ }
+ "#),
+ responses: &[
+ (200, "Returns posts in <span>application/json<span>"),
+ (400, "Body does not match parameters"),
+ (401, "Unauthorized"),
+ (500, "Failed to fetch posts")
+ ],
+ cookie: Some("auth"),
+};
+
#[derive(Deserialize)]
struct UsersPostsRequest {
user_id: u64,
- page: u64
+ page: u64,
}
impl Check for UsersPostsRequest {
@@ -96,6 +151,25 @@ async fn user(
ResponseCode::Success.json(&json)
}
+pub const POSTS_COMMENT: EndpointDocumentation = EndpointDocumentation {
+ uri: "/api/posts/comment",
+ method: EndpointMethod::Patch,
+ description: "Add a comment to a post",
+ body: Some(r#"
+ {
+ "content": "This is a very cool comment",
+ "post_id": 0
+ }
+ "#),
+ responses: &[
+ (200, "Successfully added comment"),
+ (400, "Body does not match parameters"),
+ (401, "Unauthorized"),
+ (500, "Failed to add comment")
+ ],
+ cookie: Some("auth"),
+};
+
#[derive(Deserialize)]
struct PostCommentRequest {
content: String,
@@ -129,6 +203,25 @@ async fn comment(
ResponseCode::Success.text("Successfully commented on post")
}
+pub const POSTS_LIKE: EndpointDocumentation = EndpointDocumentation {
+ uri: "/api/posts/like",
+ method: EndpointMethod::Patch,
+ description: "Set like status on a post",
+ body: Some(r#"
+ {
+ "post_id" : 0,
+ "status" : true
+ }
+ "#),
+ responses: &[
+ (200, "Successfully set like status"),
+ (400, "Body does not match parameters"),
+ (401, "Unauthorized"),
+ (500, "Failed to set like status")
+ ],
+ cookie: Some("auth"),
+};
+
#[derive(Deserialize)]
struct PostLikeRequest {
state: bool,