e1df092
use axum::extract::{Json, Path, State};
use export::rest::{AppResponseData, NoData};
use jwt::Session;
use crate::errors::ApiError;
use crate::services::dir::{DirNodeDto, DirPath, MoveDirCmd};
use crate::services::service::SpaceService;
use jwt::share::session;
#[utoipa::path(
patch,
path = "/spaces/{space_name}/dir/{dir_id}/position",
tag = "space",
description = "移动目录节点并防止父链自引用形成环。",
params(DirPath),
request_body = MoveDirCmd,
responses(
(status = 200, description = "dir node moved", body = AppResponseData<DirNodeDto>),
(status = 400, description = "bad request", body = AppResponseData<NoData>),
(status = 403, description = "forbidden", body = AppResponseData<NoData>),
(status = 404, description = "dir node not found", body = AppResponseData<NoData>),
(status = 401, description = "authentication required", body = AppResponseData<NoData>)
)
)]
pub async fn move_dir_node(
State(service): State<SpaceService>,
session: Session,
Path(path): Path<DirPath>,
Json(cmd): Json<MoveDirCmd>,
) -> Result<AppResponseData<DirNodeDto>, ApiError> {
let uid = session::require_uid(&session)?;
let node = service
.move_dir_node(uid, &path.space_name, path.dir_id, cmd)
.await?;
Ok(AppResponseData::ok(node))
}