main
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<ReminderDto>),
(status = 404, description = "not found", body = AppResponseData<NoData>),
(status = 409, description = "resource already exists", body = AppResponseData<NoData>),
(status = 400, description = "request failed validation", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn create_reminder(
State(service): State<ChatService>,
AuthedUser(uid): AuthedUser,
Path((room_id, message_id)): Path<(Uuid, Uuid)>,
Json(cmd): Json<CreateReminderCmd>,
) -> Result<AppResponseData<ReminderDto>, 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<Vec<ReminderDto>>),
(status = 401, description = "unauthorized", body = AppResponseData<NoData>),
(status = 404, description = "resource not found", body = AppResponseData<NoData>)
)
)]
pub async fn list_reminders(
State(service): State<ChatService>,
AuthedUser(uid): AuthedUser,
) -> Result<AppResponseData<Vec<ReminderDto>>, 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<NoData>),
(status = 404, description = "not found", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn cancel_reminder(
State(service): State<ChatService>,
AuthedUser(uid): AuthedUser,
Path(reminder_id): Path<Uuid>,
) -> Result<AppResponseData<NoData>, 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<ReminderDto>),
(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_reminder(
State(service): State<ChatService>,
AuthedUser(uid): AuthedUser,
Path(reminder_id): Path<Uuid>,
Json(cmd): Json<UpdateReminderCmd>,
) -> Result<AppResponseData<ReminderDto>, ApiError> {
let dto = service.update_reminder(uid, reminder_id, cmd).await?;
Ok(AppResponseData::ok(dto))
}