diff --git a/crates/api-types/src/lib.rs b/crates/api-types/src/lib.rs index e69de29..116da0f 100644 --- a/crates/api-types/src/lib.rs +++ b/crates/api-types/src/lib.rs @@ -0,0 +1,2 @@ +pub mod requests; +pub mod responses; diff --git a/crates/api-types/src/requests.rs b/crates/api-types/src/requests.rs new file mode 100644 index 0000000..c521dcc --- /dev/null +++ b/crates/api-types/src/requests.rs @@ -0,0 +1,71 @@ +use serde::Deserialize; +use uuid::Uuid; + +#[derive(Deserialize)] +pub struct RegisterRequest { + pub username: String, + pub email: String, + pub password: String, +} + +#[derive(Deserialize)] +pub struct LoginRequest { + pub email: String, + pub password: String, +} + +#[derive(Deserialize)] +pub struct CreateThoughtRequest { + pub content: String, + pub in_reply_to_id: Option, + pub visibility: Option, + pub content_warning: Option, + pub sensitive: Option, +} + +#[derive(Deserialize)] +pub struct EditThoughtRequest { + pub content: String, +} + +#[derive(Deserialize)] +pub struct UpdateProfileRequest { + pub display_name: Option, + pub bio: Option, + pub avatar_url: Option, + pub header_url: Option, + pub custom_css: Option, +} + +#[derive(Deserialize)] +pub struct SetTopFriendsRequest { + pub friend_ids: Vec, +} + +#[derive(Deserialize)] +pub struct CreateApiKeyRequest { + pub name: String, +} + +#[derive(Deserialize)] +pub struct PaginationQuery { + pub page: Option, + pub per_page: Option, +} + +impl PaginationQuery { + pub fn page(&self) -> u64 { + self.page.unwrap_or(1).max(1) + } + + pub fn per_page(&self) -> u64 { + self.per_page.unwrap_or(20).min(100) + } +} + +#[derive(Deserialize)] +pub struct SearchQuery { + pub q: String, + pub page: Option, + pub per_page: Option, +} diff --git a/crates/api-types/src/responses.rs b/crates/api-types/src/responses.rs new file mode 100644 index 0000000..bcadb60 --- /dev/null +++ b/crates/api-types/src/responses.rs @@ -0,0 +1,69 @@ +use chrono::{DateTime, Utc}; +use serde::Serialize; +use uuid::Uuid; + +#[derive(Serialize)] +pub struct AuthResponse { + pub token: String, + pub user: UserResponse, +} + +#[derive(Serialize, Clone)] +pub struct UserResponse { + pub id: Uuid, + pub username: String, + pub display_name: Option, + pub bio: Option, + pub avatar_url: Option, + pub header_url: Option, + pub local: bool, + pub created_at: DateTime, +} + +#[derive(Serialize, Clone)] +pub struct ThoughtResponse { + pub id: Uuid, + pub content: String, + pub author: UserResponse, + pub in_reply_to_id: Option, + pub visibility: String, + pub content_warning: Option, + pub sensitive: bool, + pub like_count: i64, + pub boost_count: i64, + pub reply_count: i64, + pub liked_by_viewer: bool, + pub boosted_by_viewer: bool, + pub created_at: DateTime, + pub updated_at: Option>, +} + +#[derive(Serialize)] +pub struct PagedResponse { + pub items: Vec, + pub total: i64, + pub page: u64, + pub per_page: u64, +} + +#[derive(Serialize)] +pub struct ApiKeyResponse { + pub id: Uuid, + pub name: String, + pub created_at: DateTime, +} + +#[derive(Serialize)] +pub struct NotificationResponse { + pub id: Uuid, + pub notification_type: String, + pub from_user: Option, + pub thought_id: Option, + pub read: bool, + pub created_at: DateTime, +} + +#[derive(Serialize)] +pub struct ErrorResponse { + pub error: String, +}