Skip to content

Commit ef29535

Browse files
committed
feat: Table operators are a thin wrapper around DatabaseOperator
1 parent c4c4940 commit ef29535

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/database/content_folder/folder_view.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct FolderView {
1515

1616
impl 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?;

src/database/content_folder/operator.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,31 @@ use chrono::Utc;
22
use sea_orm::*;
33
use snafu::prelude::*;
44

5+
use std::ops::Deref;
56
use std::str::FromStr;
67

78
use crate::database::operation::OperationLog;
89
use crate::database::operation::OperationType;
910
use crate::database::operation::Table;
1011
use crate::database::operator::DatabaseOperator;
1112
use crate::extractors::normalized_path::NormalizedPathComponent;
12-
use crate::extractors::user::User;
13-
use crate::state::AppState;
1413

1514
use 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.

src/database/operator.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)