Skip to content
Clone
b7cd2b1
36 lines 1.4 KB Rust
use export::http::{Json, Path, State};
use export::rest::{AppResponseData, NoData};
use jwt::Session;
use crate::errors::ApiError;
use crate::services::dir::{CreateDirCmd, DirNodeDto};
use crate::services::service::SpaceService;
use crate::services::spaces::SpaceNamePath;
use jwt::share::session;
#[utoipa::path(
post,
path = "/spaces/{space_name}/dir",
tag = "space",
description = "在空间目录树中创建目录节点。",
params(SpaceNamePath),
request_body = CreateDirCmd,
responses(
(status = 200, description = "dir node created", body = AppResponseData<DirNodeDto>),
(status = 400, description = "bad request", body = AppResponseData<NoData>),
(status = 403, description = "forbidden", body = AppResponseData<NoData>),
(status = 404, description = "space or parent not found", body = AppResponseData<NoData>),
(status = 409, description = "resource already exists", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn create_dir_node(
State(service): State<SpaceService>,
session: Session,
Path(path): Path<SpaceNamePath>,
Json(cmd): Json<CreateDirCmd>,
) -> Result<AppResponseData<DirNodeDto>, ApiError> {
let uid = session::require_uid(&session)?;
let node = service.create_dir_node(uid, &path.space_name, cmd).await?;
Ok(AppResponseData::ok(node))
}