diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 31000a2..464d816 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,21 +2,20 @@ name: Rust on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] env: CARGO_TERM_COLOR: always jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v3 + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose diff --git a/api/src/handlers/base.rs b/api/src/handlers/base.rs index 1109738..260d95b 100644 --- a/api/src/handlers/base.rs +++ b/api/src/handlers/base.rs @@ -17,7 +17,9 @@ pub async fn root_path() -> impl IntoResponse { pub async fn get_houses_web(State(database): State>) -> impl IntoResponse { let list_houses = HouseEntity::find().all(&database.db).await.unwrap(); - Records { houses: list_houses } + Records { + houses: list_houses, + } } pub async fn create_house_web( @@ -31,7 +33,9 @@ pub async fn create_house_web( ..Default::default() }; let insert_response = new_house.insert(&database.db).await.unwrap(); - HouseNewTemplate { house: insert_response }; + HouseNewTemplate { + house: insert_response, + }; } #[derive(Template)] diff --git a/api/src/handlers/room.rs b/api/src/handlers/room.rs index 1b3103f..1441e82 100644 --- a/api/src/handlers/room.rs +++ b/api/src/handlers/room.rs @@ -8,7 +8,7 @@ use entity::room::Entity as RoomEntity; use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set}; use uuid::Uuid; -use crate::models::room::{Room, CreateRoom}; +use crate::models::room::{CreateRoom, Room}; // Todo - Fix internal server error pub async fn list_rooms( diff --git a/api/src/lib.rs b/api/src/lib.rs index 66ced6d..f71764d 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -1,16 +1,16 @@ -use std::sync::Arc; use anyhow::Ok; use axum::serve; use migration::{Migrator, MigratorTrait}; use sea_orm::{Database, DatabaseConnection}; +use std::sync::Arc; use tokio::net::TcpListener; -pub mod routes; pub mod handlers; pub mod models; +pub mod routes; pub struct AppState { - db: DatabaseConnection, + db: DatabaseConnection, } #[tokio::main] @@ -18,15 +18,17 @@ async fn start() -> anyhow::Result<()> { dotenv::dotenv()?; let database_uri = dotenvy::var("DATABASE_URL")?; let db_connection = Database::connect(database_uri) - .await - .expect("Database connection failed"); + .await + .expect("Database connection failed"); Migrator::up(&db_connection, None).await?; // Initialize tracing tracing_subscriber::fmt::init(); - let app = routes::create_routes(Arc::new(AppState { db: db_connection.clone() })); + let app = routes::create_routes(Arc::new(AppState { + db: db_connection.clone(), + })); let listener = TcpListener::bind(&"0.0.0.0:3000").await.unwrap(); serve(listener, app).await?; @@ -35,9 +37,9 @@ async fn start() -> anyhow::Result<()> { } pub fn main() { - let result = start(); + let result = start(); - if let Some(err) = result.err() { - println!("Error: {err}"); - } + if let Some(err) = result.err() { + println!("Error: {err}"); + } } diff --git a/api/src/models/house.rs b/api/src/models/house.rs index 2d51871..5f80a16 100644 --- a/api/src/models/house.rs +++ b/api/src/models/house.rs @@ -17,22 +17,21 @@ pub struct CreateHouse { } pub struct DeleteResponse { - pub success: bool, - pub message: String, + pub success: bool, + pub message: String, } - // validations impl CreateHouse { - pub fn validate(&self) -> Result<(), String> { - if self.title.trim().is_empty() { - return Err("Name is empty".to_string()); - } - if self.body.trim().is_empty() { - return Err("Description is empty".to_string()); - } - Ok(()) - } + pub fn validate(&self) -> Result<(), String> { + if self.title.trim().is_empty() { + return Err("Name is empty".to_string()); + } + if self.body.trim().is_empty() { + return Err("Description is empty".to_string()); + } + Ok(()) + } } // impl NewHouse { diff --git a/api/src/models/item.rs b/api/src/models/item.rs index 7e9f774..b3ac1f9 100644 --- a/api/src/models/item.rs +++ b/api/src/models/item.rs @@ -11,7 +11,7 @@ pub struct Item { pub category: String, pub purchase_date: String, pub expiry_date: Option, - pub value: f64 + pub value: f64, } /// New Item. @@ -23,7 +23,7 @@ pub struct NewItem { pub category: String, pub purchase_date: String, pub expiry_date: Option, - pub value: f64 + pub value: f64, } #[derive(Deserialize)] @@ -33,10 +33,10 @@ pub struct ItemQuery { // validations impl NewItem { - pub fn validate(&self) -> Result<(), String> { - if self.name.trim().is_empty() { - return Err("Name is empty".to_string()); - } - Ok(()) - } + pub fn validate(&self) -> Result<(), String> { + if self.name.trim().is_empty() { + return Err("Name is empty".to_string()); + } + Ok(()) + } } diff --git a/api/src/models/room.rs b/api/src/models/room.rs index 5d64653..90e5852 100644 --- a/api/src/models/room.rs +++ b/api/src/models/room.rs @@ -23,10 +23,10 @@ pub struct CreateRoom { // validations impl CreateRoom { - pub fn validate(&self) -> Result<(), String> { - if self.name.trim().is_empty() { - return Err("Name is empty".to_string()); - } - Ok(()) - } + pub fn validate(&self) -> Result<(), String> { + if self.name.trim().is_empty() { + return Err("Name is empty".to_string()); + } + Ok(()) + } } diff --git a/api/templates/base.html b/api/templates/base.html index 1eb0b88..08ee724 100644 --- a/api/templates/base.html +++ b/api/templates/base.html @@ -1,14 +1,20 @@ - + - - - {% block title %}{{ title }} - My Site{% endblock %} + + + {% block title %}{{ title }} - My Site{% endblock %} {% block head %}{% endblock %}
- {% block content %}

Placeholder content

{% endblock %} + {% block content %} +

Placeholder content

+ {% endblock %}
diff --git a/api/templates/house.html b/api/templates/house.html index d86a86a..c4553cd 100644 --- a/api/templates/house.html +++ b/api/templates/house.html @@ -1,8 +1,15 @@ - {{ house.id }} - {{ house.title }} - {{ house.body }} - - - + {{ house.id }} + {{ house.title }} + {{ house.body }} + + + diff --git a/api/templates/houses.html b/api/templates/houses.html index 8a86533..4aa9348 100644 --- a/api/templates/houses.html +++ b/api/templates/houses.html @@ -9,9 +9,7 @@ - {% for house in houses %} - {% include "house.html" %} - {% endfor %} + {% for house in houses %} {% include "house.html" %} {% endfor %} diff --git a/api/templates/index.html b/api/templates/index.html index f044830..6524fc9 100644 --- a/api/templates/index.html +++ b/api/templates/index.html @@ -1,15 +1,25 @@ -{% extends "base.html" %} - -{% block title %}Index{% endblock %} - -{% block content %} +{% extends "base.html" %} {% block title %}Index{% endblock %} {% block content +%}

Inventory App

- - - + + +
-
+
Loading...
{% endblock %} diff --git a/api/templates/styles.css b/api/templates/styles.css index aeed300..f3d0c70 100644 --- a/api/templates/styles.css +++ b/api/templates/styles.css @@ -1,11 +1,13 @@ #content { - display: flex; - flex-direction: column; - align-items: center; - gap: 1rem; + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; } -table, th, td { +table, +th, +td { border: 1px solid black; - padding: 0.25rem; + padding: 0.25rem; } diff --git a/src/main.rs b/src/main.rs index 3c09a22..a255f51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { - inventory_api::main(); + inventory_api::main(); }