use ::session::AuthedUser; use api::http::{Json, Path, State}; use api::rest::{AppResponseData, NoData}; use uuid::Uuid; use crate::errors::ApiError; use crate::services::reminders::{CreateReminderCmd, ReminderDto, UpdateReminderCmd}; use crate::services::service::ChatService; #[utoipa::path( post, path = "/chat/rooms/{room_id}/messages/{message_id}/reminders", tag = "chat", description = "为指定消息创建未来时间的用户提醒。", params( ("room_id" = Uuid, Path, description = "room id"), ("message_id" = Uuid, Path, description = "message id") ), request_body = CreateReminderCmd, responses( (status = 200, description = "reminder created", 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 create_reminder( State(service): State, AuthedUser(uid): AuthedUser, Path((room_id, message_id)): Path<(Uuid, Uuid)>, Json(cmd): Json, ) -> Result, ApiError> { let dto = service .create_reminder(uid, room_id, message_id, cmd) .await?; Ok(AppResponseData::ok(dto)) } #[utoipa::path( get, path = "/chat/reminders", tag = "chat", description = "列出当前用户尚未执行的提醒计划。", responses( (status = 200, description = "pending reminders", body = AppResponseData>), (status = 401, description = "unauthorized", body = AppResponseData), (status = 404, description = "resource not found", body = AppResponseData) ) )] pub async fn list_reminders( State(service): State, AuthedUser(uid): AuthedUser, ) -> Result>, ApiError> { let reminders = service.list_reminders(uid).await?; Ok(AppResponseData::ok(reminders)) } #[utoipa::path( delete, path = "/chat/reminders/{reminder_id}", tag = "chat", description = "取消当前用户的一条待执行提醒。", params(("reminder_id" = Uuid, Path, description = "reminder id")), responses( (status = 200, description = "reminder cancelled", body = AppResponseData), (status = 404, description = "not found", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn cancel_reminder( State(service): State, AuthedUser(uid): AuthedUser, Path(reminder_id): Path, ) -> Result, ApiError> { service.cancel_reminder(uid, reminder_id).await?; Ok(AppResponseData::empty()) } #[utoipa::path( patch, path = "/chat/reminders/{reminder_id}", tag = "chat", description = "修改待执行提醒的时间或备注。", params(("reminder_id" = Uuid, Path)), request_body = UpdateReminderCmd, responses( (status = 200, description = "reminder 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_reminder( State(service): State, AuthedUser(uid): AuthedUser, Path(reminder_id): Path, Json(cmd): Json, ) -> Result, ApiError> { let dto = service.update_reminder(uid, reminder_id, cmd).await?; Ok(AppResponseData::ok(dto)) }