@@ -72,16 +72,34 @@ impl CategoryOperator {
7272 }
7373
7474 /// Delete a category
75- pub async fn delete ( & self , id : i32 ) -> Result < String , CategoryError > {
75+ pub async fn delete ( & self , id : i32 , user : Option < User > ) -> Result < String , CategoryError > {
7676 let db = & self . state . database ;
7777 let category: Option < Model > = Entity :: find_by_id ( id) . one ( db) . await . context ( DBSnafu ) ?;
7878
7979 match category {
8080 Some ( category) => {
81- let category_name : String = category. clone ( ) . name ;
81+ let category_clone : Model = category. clone ( ) ;
8282 category. delete ( db) . await . context ( DBSnafu ) ?;
8383
84- Ok ( category_name)
84+ let operation_log = OperationLog {
85+ user,
86+ date : Utc :: now ( ) ,
87+ table : Table :: Category ,
88+ operation : OperationType :: Delete ,
89+ operation_id : OperationId {
90+ object_id : category_clone. id ,
91+ name : category_clone. name . to_owned ( ) ,
92+ } ,
93+ operation_form : None ,
94+ } ;
95+
96+ self . state
97+ . logger
98+ . write ( operation_log)
99+ . await
100+ . context ( LoggerSnafu ) ?;
101+
102+ Ok ( category_clone. name )
85103 }
86104 None => Err ( CategoryError :: NotFound { id } ) ,
87105 }
@@ -142,7 +160,7 @@ impl CategoryOperator {
142160 object_id : model. id . to_owned ( ) ,
143161 name : f. name . to_string ( ) ,
144162 } ,
145- operation_form : Operation :: Category ( f. clone ( ) ) ,
163+ operation_form : Some ( Operation :: Category ( f. clone ( ) ) ) ,
146164 } ;
147165
148166 self . state
0 commit comments