diff options
| author | Joe Carstairs <me@joeac.net> | 2024-11-17 09:22:32 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-11-17 09:22:32 +0000 |
| commit | 1a494937021561595d0fb29e26fb707aef9e55de (patch) | |
| tree | 91234bbc9d1946946cf93d4d57b0b5a13a09de0a /backend/app/src/routes/account.rs | |
| parent | 3c7218be1446f8cf914063b1c52c1cbdc8497c8c (diff) | |
Refactors rust code into workspace
Diffstat (limited to 'backend/app/src/routes/account.rs')
| -rw-r--r-- | backend/app/src/routes/account.rs | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/backend/app/src/routes/account.rs b/backend/app/src/routes/account.rs index e4eb153..96f1f38 100644 --- a/backend/app/src/routes/account.rs +++ b/backend/app/src/routes/account.rs @@ -1,8 +1,7 @@ use budgeting_app_core::{ models::account::Account, - queries::accounts::{get_all_accounts as get_all_accounts_query, insert_account}, + queries::accounts::{get_all_accounts as get_all_accounts_query, insert_accounts}, }; -use diesel::result::DatabaseErrorKind; use rocket::http::Status; use rocket::serde::json::Json; use rocket::{get, post, Responder}; @@ -39,21 +38,13 @@ pub async fn create_account( let accounts_vec = vec![account.clone()]; let num_rows_inserted = user_data_db - .run(move |connection| insert_account(&accounts_vec, connection)) + .run(move |connection| insert_accounts(&accounts_vec, connection)) .await; match num_rows_inserted { Ok(_) => CreateAccountResponder::Created(Json(account)), - Err(err) => match err { - diesel::result::Error::DatabaseError(DatabaseErrorKind::UniqueViolation, info) => { - let column = info.column_name().unwrap_or("account"); - CreateAccountResponder::BadRequest(format!( - "Error creating account: {column} was not unique." - )) - } - _ => CreateAccountResponder::InternalServerError(format!( + Err(err) => CreateAccountResponder::InternalServerError(format!( "Error creating account: {err}" )), - }, } } |
