2023-08-29 21:34:00 +02:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
2023-08-29 21:34:00 +02:00
|
|
|
pub mod auth;
|
2023-08-29 21:34:00 +02:00
|
|
|
pub mod error;
|
2023-08-29 21:34:00 +02:00
|
|
|
pub mod htmx;
|
2023-08-29 21:34:00 +02:00
|
|
|
pub mod models;
|
|
|
|
|
pub mod routing;
|
|
|
|
|
pub mod sqlite;
|
2023-08-29 21:34:01 +02:00
|
|
|
pub mod telemetry;
|
2023-08-29 21:34:00 +02:00
|
|
|
|
|
|
|
|
mod view;
|
|
|
|
|
|
2023-08-29 21:34:00 +02:00
|
|
|
pub use error::{CommandError, Error, RequestError, StartError};
|
2023-08-29 21:34:00 +02:00
|
|
|
|
2023-08-29 21:34:01 +02:00
|
|
|
#[derive(Clone, Debug)]
|
2023-08-29 21:34:00 +02:00
|
|
|
pub struct AppState {
|
|
|
|
|
pub database_pool: sqlite::Pool<sqlite::Sqlite>,
|
|
|
|
|
pub client_state: ClientState,
|
2023-08-29 21:34:01 +02:00
|
|
|
pub auth_config: auth::Config,
|
2023-08-29 21:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-29 21:34:01 +02:00
|
|
|
#[derive(Clone, Debug)]
|
2023-08-29 21:34:00 +02:00
|
|
|
pub struct Context {
|
|
|
|
|
user: models::user::User,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Context {
|
|
|
|
|
fn build(user: models::user::User) -> Self {
|
|
|
|
|
Self { user }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 21:34:01 +02:00
|
|
|
#[derive(Clone, Debug)]
|
2023-08-29 21:34:00 +02:00
|
|
|
pub struct ClientState {
|
|
|
|
|
pub active_category_id: Option<Uuid>,
|
|
|
|
|
pub edit_item: Option<Uuid>,
|
|
|
|
|
pub trip_edit_attribute: Option<models::trips::TripAttribute>,
|
|
|
|
|
pub trip_type_edit: Option<Uuid>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ClientState {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
ClientState {
|
|
|
|
|
active_category_id: None,
|
|
|
|
|
edit_item: None,
|
|
|
|
|
trip_edit_attribute: None,
|
|
|
|
|
trip_type_edit: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for ClientState {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::new()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct UriPath(String);
|
|
|
|
|
|
|
|
|
|
impl fmt::Display for UriPath {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 21:34:01 +02:00
|
|
|
impl<'a> From<&'a UriPath> for &'a str {
|
|
|
|
|
fn from(val: &'a UriPath) -> Self {
|
|
|
|
|
val.0.as_str()
|
2023-08-29 21:34:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 21:34:01 +02:00
|
|
|
#[derive(PartialEq, Eq, Debug)]
|
2023-08-29 21:34:00 +02:00
|
|
|
pub enum TopLevelPage {
|
|
|
|
|
Inventory,
|
|
|
|
|
Trips,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TopLevelPage {
|
|
|
|
|
fn id(&self) -> &'static str {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Inventory => "inventory",
|
|
|
|
|
Self::Trips => "trips",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn path(&self) -> UriPath {
|
|
|
|
|
UriPath(
|
|
|
|
|
match self {
|
|
|
|
|
Self::Inventory => "/inventory/",
|
|
|
|
|
Self::Trips => "/trips/",
|
|
|
|
|
}
|
|
|
|
|
.to_string(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn name(&self) -> &'static str {
|
|
|
|
|
match self {
|
|
|
|
|
Self::Inventory => "Inventory",
|
|
|
|
|
Self::Trips => "Trips",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|