File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ pub struct FolderView {
1515
1616impl FolderView {
1717 /// Loads the top-most folder view, which is not a folder and may not have parents.
18- pub async fn index ( operator : & ContentFolderOperator ) -> Result < Self , ContentFolderError > {
18+ pub async fn index ( operator : & ContentFolderOperator < ' _ > ) -> Result < Self , ContentFolderError > {
1919 let children = operator
2020 . list ( )
2121 . await ?
@@ -37,7 +37,7 @@ impl FolderView {
3737 /// - the requested ID does not exist
3838 // TODO: optimize with custom query
3939 pub async fn from_id (
40- operator : & ContentFolderOperator ,
40+ operator : & ContentFolderOperator < ' _ > ,
4141 id : i32 ,
4242 ) -> Result < Self , ContentFolderError > {
4343 let list = operator. list ( ) . await ?;
Original file line number Diff line number Diff line change @@ -2,36 +2,31 @@ use chrono::Utc;
22use sea_orm:: * ;
33use snafu:: prelude:: * ;
44
5+ use std:: ops:: Deref ;
56use std:: str:: FromStr ;
67
78use crate :: database:: operation:: OperationLog ;
89use crate :: database:: operation:: OperationType ;
910use crate :: database:: operation:: Table ;
1011use crate :: database:: operator:: DatabaseOperator ;
1112use crate :: extractors:: normalized_path:: NormalizedPathComponent ;
12- use crate :: extractors:: user:: User ;
13- use crate :: state:: AppState ;
1413
1514use super :: * ;
1615
1716#[ derive( Clone , Debug ) ]
18- pub struct ContentFolderOperator {
19- pub state : AppState ,
20- pub user : Option < User > ,
17+ pub struct ContentFolderOperator < ' a > {
18+ pub db : & ' a DatabaseOperator ,
2119}
2220
23- impl ContentFolderOperator {
24- pub fn new ( state : AppState , user : Option < User > ) -> Self {
25- Self { state, user }
26- }
21+ impl Deref for ContentFolderOperator < ' _ > {
22+ type Target = DatabaseOperator ;
2723
28- pub fn db ( & self ) -> DatabaseOperator {
29- DatabaseOperator {
30- state : self . state . clone ( ) ,
31- user : self . user . clone ( ) ,
32- }
24+ fn deref ( & self ) -> & DatabaseOperator {
25+ self . db
3326 }
27+ }
3428
29+ impl ContentFolderOperator < ' _ > {
3530 /// List content folders
3631 ///
3732 /// Should not fail, unless SQLite was corrupted for some reason.
Original file line number Diff line number Diff line change @@ -13,10 +13,7 @@ impl DatabaseOperator {
1313 Self { state, user }
1414 }
1515
16- pub fn content_folder ( & self ) -> ContentFolderOperator {
17- ContentFolderOperator {
18- state : self . state . clone ( ) ,
19- user : self . user . clone ( ) ,
20- }
16+ pub fn content_folder < ' a > ( & ' a self ) -> ContentFolderOperator < ' a > {
17+ ContentFolderOperator { db : self }
2118 }
2219}
You can’t perform that action at this time.
0 commit comments