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), (status = 400, description = "bad request", body = AppResponseData), (status = 403, description = "join not allowed or requirement not met", body = AppResponseData), (status = 404, description = "not found", body = AppResponseData), (status = 409, description = "already a member or request already pending", body = AppResponseData), (status = 429, description = "rate limit exceeded", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn create_join_request( State(service): State, AuthedUser(uid): AuthedUser, Path(path): Path, Json(cmd): Json, ) -> Result, 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), (status = 404, description = "not found", body = AppResponseData), (status = 409, description = "join request is not pending", body = AppResponseData), (status = 401, description = "authentication required", body = AppResponseData) ) )] pub async fn withdraw_join_request( State(service): State, AuthedUser(uid): AuthedUser, Path(path): Path, ) -> Result, ApiError> { service .withdraw_join_request(uid, &path.space_name, path.request_id) .await?; Ok(AppResponseData::empty()) }