refactor: WIP splitting crates
This commit is contained in:
parent
f25e508bbd
commit
f35b343768
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -787,6 +787,15 @@ dependencies = [
|
|||||||
"dotenvy",
|
"dotenvy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "brass-db"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"garde",
|
||||||
|
"sqlx",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "brass-macros"
|
name = "brass-macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -809,6 +818,7 @@ dependencies = [
|
|||||||
"argon2",
|
"argon2",
|
||||||
"askama",
|
"askama",
|
||||||
"brass-config",
|
"brass-config",
|
||||||
|
"brass-db",
|
||||||
"brass-macros",
|
"brass-macros",
|
||||||
"built",
|
"built",
|
||||||
"change-detection",
|
"change-detection",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [ "cli", "config", "macros", "web", ]
|
members = [ "cli", "config", "db", "macros", "web", ]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
default-members = ["web"]
|
default-members = ["web"]
|
||||||
|
|
||||||
|
12
db/Cargo.toml
Normal file
12
db/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "brass-db"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
license = "AGPL-3.0"
|
||||||
|
authors = ["Max Hohlfeld <maxhohlfeld@posteo.de>"]
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
sqlx = { version = "^0.8", features = ["runtime-async-std-rustls", "postgres", "chrono"] }
|
||||||
|
chrono = { version = "0.4.33", features = ["serde", "now"] }
|
||||||
|
garde = { version = "0.22.0", features = ["derive", "email"] }
|
24
db/src/lib.rs
Normal file
24
db/src/lib.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
mod models;
|
||||||
|
|
||||||
|
pub use models::area::Area;
|
||||||
|
pub use models::assignment::Assignment;
|
||||||
|
pub use models::assignment_changeset::{AssignmentChangeset, AssignmentContext};
|
||||||
|
pub use models::availability::Availability;
|
||||||
|
pub use models::availability_assignment_state::AvailabilityAssignmentState;
|
||||||
|
pub use models::availability_changeset::{
|
||||||
|
AvailabilityChangeset, AvailabilityContext, find_free_date_time_slots,
|
||||||
|
};
|
||||||
|
pub use models::clothing::Clothing;
|
||||||
|
pub use models::event::Event;
|
||||||
|
pub use models::event_changeset::{EventChangeset, EventContext};
|
||||||
|
pub use models::export_event_row::{ExportEventRow, SimpleAssignment};
|
||||||
|
pub use models::function::Function;
|
||||||
|
pub use models::location::Location;
|
||||||
|
pub use models::password_reset::{NoneToken, PasswordReset, Token};
|
||||||
|
pub use models::registration::Registration;
|
||||||
|
pub use models::role::Role;
|
||||||
|
pub use models::user::User;
|
||||||
|
pub use models::user_changeset::UserChangeset;
|
||||||
|
pub use models::user_funtion::UserFunction;
|
||||||
|
pub use models::vehicle::Vehicle;
|
||||||
|
pub use models::vehicle_assignment::VehicleAssignment;
|
@ -1,7 +1,8 @@
|
|||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use sqlx::{query, PgPool};
|
use sqlx::{PgPool, query};
|
||||||
|
|
||||||
use super::{assignment_changeset::AssignmentChangeset, Function, Result};
|
use super::Result;
|
||||||
|
use crate::{AssignmentChangeset, Function};
|
||||||
|
|
||||||
pub struct Assignment {
|
pub struct Assignment {
|
||||||
pub event_id: i32,
|
pub event_id: i32,
|
@ -1,8 +1,9 @@
|
|||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use garde::Validate;
|
use garde::Validate;
|
||||||
|
|
||||||
use super::{
|
use crate::{
|
||||||
start_date_time_lies_before_end_date_time, Assignment, Availability, Event, Function, UserFunction,
|
Assignment, Availability, Event, Function, UserFunction,
|
||||||
|
models::start_date_time_lies_before_end_date_time,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Validate)]
|
#[derive(Validate)]
|
||||||
@ -64,9 +65,7 @@ fn event_has_free_slot_for_function(
|
|||||||
let list: Vec<&Assignment> = context
|
let list: Vec<&Assignment> = context
|
||||||
.assignments_for_event
|
.assignments_for_event
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|a| {
|
.filter(|a| a.availability_id != context.availability.id && a.event_id != context.event.id)
|
||||||
a.availability_id != context.availability.id && a.event_id != context.event.id
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let a = list
|
let a = list
|
||||||
@ -93,9 +92,7 @@ fn availability_not_already_assigned(
|
|||||||
let list: Vec<&Assignment> = context
|
let list: Vec<&Assignment> = context
|
||||||
.assignments_for_availability
|
.assignments_for_availability
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|a| {
|
.filter(|a| a.availability_id != context.availability.id && a.event_id != context.event.id)
|
||||||
a.availability_id != context.availability.id && a.event_id != context.event.id
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let has_start_time_during_assignment =
|
let has_start_time_during_assignment =
|
@ -1,7 +1,8 @@
|
|||||||
use chrono::{NaiveDate, NaiveDateTime};
|
use chrono::{NaiveDate, NaiveDateTime};
|
||||||
use sqlx::{query, PgPool};
|
use sqlx::{PgPool, query};
|
||||||
|
|
||||||
use super::{Area, AvailabilityChangeset, Result, Role, User, UserFunction};
|
use super::Result;
|
||||||
|
use crate::{Area, AvailabilityChangeset, Role, User, UserFunction};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Availability {
|
pub struct Availability {
|
35
db/src/models/mod.rs
Normal file
35
db/src/models/mod.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
pub mod area;
|
||||||
|
pub mod assignment;
|
||||||
|
pub mod assignment_changeset;
|
||||||
|
pub mod availability;
|
||||||
|
pub mod availability_assignment_state;
|
||||||
|
pub mod availability_changeset;
|
||||||
|
pub mod clothing;
|
||||||
|
pub mod event;
|
||||||
|
pub mod event_changeset;
|
||||||
|
pub mod export_event_row;
|
||||||
|
pub mod function;
|
||||||
|
pub mod location;
|
||||||
|
pub mod password_reset;
|
||||||
|
pub mod registration;
|
||||||
|
pub mod role;
|
||||||
|
pub mod user;
|
||||||
|
pub mod user_changeset;
|
||||||
|
pub mod user_funtion;
|
||||||
|
pub mod vehicle;
|
||||||
|
pub mod vehicle_assignment;
|
||||||
|
|
||||||
|
use chrono::NaiveDateTime;
|
||||||
|
|
||||||
|
type Result<T> = std::result::Result<T, sqlx::Error>;
|
||||||
|
|
||||||
|
fn start_date_time_lies_before_end_date_time<T>(
|
||||||
|
value: &(NaiveDateTime, NaiveDateTime),
|
||||||
|
_context: &T,
|
||||||
|
) -> garde::Result {
|
||||||
|
if value.0 >= value.1 {
|
||||||
|
return Err(garde::Error::new("endtime can't lie before starttime"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -28,6 +28,7 @@ zxcvbn = "3.1.0"
|
|||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
brass-macros = { path = "../macros" }
|
brass-macros = { path = "../macros" }
|
||||||
brass-config = { path = "../config" }
|
brass-config = { path = "../config" }
|
||||||
|
brass-db = { path = "../db" }
|
||||||
actix-http = "3.9.0"
|
actix-http = "3.9.0"
|
||||||
askama = "0.13.0"
|
askama = "0.13.0"
|
||||||
garde = { version = "0.22.0", features = ["derive", "email"] }
|
garde = { version = "0.22.0", features = ["derive", "email"] }
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
mod area;
|
|
||||||
mod assignment;
|
|
||||||
mod assignment_changeset;
|
|
||||||
mod availability;
|
|
||||||
mod availability_assignment_state;
|
|
||||||
mod availability_changeset;
|
|
||||||
mod clothing;
|
|
||||||
mod event;
|
|
||||||
mod event_changeset;
|
|
||||||
mod export_event_row;
|
|
||||||
mod function;
|
|
||||||
mod location;
|
|
||||||
mod password_reset;
|
|
||||||
mod registration;
|
|
||||||
mod role;
|
|
||||||
mod user;
|
|
||||||
mod user_changeset;
|
|
||||||
mod user_funtion;
|
|
||||||
mod vehicle;
|
|
||||||
mod vehicle_assignment;
|
|
||||||
|
|
||||||
pub use area::Area;
|
|
||||||
pub use assignment::Assignment;
|
|
||||||
pub use assignment_changeset::{AssignmentChangeset, AssignmentContext};
|
|
||||||
pub use availability::Availability;
|
|
||||||
pub use availability_assignment_state::AvailabilityAssignmentState;
|
|
||||||
pub use availability_changeset::{
|
|
||||||
find_free_date_time_slots, AvailabilityChangeset, AvailabilityContext,
|
|
||||||
};
|
|
||||||
pub use clothing::Clothing;
|
|
||||||
pub use event::Event;
|
|
||||||
pub use event_changeset::{EventChangeset, EventContext};
|
|
||||||
pub use export_event_row::{ExportEventRow, SimpleAssignment};
|
|
||||||
pub use function::Function;
|
|
||||||
pub use location::Location;
|
|
||||||
pub use password_reset::{NoneToken, PasswordReset, Token};
|
|
||||||
pub use registration::Registration;
|
|
||||||
pub use role::Role;
|
|
||||||
pub use user::User;
|
|
||||||
pub use user_changeset::UserChangeset;
|
|
||||||
pub use user_funtion::UserFunction;
|
|
||||||
pub use vehicle::Vehicle;
|
|
||||||
pub use vehicle_assignment::VehicleAssignment;
|
|
||||||
|
|
||||||
use chrono::NaiveDateTime;
|
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, sqlx::Error>;
|
|
||||||
|
|
||||||
fn start_date_time_lies_before_end_date_time<T>(
|
|
||||||
value: &(NaiveDateTime, NaiveDateTime),
|
|
||||||
_context: &T,
|
|
||||||
) -> garde::Result {
|
|
||||||
if value.0 >= value.1 {
|
|
||||||
return Err(garde::Error::new("endtime can't lie before starttime"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user