Skip to content
Clone
main
34 lines 1.1 KB Rust
use api::http::State;
use api::rest::{AppResponseData, NoData};
use serde::Serialize;
use utoipa::ToSchema;
use crate::AuthService;
use crate::errors::ApiError;
use crate::services::profile::{ProfileDto, UserMeDto};
use ::session::AuthedUser;
#[derive(Debug, Clone, Serialize, ToSchema)]
pub struct MeResp {
pub user: UserMeDto,
pub profile: Option<ProfileDto>,
}
#[utoipa::path(
get,
path = "/me",
tag = "account",
description = "返回当前登录用户的身份、账号状态与资料。",
responses(
(status = 200, description = "identity and profile of the active user", body = AppResponseData<MeResp>),
(status = 404, description = "resource not found", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn me(
State(service): State<AuthService>,
AuthedUser(uid): AuthedUser,
) -> Result<AppResponseData<MeResp>, ApiError> {
let (user, profile) = service.account_me(uid).await.map_err(ApiError::from)?;
Ok(AppResponseData::ok(MeResp { user, profile }))
}