Skip to content
Clone
main
32 lines 999 B Rust
use ::session::AuthedUser;
use api::http::{Path, State};
use api::rest::{AppResponseData, NoData};
use crate::AuthService;
use crate::errors::ApiError;
use crate::share::account::types::UserPublic;
#[utoipa::path(
get,
path = "/users/{user_id}",
tag = "users",
description = "按用户 ID 返回公开身份资料,并按账号状态与可见性过滤。",
params(
("user_id" = i64, Path, description = "user id")
),
responses(
(status = 200, description = "public user identity", body = AppResponseData<UserPublic>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn get_user(
State(service): State<AuthService>,
AuthedUser(caller): AuthedUser,
Path(user_id): Path<i64>,
) -> Result<AppResponseData<UserPublic>, ApiError> {
let user = service
.public_user(caller, user_id)
.await
.map_err(ApiError::from)?;
Ok(AppResponseData::ok(user))
}