Skip to content
Clone
main
61 lines 2.5 KB Rust
use ::session::AuthedUser;
use api::http::{Json, Path, State};
use api::rest::{AppResponseData, NoData};
use crate::errors::ApiError;
use crate::services::dto::SpacePath;
use crate::services::join_requests::{CreateJoinRequestCmd, JoinRequestDto, JoinRequestPath};
use crate::services::service::SpaceService;
#[utoipa::path(
post,
path = "/spaces/{space_name}/join-requests",
tag = "space",
description = "提交一条加入公开空间的申请,可附一段说明。",
params(SpacePath),
request_body = CreateJoinRequestCmd,
responses(
(status = 200, description = "join request submitted", body = AppResponseData<JoinRequestDto>),
(status = 400, description = "bad request", body = AppResponseData<NoData>),
(status = 403, description = "join not allowed or requirement not met", body = AppResponseData<NoData>),
(status = 404, description = "not found", body = AppResponseData<NoData>),
(status = 409, description = "already a member or request already pending", body = AppResponseData<NoData>),
(status = 429, description = "rate limit exceeded", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn create_join_request(
State(service): State<SpaceService>,
AuthedUser(uid): AuthedUser,
Path(path): Path<SpacePath>,
Json(cmd): Json<CreateJoinRequestCmd>,
) -> Result<AppResponseData<JoinRequestDto>, ApiError> {
let request = service
.create_join_request(uid, &path.space_name, cmd)
.await?;
Ok(AppResponseData::ok(request))
}
#[utoipa::path(
delete,
path = "/spaces/{space_name}/join-requests/{request_id}",
tag = "space",
description = "申请人撤回自己待审批的加入申请。",
params(JoinRequestPath),
responses(
(status = 200, description = "join request withdrawn", body = AppResponseData<NoData>),
(status = 404, description = "not found", body = AppResponseData<NoData>),
(status = 409, description = "join request is not pending", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn withdraw_join_request(
State(service): State<SpaceService>,
AuthedUser(uid): AuthedUser,
Path(path): Path<JoinRequestPath>,
) -> Result<AppResponseData<NoData>, ApiError> {
service
.withdraw_join_request(uid, &path.space_name, path.request_id)
.await?;
Ok(AppResponseData::empty())
}