Implemented data model, database schema and database connection pool.
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
use chrono::{NaiveDate, NaiveTime, Weekday};
|
||||
use rust_decimal::Decimal;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub struct Company {
|
||||
id: u16,
|
||||
name: String,
|
||||
street: String,
|
||||
house_number: String,
|
||||
zip_code: String,
|
||||
city: String,
|
||||
}
|
||||
|
||||
pub struct User {
|
||||
id: u16,
|
||||
login: String,
|
||||
password: String,
|
||||
full_name: String,
|
||||
email: String,
|
||||
admin: bool,
|
||||
get_emails: bool,
|
||||
}
|
||||
|
||||
pub struct Property {
|
||||
id: u16,
|
||||
name: String,
|
||||
description: String,
|
||||
price: Decimal
|
||||
}
|
||||
|
||||
pub enum MessageType {
|
||||
NewReservation,
|
||||
NewReservationCust,
|
||||
ReservationApp,
|
||||
ReservationCanceled,
|
||||
}
|
||||
|
||||
pub struct Message {
|
||||
id: u16,
|
||||
msg_type: MessageType,
|
||||
subject: String,
|
||||
text: String,
|
||||
}
|
||||
|
||||
pub struct OpeningHour {
|
||||
id: u16,
|
||||
day: Weekday,
|
||||
from: NaiveTime,
|
||||
to: NaiveTime,
|
||||
discount: u8
|
||||
}
|
||||
|
||||
pub struct Customer {
|
||||
id: u128,
|
||||
full_name: String,
|
||||
email: String,
|
||||
phone: String,
|
||||
discount: u8
|
||||
}
|
||||
|
||||
pub enum ReservationState {
|
||||
New,
|
||||
Approved,
|
||||
Canceled,
|
||||
}
|
||||
|
||||
pub struct Reservation {
|
||||
id: u128,
|
||||
from: NaiveTime,
|
||||
to: NaiveTime,
|
||||
property: Property,
|
||||
}
|
||||
|
||||
pub struct ReservationSum {
|
||||
id: u128,
|
||||
uuid: Uuid,
|
||||
date: NaiveDate,
|
||||
items: Vec<Reservation>,
|
||||
customer: Customer,
|
||||
price: Decimal,
|
||||
state: ReservationState,
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
pub mod data;
|
||||
|
||||
cfg_if!{
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use sqlx::PgPool;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppData {
|
||||
db_pool: PgPool
|
||||
}
|
||||
|
||||
impl AppData {
|
||||
pub fn new(db_pool: PgPool) -> Self {
|
||||
Self {
|
||||
db_pool
|
||||
}
|
||||
}
|
||||
|
||||
pub fn db_pool(&self) -> &PgPool {
|
||||
&self.db_pool
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ pub mod modal_box;
|
||||
pub mod home_page;
|
||||
pub mod server_fn;
|
||||
pub mod locales;
|
||||
pub mod backend;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
|
||||
+11
-3
@@ -1,3 +1,6 @@
|
||||
use sqlx::migrate;
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
@@ -6,10 +9,11 @@ async fn main() -> std::io::Result<()> {
|
||||
use leptos::*;
|
||||
use leptos_actix::{generate_route_list, LeptosRoutes};
|
||||
use rezervator::app::*;
|
||||
//use rezervator::server_fn::*;
|
||||
use rezervator::backend::*;
|
||||
use actix_session::storage::CookieSessionStore;
|
||||
use actix_session::SessionMiddleware;
|
||||
use actix_web::cookie::Key;
|
||||
use actix_web::web::Data;
|
||||
|
||||
let conf = get_configuration(None).await.unwrap();
|
||||
let addr = conf.leptos_options.site_addr;
|
||||
@@ -17,14 +21,18 @@ async fn main() -> std::io::Result<()> {
|
||||
let routes = generate_route_list(|cx| view! { cx, <App/> });
|
||||
let key = Key::generate();
|
||||
|
||||
//SetSession::register();
|
||||
//GetSession::register();
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(10)
|
||||
.connect("postgres://pepa:mkoijn@localhost/rezervator").await.unwrap();
|
||||
|
||||
migrate!().run(&pool).await.expect("could not run SQLx migrations");
|
||||
|
||||
HttpServer::new(move || {
|
||||
let leptos_options = &conf.leptos_options;
|
||||
let site_root = &leptos_options.site_root;
|
||||
|
||||
App::new()
|
||||
.app_data(Data::new(AppData::new(pool.clone())))
|
||||
.wrap(SessionMiddleware::new(
|
||||
CookieSessionStore::default(),
|
||||
key.clone()
|
||||
|
||||
@@ -4,6 +4,8 @@ use leptos::*;
|
||||
pub async fn set_session(cx: Scope) -> Result<(), ServerFnError> {
|
||||
use leptos_actix::extract;
|
||||
use actix_session::*;
|
||||
use actix_web::web::Data;
|
||||
//use crate::DataPok;
|
||||
|
||||
extract(cx, |session: Session| async move {
|
||||
leptos::log!("extract");
|
||||
|
||||
Reference in New Issue
Block a user