2025-03-22 22:17:47 -04:00
|
|
|
pub mod auth;
|
2025-03-27 18:10:47 -04:00
|
|
|
pub mod communities;
|
2025-03-29 23:51:13 -04:00
|
|
|
pub mod notifications;
|
2025-03-24 22:42:33 -04:00
|
|
|
pub mod reactions;
|
2025-04-01 13:26:33 -04:00
|
|
|
pub mod util;
|
2025-03-24 19:55:08 -04:00
|
|
|
|
2025-03-22 22:17:47 -04:00
|
|
|
use axum::{
|
|
|
|
Router,
|
2025-03-24 19:55:08 -04:00
|
|
|
routing::{delete, get, post},
|
2025-03-22 22:17:47 -04:00
|
|
|
};
|
|
|
|
use serde::Deserialize;
|
2025-03-24 22:42:33 -04:00
|
|
|
use tetratto_core::model::{
|
2025-04-01 15:03:56 -04:00
|
|
|
communities::{
|
|
|
|
CommunityContext, CommunityJoinAccess, CommunityReadAccess, CommunityWriteAccess,
|
|
|
|
PostContext,
|
|
|
|
},
|
2025-03-31 15:39:49 -04:00
|
|
|
communities_permissions::CommunityPermission,
|
2025-03-24 22:42:33 -04:00
|
|
|
reactions::AssetType,
|
2025-03-24 20:23:52 -04:00
|
|
|
};
|
2025-03-22 22:17:47 -04:00
|
|
|
|
|
|
|
pub fn routes() -> Router {
|
|
|
|
Router::new()
|
2025-04-01 13:26:33 -04:00
|
|
|
// misc
|
|
|
|
.route("/util/proxy", get(util::proxy_request))
|
|
|
|
.route("/util/lang", get(util::set_langfile_request))
|
2025-03-24 22:42:33 -04:00
|
|
|
// reactions
|
|
|
|
.route("/reactions", post(reactions::create_request))
|
|
|
|
.route("/reactions/{id}", get(reactions::get_request))
|
|
|
|
.route("/reactions/{id}", delete(reactions::delete_request))
|
2025-03-29 00:26:56 -04:00
|
|
|
// communities
|
|
|
|
.route(
|
|
|
|
"/communities/find/{id}",
|
|
|
|
get(communities::communities::redirect_from_id),
|
|
|
|
)
|
2025-03-24 19:55:08 -04:00
|
|
|
.route(
|
2025-03-27 18:10:47 -04:00
|
|
|
"/communities",
|
|
|
|
post(communities::communities::create_request),
|
2025-03-24 19:55:08 -04:00
|
|
|
)
|
|
|
|
.route(
|
2025-03-27 18:10:47 -04:00
|
|
|
"/communities/{id}",
|
|
|
|
delete(communities::communities::delete_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{id}/title",
|
|
|
|
post(communities::communities::update_title_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{id}/context",
|
|
|
|
post(communities::communities::update_context_request),
|
2025-03-24 19:55:08 -04:00
|
|
|
)
|
|
|
|
.route(
|
2025-03-29 00:26:56 -04:00
|
|
|
"/communities/{id}/access/read",
|
2025-03-27 18:10:47 -04:00
|
|
|
post(communities::communities::update_read_access_request),
|
2025-03-24 19:55:08 -04:00
|
|
|
)
|
|
|
|
.route(
|
2025-03-29 00:26:56 -04:00
|
|
|
"/communities/{id}/access/write",
|
2025-03-27 18:10:47 -04:00
|
|
|
post(communities::communities::update_write_access_request),
|
2025-03-24 19:55:08 -04:00
|
|
|
)
|
2025-04-01 15:03:56 -04:00
|
|
|
.route(
|
|
|
|
"/communities/{id}/access/join",
|
|
|
|
post(communities::communities::update_join_access_request),
|
|
|
|
)
|
2025-03-29 00:26:56 -04:00
|
|
|
.route(
|
|
|
|
"/communities/{id}/upload/avatar",
|
|
|
|
post(communities::images::upload_avatar_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{id}/upload/banner",
|
|
|
|
post(communities::images::upload_banner_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{id}/avatar",
|
|
|
|
get(communities::images::avatar_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{id}/banner",
|
|
|
|
get(communities::images::banner_request),
|
|
|
|
)
|
2025-03-27 18:10:47 -04:00
|
|
|
// posts
|
|
|
|
.route("/posts", post(communities::posts::create_request))
|
|
|
|
.route("/posts/{id}", delete(communities::posts::delete_request))
|
2025-03-24 19:55:08 -04:00
|
|
|
.route(
|
2025-03-25 21:19:55 -04:00
|
|
|
"/posts/{id}/content",
|
2025-03-27 18:10:47 -04:00
|
|
|
post(communities::posts::update_content_request),
|
2025-03-24 19:55:08 -04:00
|
|
|
)
|
2025-03-24 20:23:52 -04:00
|
|
|
.route(
|
2025-03-25 21:19:55 -04:00
|
|
|
"/posts/{id}/context",
|
2025-03-27 18:10:47 -04:00
|
|
|
post(communities::posts::update_context_request),
|
2025-03-24 20:23:52 -04:00
|
|
|
)
|
2025-03-23 16:37:43 -04:00
|
|
|
// auth
|
2025-03-22 22:17:47 -04:00
|
|
|
// global
|
|
|
|
.route("/auth/register", post(auth::register_request))
|
|
|
|
.route("/auth/login", post(auth::login_request))
|
2025-03-23 16:37:43 -04:00
|
|
|
.route("/auth/logout", post(auth::logout_request))
|
2025-03-23 18:03:11 -04:00
|
|
|
.route(
|
|
|
|
"/auth/upload/avatar",
|
|
|
|
post(auth::images::upload_avatar_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/auth/upload/banner",
|
|
|
|
post(auth::images::upload_banner_request),
|
|
|
|
)
|
2025-03-22 22:17:47 -04:00
|
|
|
// profile
|
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/avatar",
|
|
|
|
get(auth::images::avatar_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/banner",
|
|
|
|
get(auth::images::banner_request),
|
|
|
|
)
|
2025-03-25 22:52:47 -04:00
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/follow",
|
|
|
|
post(auth::social::follow_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/block",
|
|
|
|
post(auth::social::block_request),
|
|
|
|
)
|
2025-03-25 23:58:27 -04:00
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/settings",
|
2025-04-01 16:12:13 -04:00
|
|
|
post(auth::profile::update_user_settings_request),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}",
|
|
|
|
delete(auth::profile::delete_user_request),
|
2025-03-25 23:58:27 -04:00
|
|
|
)
|
2025-03-31 11:45:34 -04:00
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/password",
|
2025-04-01 16:12:13 -04:00
|
|
|
post(auth::profile::update_user_password_request),
|
2025-03-31 11:45:34 -04:00
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/username",
|
2025-04-01 16:12:13 -04:00
|
|
|
post(auth::profile::update_user_username_request),
|
2025-03-31 11:45:34 -04:00
|
|
|
)
|
2025-03-26 21:46:21 -04:00
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/tokens",
|
2025-04-01 16:12:13 -04:00
|
|
|
post(auth::profile::update_user_tokens_request),
|
2025-03-26 21:46:21 -04:00
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/auth/profile/{id}/verified",
|
2025-04-01 16:12:13 -04:00
|
|
|
post(auth::profile::update_user_is_verified_request),
|
2025-03-26 21:46:21 -04:00
|
|
|
)
|
2025-03-29 00:26:56 -04:00
|
|
|
.route(
|
|
|
|
"/auth/profile/find/{id}",
|
|
|
|
get(auth::profile::redirect_from_id),
|
|
|
|
)
|
2025-03-29 23:51:13 -04:00
|
|
|
// notifications
|
|
|
|
.route(
|
|
|
|
"/notifications/my",
|
|
|
|
delete(notifications::delete_all_request),
|
|
|
|
)
|
|
|
|
.route("/notifications/{id}", delete(notifications::delete_request))
|
|
|
|
.route(
|
2025-03-30 22:26:20 -04:00
|
|
|
"/notifications/{id}/read_status",
|
|
|
|
post(notifications::update_read_status_request),
|
2025-03-29 23:51:13 -04:00
|
|
|
)
|
2025-03-31 15:39:49 -04:00
|
|
|
// community memberships
|
|
|
|
.route(
|
|
|
|
"/communities/{id}/join",
|
|
|
|
post(communities::communities::create_membership),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{cid}/memberships/{uid}",
|
|
|
|
get(communities::communities::get_membership),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{cid}/memberships/{uid}",
|
|
|
|
delete(communities::communities::delete_membership),
|
|
|
|
)
|
|
|
|
.route(
|
|
|
|
"/communities/{cid}/memberships/{uid}/role",
|
|
|
|
post(communities::communities::update_membership_role),
|
|
|
|
)
|
2025-04-01 23:16:09 -04:00
|
|
|
// ipbans
|
|
|
|
.route("/bans/{ip}", post(auth::ipbans::create_request))
|
|
|
|
.route("/bans/id/{id}", delete(auth::ipbans::delete_request))
|
2025-03-22 22:17:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct AuthProps {
|
|
|
|
pub username: String,
|
|
|
|
pub password: String,
|
|
|
|
}
|
2025-03-24 19:55:08 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2025-03-27 18:10:47 -04:00
|
|
|
pub struct CreateCommunity {
|
2025-03-24 19:55:08 -04:00
|
|
|
pub title: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2025-03-29 00:26:56 -04:00
|
|
|
pub struct UpdateCommunityTitle {
|
2025-03-24 19:55:08 -04:00
|
|
|
pub title: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2025-03-27 18:10:47 -04:00
|
|
|
pub struct UpdateCommunityContext {
|
|
|
|
pub context: CommunityContext,
|
2025-03-24 19:55:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2025-03-29 00:26:56 -04:00
|
|
|
pub struct UpdateCommunityReadAccess {
|
2025-03-27 18:10:47 -04:00
|
|
|
pub access: CommunityReadAccess,
|
2025-03-24 19:55:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2025-03-29 00:26:56 -04:00
|
|
|
pub struct UpdateCommunityWriteAccess {
|
2025-03-27 18:10:47 -04:00
|
|
|
pub access: CommunityWriteAccess,
|
2025-03-24 19:55:08 -04:00
|
|
|
}
|
|
|
|
|
2025-04-01 15:03:56 -04:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct UpdateCommunityJoinAccess {
|
|
|
|
pub access: CommunityJoinAccess,
|
|
|
|
}
|
|
|
|
|
2025-03-24 19:55:08 -04:00
|
|
|
#[derive(Deserialize)]
|
2025-03-29 00:26:56 -04:00
|
|
|
pub struct CreatePost {
|
2025-03-24 19:55:08 -04:00
|
|
|
pub content: String,
|
2025-03-29 00:26:56 -04:00
|
|
|
pub community: String,
|
2025-03-25 22:52:47 -04:00
|
|
|
#[serde(default)]
|
2025-03-29 00:26:56 -04:00
|
|
|
pub replying_to: Option<String>,
|
2025-03-24 19:55:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2025-03-29 00:26:56 -04:00
|
|
|
pub struct UpdatePostContent {
|
2025-03-24 19:55:08 -04:00
|
|
|
pub content: String,
|
|
|
|
}
|
2025-03-24 20:23:52 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2025-03-29 00:26:56 -04:00
|
|
|
pub struct UpdatePostContext {
|
2025-03-27 18:10:47 -04:00
|
|
|
pub context: PostContext,
|
2025-03-24 20:23:52 -04:00
|
|
|
}
|
2025-03-24 22:42:33 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct CreateReaction {
|
2025-03-29 22:27:57 -04:00
|
|
|
pub asset: String,
|
2025-03-24 22:42:33 -04:00
|
|
|
pub asset_type: AssetType,
|
2025-03-24 22:49:15 -04:00
|
|
|
pub is_like: bool,
|
2025-03-24 22:42:33 -04:00
|
|
|
}
|
2025-03-26 21:46:21 -04:00
|
|
|
|
2025-03-31 11:45:34 -04:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct UpdateUserPassword {
|
|
|
|
pub from: String,
|
|
|
|
pub to: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct UpdateUserUsername {
|
|
|
|
pub to: String,
|
|
|
|
}
|
|
|
|
|
2025-03-26 21:46:21 -04:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct UpdateUserIsVerified {
|
|
|
|
pub is_verified: bool,
|
|
|
|
}
|
2025-03-29 23:51:13 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct UpdateNotificationRead {
|
|
|
|
pub read: bool,
|
|
|
|
}
|
2025-03-31 15:39:49 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct UpdateMembershipRole {
|
|
|
|
pub role: CommunityPermission,
|
|
|
|
}
|
2025-04-01 16:12:13 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct DeleteUser {
|
|
|
|
pub password: String,
|
|
|
|
}
|
2025-04-01 23:16:09 -04:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct CreateIpBan {
|
|
|
|
pub reason: String,
|
|
|
|
}
|