Initial commit
This commit is contained in:
37
src/endpoints/folder/create.rs
Normal file
37
src/endpoints/folder/create.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Params {
|
||||
folder_name: String,
|
||||
parent_folder_id: Uuid,
|
||||
}
|
||||
|
||||
pub async fn create(
|
||||
State(state): State<AppState>,
|
||||
claims: Claims,
|
||||
Json(params): Json<Params>,
|
||||
) -> Result<Json<Uuid>, StatusCode> {
|
||||
db::folder::get_permissions(params.parent_folder_id, claims.user_id, &state.pool)
|
||||
.await
|
||||
.handle_internal()?
|
||||
.can_write_guard()?;
|
||||
|
||||
let exists =
|
||||
db::folder::exists_by_name(params.parent_folder_id, ¶ms.folder_name, &state.pool)
|
||||
.await
|
||||
.handle_internal()?;
|
||||
if exists {
|
||||
return Err(StatusCode::CONFLICT);
|
||||
}
|
||||
|
||||
let id = db::folder::insert(
|
||||
params.parent_folder_id,
|
||||
claims.user_id,
|
||||
¶ms.folder_name,
|
||||
&state.pool,
|
||||
)
|
||||
.await
|
||||
.handle_internal()?;
|
||||
|
||||
Ok(Json(id))
|
||||
}
|
Reference in New Issue
Block a user