Skip to content
Clone
a06673b
37 lines 1.0 KB Rust
use axum::Json;
use axum::extract::{Path, State};
use jwt::extractor::AuthOptional;
use uuid::Uuid;
use crate::error::{UserError, UserResult};
use crate::features::UserService;
use crate::features::profile::UserPublic;
#[utoipa::path(
get,
path = "/user/users/{uid}",
tag = "user",
params(
("uid" = Uuid, Path, description = "User identifier."),
),
responses(
(status = 200, description = "Public view of the user (visibility-filtered).", body = UserPublic),
(status = 404, description = "User not found."),
),
)]
pub(crate) async fn handler(
State(svc): State<UserService>,
AuthOptional(opt): AuthOptional,
Path(uid): Path<Uuid>,
) -> UserResult<Json<UserPublic>> {
let viewer = opt.map(|u| u.claims.sub);
let public = svc
.get_user_public(uid, viewer)
.await
.map_err(|e| match e {
UserError::NotFound(_) => UserError::NotFound(format!("user {uid}")),
other => other,
})?;
Ok(Json(public))
}