40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use crate::prelude::*;
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Params {
|
|
folder_name: String,
|
|
parent_folder_id: Uuid,
|
|
}
|
|
|
|
pub async fn create(
|
|
State(pool): State<Pool>,
|
|
claims: Claims,
|
|
Json(params): Json<Params>,
|
|
) -> GeneralResult<Json<Uuid>> {
|
|
db::folder::get_permissions(params.parent_folder_id, claims.user_id, &pool)
|
|
.await
|
|
.can_write_guard()?;
|
|
|
|
if params.folder_name.len() > 255 {
|
|
return Err(GeneralError::message(
|
|
StatusCode::BAD_REQUEST,
|
|
"Folder name too long",
|
|
));
|
|
}
|
|
|
|
let exists = db::folder::name_exists(params.parent_folder_id, ¶ms.folder_name, &pool)
|
|
.await
|
|
.handle_internal("Error getting existing names")?;
|
|
if exists {
|
|
return Err(GeneralError::message(
|
|
StatusCode::CONFLICT,
|
|
"Name already taken",
|
|
));
|
|
}
|
|
|
|
db::folder::insert(params.parent_folder_id, ¶ms.folder_name, &pool)
|
|
.await
|
|
.handle_internal("Error creating the folder")
|
|
.map(Json)
|
|
}
|