summaryrefslogtreecommitdiff
path: root/rust/schist_backend/src/routes
diff options
context:
space:
mode:
Diffstat (limited to 'rust/schist_backend/src/routes')
-rw-r--r--rust/schist_backend/src/routes/account.rs48
-rw-r--r--rust/schist_backend/src/routes/category.rs16
-rw-r--r--rust/schist_backend/src/routes/mod.rs2
3 files changed, 0 insertions, 66 deletions
diff --git a/rust/schist_backend/src/routes/account.rs b/rust/schist_backend/src/routes/account.rs
deleted file mode 100644
index 83d4d1b..0000000
--- a/rust/schist_backend/src/routes/account.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-use schist_models::account::Account;
-use schist_queries::accounts::{get_all_accounts as get_all_accounts_query, insert_accounts};
-use rocket::http::Status;
-use rocket::serde::json::Json;
-use rocket::{get, post, Responder};
-
-use crate::databases::UserDataDb;
-
-#[get("/account")]
-pub async fn get_all_accounts(user_data_db: UserDataDb) -> Result<Json<Vec<Account>>, (Status, String)> {
- user_data_db
- .run(get_all_accounts_query)
- .await
- .map(Json)
- .map_err(|err| (Status::InternalServerError, err.to_string()))
-}
-
-#[derive(Responder)]
-pub enum CreateAccountResponder {
- #[response(status = 500, content_type = "text")]
- InternalServerError(String),
-
- #[response(status = 202, content_type = "json")]
- Created(Json<Account>),
-
- #[response(status = 400, content_type = "text")]
- BadRequest(String),
-}
-
-#[post("/account", data = "<account>", format = "json")]
-pub async fn create_account(
- account: Json<Account>,
- user_data_db: UserDataDb,
-) -> CreateAccountResponder {
- let account = account.into_inner();
- let accounts_vec = vec![account.clone()];
-
- let num_rows_inserted = user_data_db
- .run(move |connection| insert_accounts(&accounts_vec, connection))
- .await;
-
- match num_rows_inserted {
- Ok(_) => CreateAccountResponder::Created(Json(account)),
- Err(err) => CreateAccountResponder::InternalServerError(format!(
- "Error creating account: {err}"
- )),
- }
-}
diff --git a/rust/schist_backend/src/routes/category.rs b/rust/schist_backend/src/routes/category.rs
deleted file mode 100644
index b2412ac..0000000
--- a/rust/schist_backend/src/routes/category.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use rocket::get;
-use rocket::http::Status;
-use rocket::serde::json::Json;
-use schist_models::category::Category;
-use schist_queries::categories::get_all_categories as get_all_categories_query;
-
-use crate::databases::UserDataDb;
-
-#[get("/category")]
-pub async fn get_all_categories(user_data_db: UserDataDb) -> Result<Json<Vec<Category>>, Status> {
- user_data_db
- .run(get_all_categories_query)
- .await
- .map(Json)
- .map_err(|_| Status { code: 500 })
-}
diff --git a/rust/schist_backend/src/routes/mod.rs b/rust/schist_backend/src/routes/mod.rs
deleted file mode 100644
index e22565c..0000000
--- a/rust/schist_backend/src/routes/mod.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub mod account;
-pub mod category;