feat: add image models
							parent
							
								
									3568365c6f
								
							
						
					
					
						commit
						c10b9baa95
					
				|  | @ -157,6 +157,7 @@ dependencies = [ | |||
|  "matchit", | ||||
|  "memchr", | ||||
|  "mime", | ||||
|  "multer", | ||||
|  "percent-encoding", | ||||
|  "pin-project-lite", | ||||
|  "rustversion", | ||||
|  | @ -634,6 +635,15 @@ version = "1.13.0" | |||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "encoding_rs" | ||||
| version = "0.8.35" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" | ||||
| dependencies = [ | ||||
|  "cfg-if", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "equivalent" | ||||
| version = "1.0.1" | ||||
|  | @ -1053,6 +1063,23 @@ dependencies = [ | |||
|  "windows-sys 0.52.0", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "multer" | ||||
| version = "3.1.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" | ||||
| dependencies = [ | ||||
|  "bytes", | ||||
|  "encoding_rs", | ||||
|  "futures-util", | ||||
|  "http", | ||||
|  "httparse", | ||||
|  "memchr", | ||||
|  "mime", | ||||
|  "spin", | ||||
|  "version_check", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "nu-ansi-term" | ||||
| version = "0.46.0" | ||||
|  | @ -1533,6 +1560,12 @@ dependencies = [ | |||
|  "windows-sys 0.52.0", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| name = "spin" | ||||
| version = "0.9.8" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" | ||||
| 
 | ||||
| [[package]] | ||||
| name = "strsim" | ||||
| version = "0.11.1" | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ name = "calathea" | |||
| 
 | ||||
| [dependencies] | ||||
| argon2 = "0.5.3" | ||||
| axum = { version = "0.8.0", features = ["macros"] } | ||||
| axum = { version = "0.8.0", features = ["macros", "multipart"] } | ||||
| axum-extra = { version = "0.10.0", features = ["cookie"] } | ||||
| chrono = { version = "0.4.39", features = ["serde"] } | ||||
| clap = { version = "4.5.26", features = ["derive", "env"] } | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| drop table images; | ||||
|  | @ -0,0 +1,9 @@ | |||
| create table images ( | ||||
|     id integer primary key not null, | ||||
|     plant_id integer not null | ||||
|         references plants (id) | ||||
|         -- Keep entries in the database so the files can be removed later | ||||
|         on delete set null, | ||||
|     date_taken date not null, | ||||
|     note text | ||||
| ); | ||||
|  | @ -0,0 +1,33 @@ | |||
| use diesel::prelude::*; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use chrono::NaiveDate; | ||||
| 
 | ||||
| use crate::db::{schema::*, DbPool, DbResult}; | ||||
| 
 | ||||
| #[derive(Serialize, Queryable, Selectable)] | ||||
| #[diesel(table_name = images)] | ||||
| #[diesel(check_for_backend(diesel::sqlite::Sqlite))] | ||||
| pub struct Image { | ||||
|     id: i32, | ||||
|     plant_id: i32, | ||||
|     date_taken: NaiveDate, | ||||
|     note: Option<String>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Deserialize, Insertable)] | ||||
| #[diesel(table_name = images)] | ||||
| #[diesel(check_for_backend(diesel::sqlite::Sqlite))] | ||||
| pub struct NewImage { | ||||
|     plant_id: i32, | ||||
|     date_taken: NaiveDate, | ||||
|     note: Option<String>, | ||||
| } | ||||
| 
 | ||||
| impl NewImage { | ||||
|     pub fn insert(self, pool: &DbPool) -> DbResult<Image> { | ||||
|         Ok(self | ||||
|             .insert_into(images::table) | ||||
|             .returning(Image::as_returning()) | ||||
|             .get_result(&mut pool.get()?)?) | ||||
|     } | ||||
| } | ||||
|  | @ -2,3 +2,4 @@ pub mod event; | |||
| pub mod plant; | ||||
| pub mod session; | ||||
| pub mod user; | ||||
| pub mod image; | ||||
|  |  | |||
|  | @ -10,6 +10,15 @@ diesel::table! { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| diesel::table! { | ||||
|     images (id) { | ||||
|         id -> Integer, | ||||
|         plant_id -> Integer, | ||||
|         date_taken -> Date, | ||||
|         note -> Nullable<Text>, | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| diesel::table! { | ||||
|     plants (id) { | ||||
|         id -> Integer, | ||||
|  | @ -36,6 +45,13 @@ diesel::table! { | |||
| } | ||||
| 
 | ||||
| diesel::joinable!(events -> plants (plant_id)); | ||||
| diesel::joinable!(images -> plants (plant_id)); | ||||
| diesel::joinable!(sessions -> users (user_id)); | ||||
| 
 | ||||
| diesel::allow_tables_to_appear_in_same_query!(events, plants, sessions, users,); | ||||
| diesel::allow_tables_to_appear_in_same_query!( | ||||
|     events, | ||||
|     images, | ||||
|     plants, | ||||
|     sessions, | ||||
|     users, | ||||
| ); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue