Skip to content
Clone
main
53 lines 2.1 KB Rust
use ::session::AuthedUser;
use api::http::{Json, Path, State};
use api::rest::{AppResponseData, NoData};
use uuid::Uuid;
use crate::errors::ApiError;
use crate::services::service::ChatService;
use crate::services::settings::{RoomSettingDto, UpdateRoomSettingCmd};
#[utoipa::path(
get,
path = "/chat/rooms/{room_id}/settings",
tag = "chat",
description = "读取当前用户针对单个房间的通知与显示设置。",
params(("room_id" = Uuid, Path, description = "room id")),
responses(
(status = 200, description = "room setting", body = AppResponseData<RoomSettingDto>),
(status = 404, description = "not found", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn get_room_setting(
State(service): State<ChatService>,
AuthedUser(uid): AuthedUser,
Path(room_id): Path<Uuid>,
) -> Result<AppResponseData<RoomSettingDto>, ApiError> {
let dto = service.get_room_setting(uid, room_id).await?;
Ok(AppResponseData::ok(dto))
}
#[utoipa::path(
put,
path = "/chat/rooms/{room_id}/settings",
tag = "chat",
description = "更新当前用户的房间通知级别、收藏、隐藏或免打扰设置。",
params(("room_id" = Uuid, Path, description = "room id")),
request_body = UpdateRoomSettingCmd,
responses(
(status = 200, description = "room setting updated", body = AppResponseData<RoomSettingDto>),
(status = 404, description = "not found", body = AppResponseData<NoData>),
(status = 400, description = "request failed validation", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn update_room_setting(
State(service): State<ChatService>,
AuthedUser(uid): AuthedUser,
Path(room_id): Path<Uuid>,
Json(cmd): Json<UpdateRoomSettingCmd>,
) -> Result<AppResponseData<RoomSettingDto>, ApiError> {
let dto = service.update_room_setting(uid, room_id, cmd).await?;
Ok(AppResponseData::ok(dto))
}