@@ -3,16 +3,15 @@ use askama_web::WebTemplate;
33use axum:: Form ;
44use axum_extra:: extract:: CookieJar ;
55use serde:: { Deserialize , Serialize } ;
6- use snafu:: prelude:: * ;
76
87use crate :: database:: content_folder:: PathBreadcrumb ;
98use crate :: database:: { category, content_folder} ;
109use crate :: extractors:: folder_request:: FolderRequest ;
1110use crate :: filesystem:: FileSystemEntry ;
11+ use crate :: state:: AppStateContext ;
1212use crate :: state:: flash_message:: {
1313 FallibleTemplate , FlashRedirect , FlashTemplate , OperationStatus , StatusCookie ,
1414} ;
15- use crate :: state:: { AppStateContext , error:: * } ;
1615
1716#[ derive( Clone , Debug , Deserialize , Serialize ) ]
1817pub struct ContentFolderForm {
@@ -72,19 +71,12 @@ pub async fn show(
7271 status. with_template ( ContentFolderShowTemplate :: new ( context, folder) )
7372}
7473
75- // TODO: currently an error takes us back to /
76- pub async fn create (
74+ pub async fn create_subfolder (
7775 context : AppStateContext ,
7876 jar : CookieJar ,
77+ folder : FolderRequest ,
7978 Form ( form) : Form < ContentFolderForm > ,
80- ) -> Result < FlashRedirect , AppStateError > {
81- let category = context
82- . db
83- . category ( )
84- . find_by_id ( form. category_id )
85- . await
86- . context ( CategorySnafu ) ?;
87-
79+ ) -> Result < FlashRedirect , ContentFolderShowTemplate > {
8880 match context. db . content_folder ( ) . create ( & form) . await {
8981 Ok ( created) => {
9082 let status = StatusCookie :: success (
@@ -95,23 +87,12 @@ pub async fn create(
9587 ) ,
9688 ) ;
9789
98- let uri = format ! ( "/folders/{}{}" , category. name, created. path) ;
90+ let uri = format ! ( "/folders/{}{}" , folder . category. name, created. path) ;
9991 Ok ( status. redirect ( & uri) )
10092 }
10193 Err ( error) => {
102- let status = StatusCookie :: error ( jar, error. to_string ( ) ) ;
103- let uri = if let Some ( parent_id) = form. parent_id {
104- let parent = context
105- . db
106- . content_folder ( )
107- . find_by_id ( parent_id)
108- . await
109- . context ( ContentFolderSnafu ) ?;
110- format ! ( "/folders/{}{}" , category. name, parent. path)
111- } else {
112- format ! ( "/folders{}" , category. name)
113- } ;
114- Ok ( status. redirect ( & uri) )
94+ let status = OperationStatus :: error ( error) ;
95+ Err ( status. with_template ( ContentFolderShowTemplate :: new ( context, folder) ) )
11596 }
11697 }
11798}
0 commit comments