implement tags

This commit is contained in:
2026-02-25 02:45:42 +01:00
parent 5a92740785
commit 11476f7c5b
4 changed files with 271 additions and 5 deletions

View File

@@ -4,9 +4,13 @@ use axum::{
routing::get,
};
use crate::users::{UserError, auth::AuthError, sessions::SessionError};
use crate::{
tags::TagError,
users::{UserError, auth::AuthError, sessions::SessionError},
};
mod sessions;
mod tags;
mod users;
// TODO: PERMISSIONS FOR ENDPOINTS & ACTIONS
@@ -17,6 +21,8 @@ pub fn api_router() -> Router {
.route("/api/users/{id}", get(users::get_by_id))
.route("/api/users/@{handle}", get(users::get_by_handle))
.route("/api/sessions/{id}", get(sessions::get_by_id))
.route("/api/tags/{id}", get(tags::get_by_id))
.route("/api/tags/#{id}", get(tags::get_by_name))
}
pub struct CompositeError(Response);
@@ -37,4 +43,4 @@ macro_rules! composite_from {
)+
};
}
composite_from!(AuthError, UserError, SessionError);
composite_from!(AuthError, UserError, SessionError, TagError);

32
src/api/tags.rs Normal file
View File

@@ -0,0 +1,32 @@
use axum::{
Json,
extract::Path,
http::HeaderMap,
response::{IntoResponse, Response},
};
use uuid::Uuid;
use crate::{
api::CompositeError,
tags::{Tag, TagName},
users::{
User,
auth::{UserAuthRequired, UserAuthenticate},
},
};
pub async fn get_by_id(
Path(id): Path<Uuid>,
headers: HeaderMap,
) -> Result<Response, CompositeError> {
User::authenticate(&headers)?.required()?;
Ok(Json(Tag::get_by_id(id)?).into_response())
}
pub async fn get_by_name(
Path(name): Path<TagName>,
headers: HeaderMap,
) -> Result<Response, CompositeError> {
User::authenticate(&headers)?.required()?;
Ok(Json(Tag::get_by_name(name)?).into_response())
}