-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add db trait, move config to state, fix flist_exists, get_user and vi…
…sit_dir_one_level functions
- Loading branch information
1 parent
e588b80
commit 2efda5e
Showing
6 changed files
with
143 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use utoipa::ToSchema; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct User { | ||
pub username: String, | ||
pub password: String, | ||
} | ||
|
||
pub trait DB: Send + Sync { | ||
fn get_user_by_username(&self, username: &str) -> Option<&User>; | ||
} | ||
|
||
#[derive(Debug, ToSchema)] | ||
pub struct VecDB { | ||
users: Vec<User>, | ||
} | ||
|
||
impl VecDB { | ||
pub fn new(users: &[User]) -> Self { | ||
Self { | ||
users: users.to_vec(), | ||
} | ||
} | ||
} | ||
|
||
impl DB for VecDB { | ||
fn get_user_by_username(&self, username: &str) -> Option<&User> { | ||
self.users.iter().find(|u| u.username == username) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.