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::bookmarks::{BookmarkDto, CreateBookmarkCmd, UpdateBookmarkCmd}; use crate::services::service::ChatService; #[utoipa::path( get, path = "/chat/rooms/{room_id}/bookmarks", tag = "chat", description = "按排序位置读取指定房间的书签列表。", params(("room_id" = Uuid, Path, description = "room id"), api::pagination::PageQuery), responses( (status = 200, description = "bookmark list", body = AppResponseData>), (status = 404, description = "not found", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn list_bookmarks( State(service): State, AuthedUser(uid): AuthedUser, Path(room_id): Path, Query(page): Query, ) -> Result>, ApiError> { let bookmarks = service.list_bookmarks(uid, room_id).await?; Ok(AppResponseData::ok(api::pagination::paginate( bookmarks, &page, )?)) } #[utoipa::path( post, path = "/chat/rooms/{room_id}/bookmarks", tag = "chat", description = "在可读取的房间中创建链接书签或表情书签。", params(("room_id" = Uuid, Path, description = "room id")), request_body = CreateBookmarkCmd, responses( (status = 200, description = "bookmark created", body = AppResponseData), (status = 400, description = "bad request", body = AppResponseData), (status = 409, description = "resource already exists", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn create_bookmark( State(service): State, AuthedUser(uid): AuthedUser, Path(room_id): Path, Json(cmd): Json, ) -> Result, ApiError> { let dto = service.create_bookmark(uid, room_id, cmd).await?; Ok(AppResponseData::ok(dto)) } #[utoipa::path( patch, path = "/chat/rooms/{room_id}/bookmarks/{bookmark_id}", tag = "chat", description = "更新书签的标题、链接、表情或排序位置;仅作者或空间管理员可改。", params( ("room_id" = Uuid, Path, description = "room id"), ("bookmark_id" = Uuid, Path, description = "bookmark id") ), request_body = UpdateBookmarkCmd, responses( (status = 200, description = "bookmark updated", body = AppResponseData), (status = 404, description = "not found", body = AppResponseData), (status = 400, description = "request failed validation", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn update_bookmark( State(service): State, AuthedUser(uid): AuthedUser, Path((room_id, bookmark_id)): Path<(Uuid, Uuid)>, Json(cmd): Json, ) -> Result, ApiError> { let dto = service .update_bookmark(uid, room_id, bookmark_id, cmd) .await?; Ok(AppResponseData::ok(dto)) } #[utoipa::path( delete, path = "/chat/rooms/{room_id}/bookmarks/{bookmark_id}", tag = "chat", description = "删除指定房间书签;仅作者或空间管理员可操作。", params( ("room_id" = Uuid, Path, description = "room id"), ("bookmark_id" = Uuid, Path, description = "bookmark id") ), responses( (status = 200, description = "bookmark deleted", body = AppResponseData), (status = 404, description = "not found", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn delete_bookmark( State(service): State, AuthedUser(uid): AuthedUser, Path((room_id, bookmark_id)): Path<(Uuid, Uuid)>, ) -> Result, ApiError> { service.delete_bookmark(uid, room_id, bookmark_id).await?; Ok(AppResponseData::empty()) }