1
0
Fork 0
forked from gorb/backend

docs: partially document codebase

Should make it easier for frontend to figure out what stuff actually does, more will be added as the project goes on
This commit is contained in:
Radical 2025-05-27 11:52:17 +00:00
parent 1aa38631b8
commit 16ccf94631
10 changed files with 226 additions and 18 deletions

View file

@ -1,3 +1,5 @@
//! `/api/v1/servers` Guild related endpoints
use actix_web::{HttpRequest, HttpResponse, Scope, get, post, web};
use serde::Deserialize;
@ -18,13 +20,37 @@ struct GuildInfo {
pub fn web() -> Scope {
web::scope("/servers")
.service(create)
.service(post)
.service(get)
.service(uuid::web())
}
/// `POST /api/v1/servers` Creates a new guild
///
/// requires auth: yes
///
/// ### Request Example
/// ```
/// json!({
/// "name": "My new server!"
/// });
/// ```
///
/// ### Response Example
/// ```
/// json!({
/// "uuid": "383d2afa-082f-4dd3-9050-ca6ed91487b6",
/// "name": "My new server!",
/// "description": null,
/// "icon": null,
/// "owner_uuid": "155d2291-fb23-46bd-a656-ae7c5d8218e6",
/// "roles": [],
/// "member_count": 1
/// });
/// ```
/// NOTE: UUIDs in this response are made using `uuidgen`, UUIDs made by the actual backend will be UUIDv7 and have extractable timestamps
#[post("")]
pub async fn create(
pub async fn post(
req: HttpRequest,
guild_info: web::Json<GuildInfo>,
data: web::Data<Data>,
@ -47,6 +73,53 @@ pub async fn create(
Ok(HttpResponse::Ok().json(guild))
}
/// `GET /api/v1/servers` Fetches all guilds
///
/// requires auth: yes
///
/// requires admin: yes
///
/// ### Response Example
/// ```
/// json!([
/// {
/// "uuid": "383d2afa-082f-4dd3-9050-ca6ed91487b6",
/// "name": "My new server!",
/// "description": null,
/// "icon": null,
/// "owner_uuid": "155d2291-fb23-46bd-a656-ae7c5d8218e6",
/// "roles": [],
/// "member_count": 1
/// },
/// {
/// "uuid": "5ba61ec7-5f97-43e1-89a5-d4693c155612",
/// "name": "My first server!",
/// "description": "This is a cool and nullable description!",
/// "icon": "https://nullable-url/path/to/icon.png",
/// "owner_uuid": "155d2291-fb23-46bd-a656-ae7c5d8218e6",
/// "roles": [
/// {
/// "uuid": "be0e4da4-cf73-4f45-98f8-bb1c73d1ab8b",
/// "guild_uuid": "5ba61ec7-5f97-43e1-89a5-d4693c155612",
/// "name": "Cool people",
/// "color": 15650773,
/// "is_above": c7432f1c-f4ad-4ad3-8216-51388b6abb5b,
/// "permissions": 0
/// }
/// {
/// "uuid": "c7432f1c-f4ad-4ad3-8216-51388b6abb5b",
/// "guild_uuid": "5ba61ec7-5f97-43e1-89a5-d4693c155612",
/// "name": "Equally cool people",
/// "color": 16777215,
/// "is_above": null,
/// "permissions": 0
/// }
/// ],
/// "member_count": 20
/// }
/// ]);
/// ```
/// NOTE: UUIDs in this response are made using `uuidgen`, UUIDs made by the actual backend will be UUIDv7 and have extractable timestamps
#[get("")]
pub async fn get(
req: HttpRequest,