gitdataai/libs/service/auth/me.rs
2026-04-15 09:08:09 +08:00

30 lines
956 B
Rust

use crate::AppService;
use crate::error::AppError;
use serde::{Deserialize, Serialize};
use session::Session;
use uuid::Uuid;
#[derive(Deserialize, Serialize, Clone, Debug, utoipa::ToSchema)]
pub struct ContextMe {
pub uid: Uuid,
pub username: String,
pub display_name: Option<String>,
pub avatar_url: Option<String>,
pub has_unread_notifications: u64,
}
impl AppService {
pub async fn auth_me(&self, ctx: Session) -> Result<ContextMe, AppError> {
let user_id = ctx.user().ok_or(AppError::Unauthorized)?;
let user = self.utils_find_user_by_uid(user_id).await?;
// let notify = self.notify_get_user_unread_count(&ctx).await?;
Ok(ContextMe {
uid: user.uid,
username: user.username,
display_name: user.display_name,
avatar_url: user.avatar_url,
// has_unread_notifications: notify,
has_unread_notifications: 0,
})
}
}