use ::session::AuthedUser; use api::http::{Json, Path, Query, State}; use api::rest::{AppResponseData, NoData}; use uuid::Uuid; use crate::errors::ApiError; use crate::services::dms::{DmDto, OpenDmCmd}; use crate::services::service::ChatService; #[utoipa::path( post, path = "/chat/dms", tag = "chat", description = "打开与指定用户的私聊会话;已有会话则恢复,新会话则创建。", request_body = OpenDmCmd, responses( (status = 200, description = "dm opened", body = AppResponseData), (status = 429, description = "creation quota exceeded", body = AppResponseData), (status = 404, description = "not found", body = AppResponseData), (status = 409, description = "resource already exists", body = AppResponseData), (status = 400, description = "request failed validation", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn open_dm( State(service): State, AuthedUser(uid): AuthedUser, Json(cmd): Json, ) -> Result, ApiError> { let dto = service.open_dm(uid, cmd).await?; Ok(AppResponseData::ok(dto)) } #[utoipa::path( get, path = "/chat/dms", tag = "chat", description = "列出当前用户仍有效的私聊会话及其未读信息。", params(api::pagination::PageQuery), responses( (status = 200, description = "my dms", body = AppResponseData>), (status = 401, description = "unauthorized", body = AppResponseData), (status = 404, description = "resource not found", body = AppResponseData) ) )] pub async fn list_dms( State(service): State, AuthedUser(uid): AuthedUser, Query(page): Query, ) -> Result>, ApiError> { let dms = service.list_dms(uid).await?; Ok(AppResponseData::ok(api::pagination::paginate(dms, &page)?)) } #[utoipa::path( delete, path = "/chat/dms/{room_id}", tag = "chat", description = "将当前用户从指定私聊会话中移除,不再接收该会话消息。", params(("room_id" = Uuid, Path, description = "dm room id")), responses( (status = 200, description = "dm closed", body = AppResponseData), (status = 404, description = "not found", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn close_dm( State(service): State, AuthedUser(uid): AuthedUser, Path(room_id): Path, ) -> Result, ApiError> { service.close_dm(uid, room_id).await?; Ok(AppResponseData::empty()) }