From 9c6b9d173cfa5ede2cdd652dc53b1d6d3c6f09c6 Mon Sep 17 00:00:00 2001 From: Johannes Heuel Date: Mon, 22 Aug 2022 19:57:54 +0200 Subject: [PATCH 1/3] disable border --- frontend/src/gallery/grid.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/gallery/grid.rs b/frontend/src/gallery/grid.rs index cd74c29..5e9efd5 100644 --- a/frontend/src/gallery/grid.rs +++ b/frontend/src/gallery/grid.rs @@ -127,7 +127,7 @@ pub fn grid(props: &GridProps) -> Html { "display: flex;", "flex-wrap: wrap;", "flex-direction: row;", - "border: 1px solid black;", + //"border: 1px solid black;", )}> { props.pictures.iter().zip(dimensions).map(|(p, d)| html!{} From 12e5c79a5ea65118257dae88b8fd012bd89eb109 Mon Sep 17 00:00:00 2001 From: Johannes Heuel Date: Mon, 22 Aug 2022 20:07:39 +0200 Subject: [PATCH 2/3] add pre-commit config --- .env | 2 +- .pre-commit-config.yaml | 13 ++++++++++++ backend/Cargo.toml | 2 +- .../2022-04-12-165834_create_photos/down.sql | 2 +- .../2022-04-12-165834_create_photos/up.sql | 2 +- backend/src/actions.rs | 6 +++--- backend/src/bin/add_picture.rs | 20 +++++++++---------- backend/src/bin/show_pictures.rs | 4 ++-- backend/src/lib.rs | 13 ++++++------ common/Cargo.toml | 2 +- common/src/lib.rs | 4 ++-- frontend/src/gallery/mod.rs | 2 +- src/main.rs | 2 +- 13 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.env b/.env index d6706b6..f5eae95 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -DATABASE_URL=postgres://user:password@localhost/diesel_demo \ No newline at end of file +DATABASE_URL=postgres://user:password@localhost/diesel_demo diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..009d9cc --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/doublify/pre-commit-rust + rev: master + hooks: + - id: fmt + - id: cargo-check diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 0a5a1e1..32aec28 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -19,4 +19,4 @@ dotenv = "0.15.0" walkdir = "2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -common = { path = "../common" } \ No newline at end of file +common = { path = "../common" } diff --git a/backend/migrations/2022-04-12-165834_create_photos/down.sql b/backend/migrations/2022-04-12-165834_create_photos/down.sql index 33a3a43..5b73e6f 100644 --- a/backend/migrations/2022-04-12-165834_create_photos/down.sql +++ b/backend/migrations/2022-04-12-165834_create_photos/down.sql @@ -1 +1 @@ -DROP TABLE pictures \ No newline at end of file +DROP TABLE pictures diff --git a/backend/migrations/2022-04-12-165834_create_photos/up.sql b/backend/migrations/2022-04-12-165834_create_photos/up.sql index d6843f3..52ce61b 100644 --- a/backend/migrations/2022-04-12-165834_create_photos/up.sql +++ b/backend/migrations/2022-04-12-165834_create_photos/up.sql @@ -15,4 +15,4 @@ CREATE TABLE pictures ( exposure_program VARCHAR, exposure_compensation VARCHAR, thumbnail VARCHAR -) \ No newline at end of file +) diff --git a/backend/src/actions.rs b/backend/src/actions.rs index 0576e8c..f393ee8 100644 --- a/backend/src/actions.rs +++ b/backend/src/actions.rs @@ -1,16 +1,16 @@ extern crate diesel; use backend::models::*; -use diesel::prelude::*; use backend::*; +use diesel::prelude::*; type DbError = Box; pub fn list_pictures(conn: &PgConnection) -> Result, DbError> { use self::schema::pictures::dsl::*; - + Ok(pictures .limit(50) .order_by(created_at.desc()) .load::(conn)?) -} \ No newline at end of file +} diff --git a/backend/src/bin/add_picture.rs b/backend/src/bin/add_picture.rs index 492e7a8..b0c5cea 100644 --- a/backend/src/bin/add_picture.rs +++ b/backend/src/bin/add_picture.rs @@ -1,7 +1,7 @@ extern crate diesel; use backend::create_picture; -use backend::models::NewPicture; use backend::establish_connection; +use backend::models::NewPicture; // use backend::*; use std::ffi::OsStr; @@ -123,17 +123,18 @@ fn main() { println!("pe = {}", serde_json::to_string_pretty(pe).unwrap()); - let created_at: Option = if let Some(c) = pe.created_at { Some(c) } else { let metadata = fs::metadata(&path.path()).unwrap(); if let Ok(time) = metadata.created() { - Some(time.duration_since(UNIX_EPOCH) - .unwrap() - .as_secs() - .try_into() - .unwrap()) + Some( + time.duration_since(UNIX_EPOCH) + .unwrap() + .as_secs() + .try_into() + .unwrap(), + ) } else { println!("Not supported on this platform or filesystem"); None @@ -161,10 +162,7 @@ fn main() { }; let pic = create_picture(&connection, new_picture); - println!( - "Created picture with filepath={} and id={}", - filepath, pic - ); + println!("Created picture with filepath={} and id={}", filepath, pic); }); } diff --git a/backend/src/bin/show_pictures.rs b/backend/src/bin/show_pictures.rs index 4585629..5045882 100644 --- a/backend/src/bin/show_pictures.rs +++ b/backend/src/bin/show_pictures.rs @@ -1,8 +1,8 @@ extern crate diesel; use self::models::*; -use diesel::prelude::*; use backend::*; +use diesel::prelude::*; fn main() { use self::schema::pictures::dsl::*; @@ -18,4 +18,4 @@ fn main() { println!("filepath: {}", picture.filepath); println!("\tid: {}", picture.id); } -} \ No newline at end of file +} diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 4890174..960f2b7 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -5,17 +5,16 @@ extern crate dotenv; pub mod models; pub mod schema; -use self::models::{NewPicture}; -use diesel::prelude::*; +use self::models::NewPicture; use diesel::pg::PgConnection; +use diesel::prelude::*; use dotenv::dotenv; use std::env; pub fn establish_connection() -> PgConnection { dotenv().ok(); - let database_url = env::var("DATABASE_URL") - .expect("DATABASE_URL must be set"); + let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set"); PgConnection::establish(&database_url) .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) } @@ -24,7 +23,7 @@ pub fn create_picture<'a>(conn: &PgConnection, new_picture: NewPicture) -> usize use schema::pictures; diesel::insert_into(pictures::table) - .values(&new_picture) - .execute(conn) - .expect("Error saving new picture") + .values(&new_picture) + .execute(conn) + .expect("Error saving new picture") } diff --git a/common/Cargo.toml b/common/Cargo.toml index 108e5ea..8da4d72 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -7,4 +7,4 @@ license = "MIT" [dependencies] serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" \ No newline at end of file +serde_json = "1.0" diff --git a/common/src/lib.rs b/common/src/lib.rs index 17e3884..e090865 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,6 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; -#[derive(Serialize,Deserialize,Debug,Clone,PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct OutputPicture { pub thumbnail: Option, pub width: u32, diff --git a/frontend/src/gallery/mod.rs b/frontend/src/gallery/mod.rs index 9e8e28f..d6f95a3 100644 --- a/frontend/src/gallery/mod.rs +++ b/frontend/src/gallery/mod.rs @@ -2,4 +2,4 @@ pub mod grid; pub use grid::Grid; pub mod picture; -pub use picture::Picture; \ No newline at end of file +pub use picture::Picture; diff --git a/src/main.rs b/src/main.rs index bcf2929..623ab5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { println!("Hello world!") -} \ No newline at end of file +} From 20c61d76f3d12f5a5b038c84245f40c3f73ea6da Mon Sep 17 00:00:00 2001 From: Johannes Heuel Date: Mon, 22 Aug 2022 20:49:24 +0200 Subject: [PATCH 3/3] add github workflow --- .github/workflows/rust.yml | 33 +++++++++++++++++++++++++++++++++ backend/src/main.rs | 27 --------------------------- 2 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..5d74df1 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,33 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + name: pre-commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 + test: + name: tests + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + + - name: Run cargo test + uses: actions-rs/cargo@v1 + with: + command: test diff --git a/backend/src/main.rs b/backend/src/main.rs index db18daf..874cb52 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -114,30 +114,3 @@ async fn main() -> std::io::Result<()> { .run() .await } - -#[cfg(test)] -mod tests { - use super::*; - use actix_web::test; - - #[actix_web::test] - async fn user_routes() { - std::env::set_var("RUST_LOG", "actix_web=debug"); - env_logger::init(); - dotenv::dotenv().ok(); - - let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL"); - let manager = ConnectionManager::::new(connspec); - let pool = r2d2::Pool::builder() - .build(manager) - .expect("Failed to create pool."); - - let _app = test::init_service( - App::new() - .app_data(web::Data::new(pool.clone())) - .wrap(middleware::Logger::default()), // .service(get_user) - // .service(add_user), - ) - .await; - } -}