Skip to content

Commit

Permalink
Introduce Sessions, Yeet .eslintrc
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Jul 29, 2024
1 parent 89a7aff commit 58c1df9
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 116 deletions.
1 change: 0 additions & 1 deletion engine/src/auth/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct ActiveUser {

pub enum AuthToken {
Active(ActiveUser),
Error(Error),
None,
}

Expand Down
47 changes: 40 additions & 7 deletions engine/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ use poem::{
EndpointExt, Route, Server,
};
use poem_openapi::{param::Query, payload::PlainText, OpenApi, OpenApiService};
use reqwest::StatusCode;

use crate::{models::{media::Media, product::Product, property::Property}, state::AppState};
use crate::{
auth::{middleware::AuthToken, session::SessionState},
models::{media::Media, product::Product, property::Property},
state::AppState,
};

pub mod auth;

Expand Down Expand Up @@ -42,16 +47,22 @@ impl Api {
}

#[oai(path = "/media/:media_id", method = "get")]
async fn get_media(&self, state: Data<&Arc<AppState>>, media_id: Path<i32>) -> poem_openapi::payload::Json<Media> {
let media = Media::get_by_id(media_id.0, &state.database)
.await
.unwrap();
async fn get_media(
&self,
state: Data<&Arc<AppState>>,
media_id: Path<i32>,
) -> poem_openapi::payload::Json<Media> {
let media = Media::get_by_id(media_id.0, &state.database).await.unwrap();

poem_openapi::payload::Json(media)
}

#[oai(path = "/product/:product_id", method = "get")]
async fn get_product(&self, state: Data<&Arc<AppState>>, product_id: Path<i32>) -> poem_openapi::payload::Json<Product> {
async fn get_product(
&self,
state: Data<&Arc<AppState>>,
product_id: Path<i32>,
) -> poem_openapi::payload::Json<Product> {
let product = Product::get_by_id(product_id.0, &state.database)
.await
.unwrap();
Expand All @@ -60,13 +71,35 @@ impl Api {
}

#[oai(path = "/property/:property_id", method = "get")]
async fn get_property(&self, state: Data<&Arc<AppState>>, property_id: Path<i32>) -> poem_openapi::payload::Json<Property> {
async fn get_property(
&self,
state: Data<&Arc<AppState>>,
property_id: Path<i32>,
) -> poem_openapi::payload::Json<Property> {
let property = Property::get_by_id(property_id.0, &state.database)
.await
.unwrap();

poem_openapi::payload::Json(property)
}

#[oai(path = "/sessions", method = "get")]
async fn get_sessions(
&self,
auth: AuthToken,
state: Data<&Arc<AppState>>,
) -> poem_openapi::payload::Json<Vec<SessionState>> {
match auth {
AuthToken::Active(active_user) => {
let sessions = SessionState::get_by_user_id(active_user.session.user_id, &state.database)
.await
.unwrap();

poem_openapi::payload::Json(sessions)
}
_ => poem_openapi::payload::Json(vec![]),
}
}
}

// returns the html from the index.html file
Expand Down
19 changes: 0 additions & 19 deletions web/.eslintrc.json

This file was deleted.

6 changes: 5 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "vite",
"build": "vite build",
"lint": "eslint -c .eslintrc.json --ext .ts ./src"
"lint": "eslint"
},
"keywords": [],
"author": "",
"license": "GPL-3",
"dependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.8.0",
"@tanstack/react-router": "^1.45.14",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.19",
"eslint-plugin-unused-imports": "^4.0.1",
"globals": "^15.8.0",
"postcss": "^8.4.38",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
Loading

0 comments on commit 58c1df9

Please sign in to comment.