Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mobergmann committed Nov 25, 2023
1 parent 46a737f commit a72b6ab
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::sqlite::{SqliteConnectOptions};
use sqlx::{ConnectOptions, Executor, SqlitePool};
use std::str::FromStr;

Expand Down
4 changes: 2 additions & 2 deletions src/logic/account.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::account::{BareAccount, EditAccount};
use crate::database;
use crate::logic::AuthContext;
use axum::extract::State;

use crate::logic::auth::logout;

use axum::extract::State;
use axum::response::IntoResponse;
use axum::Json;
use http::StatusCode;
Expand Down
8 changes: 4 additions & 4 deletions src/logic/activities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn get_activity(
) -> impl IntoResponse {
let activity = match database::activity::get(pool, activity_id).await {
Ok(activity) => activity,
Err(Error::ElementNotFound) => return (StatusCode::NOT_FOUND).into_response(),
// Err(Error::ElementNotFound) => return (StatusCode::NOT_FOUND).into_response(),
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR).into_response(),
};

Expand Down Expand Up @@ -133,12 +133,12 @@ pub async fn edit_activity(
State(pool): State<&SqlitePool>,
mut auth: AuthContext,
Path(activity_id): Path<(i64)>,
Json(payload): Json<StringBareActivity>,
Json(payload): Json<BareActivity>, // todo string bare activity
) -> impl IntoResponse {
// get the referenced activity from the database
let activity = match database::activity::get(pool, activity_id).await {
Ok(activity) => activity,
Err(Error::ElementNotFound) => return (StatusCode::NOT_FOUND).into_response(),
// Err(Error::ElementNotFound) => return (StatusCode::NOT_FOUND).into_response(),
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR).into_response(),
};

Expand Down Expand Up @@ -168,7 +168,7 @@ pub async fn delete_activity(
// get the referenced activity from the database
let activity = match database::activity::get(pool, activity_id).await {
Ok(activity) => activity,
Err(Error::ElementNotFound) => return (StatusCode::NOT_FOUND).into_response(),
// Err(Error::ElementNotFound) => return (StatusCode::NOT_FOUND).into_response(),
// todo catch additional errors
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR).into_response(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/logic/auth.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::account::{Account, BareAccount};
use crate::database;
use crate::hasher;
use axum::extract::State;

use axum::extract::State;
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::Json;
Expand Down
5 changes: 3 additions & 2 deletions src/logic/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use axum::response::IntoResponse;
use axum::Json;
use http::StatusCode;
use sqlx::SqlitePool;
use crate::database::Error;

pub async fn get_user(
State(pool): State<&SqlitePool>,
Path(username): Path<String>,
) -> impl IntoResponse {
let user = match database::user::get(pool, &username).await {
Ok(user) => user,
Err(Error::ElementNotFound) => return (StatusCode::NO_CONTENT).into_response(),
// Err(Error::ElementNotFound) => return (StatusCode::NO_CONTENT).into_response(),
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR).into_response(),
};

Expand All @@ -25,7 +26,7 @@ pub async fn get_user_id(
) -> impl IntoResponse {
let user = match database::user::get_id(pool, user_id).await {
Ok(user) => user,
Err(Error::ElementNotFound) => return (StatusCode::NO_CONTENT).into_response(),
// Err(Error::ElementNotFound) => return (StatusCode::NO_CONTENT).into_response(),
Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR).into_response(),
};

Expand Down
3 changes: 1 addition & 2 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ pub async fn backend_router(pool: &SqlitePool) -> Router {
let session_layer = SessionLayer::new(session_store, &secret)
.with_secure(false)
.with_same_site_policy(SameSite::Lax);
let pool = SqlitePoolOptions::new().connect(DB_URI).await.unwrap();
let user_store = SqliteStore::<Account>::new(pool);
let user_store = SqliteStore::<Account>::new(pool.clone());
let auth_layer = AuthLayer::new(user_store, &secret);

let auth_router = Router::new()
Expand Down

0 comments on commit a72b6ab

Please sign in to comment.