diff options
| author | Erwin Kroon <123574+ekroon@users.noreply.github.com> | 2023-02-15 09:54:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-15 08:54:09 +0000 |
| commit | dcfad9a90d4b18465c437811698c879c4c5a9fcc (patch) | |
| tree | 327990925add8c97cc02c61d5607628921e81b96 /atuin-server/src/handlers/user.rs | |
| parent | fish: Fix `atuin init` for the fish shell (#699) (diff) | |
| download | atuin-dcfad9a90d4b18465c437811698c879c4c5a9fcc.zip | |
Add support for generic database in AppState (#711)
Diffstat (limited to 'atuin-server/src/handlers/user.rs')
| -rw-r--r-- | atuin-server/src/handlers/user.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/atuin-server/src/handlers/user.rs b/atuin-server/src/handlers/user.rs index 761724c5..677e7c65 100644 --- a/atuin-server/src/handlers/user.rs +++ b/atuin-server/src/handlers/user.rs @@ -34,11 +34,11 @@ pub fn verify_str(secret: &str, verify: &str) -> bool { } #[instrument(skip_all, fields(user.username = username.as_str()))] -pub async fn get( +pub async fn get<DB: Database>( Path(username): Path<String>, - state: State<AppState>, + state: State<AppState<DB>>, ) -> Result<Json<UserResponse>, ErrorResponseStatus<'static>> { - let db = &state.0.postgres; + let db = &state.0.database; let user = match db.get_user(username.as_ref()).await { Ok(user) => user, Err(sqlx::Error::RowNotFound) => { @@ -58,9 +58,9 @@ pub async fn get( } #[instrument(skip_all)] -pub async fn register( +pub async fn register<DB: Database>( settings: Extension<Settings>, - state: State<AppState>, + state: State<AppState<DB>>, Json(register): Json<RegisterRequest>, ) -> Result<Json<RegisterResponse>, ErrorResponseStatus<'static>> { if !settings.open_registration { @@ -78,7 +78,7 @@ pub async fn register( password: hashed, }; - let db = &state.0.postgres; + let db = &state.0.database; let user_id = match db.add_user(&new_user).await { Ok(id) => id, Err(e) => { @@ -107,11 +107,11 @@ pub async fn register( } #[instrument(skip_all, fields(user.username = login.username.as_str()))] -pub async fn login( - state: State<AppState>, +pub async fn login<DB: Database>( + state: State<AppState<DB>>, login: Json<LoginRequest>, ) -> Result<Json<LoginResponse>, ErrorResponseStatus<'static>> { - let db = &state.0.postgres; + let db = &state.0.database; let user = match db.get_user(login.username.borrow()).await { Ok(u) => u, Err(sqlx::Error::RowNotFound) => { |
