Implemented data model, database schema and database connection pool.
This commit is contained in:
@@ -0,0 +1,70 @@
|
|||||||
|
CREATE TABLE company (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR NOT NULL,
|
||||||
|
street VARCHAR,
|
||||||
|
house_number VARCHAR,
|
||||||
|
zip_code VARCHAR,
|
||||||
|
city VARCHAR
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "user" (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
login VARCHAR NOT NULL,
|
||||||
|
password VARCHAR NOT NULL,
|
||||||
|
full_name VARCHAR,
|
||||||
|
email VARCHAR,
|
||||||
|
admin bool,
|
||||||
|
get_emails bool
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE property (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR NOT NULL,
|
||||||
|
description VARCHAR,
|
||||||
|
price NUMERIC(9, 2) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TYPE message_type AS ENUM ('NewReservation', 'NewReservationCust', 'ReservationApp', 'ReservationCanceled');
|
||||||
|
|
||||||
|
CREATE TABLE message (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
msg_type message_type NOT NULL ,
|
||||||
|
subject VARCHAR NOT NULL ,
|
||||||
|
"text" TEXT NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE opening_hour (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
day INTEGER NOT NULL ,
|
||||||
|
"from" TIME NOT NULL ,
|
||||||
|
"to" TIME NOT NULL,
|
||||||
|
discount INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE customer (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
full_name VARCHAR NOT NULL,
|
||||||
|
email VARCHAR NOT NULL,
|
||||||
|
phone VARCHAR,
|
||||||
|
discount INTEGER
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TYPE reservation_state AS ENUM ('New', 'Approved', 'Canceled');
|
||||||
|
|
||||||
|
CREATE TABLE reservation_sum (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
uuid uuid NOT NULL,
|
||||||
|
date DATE NOT NULL,
|
||||||
|
customer BIGINT REFERENCES customer(id) NOT NULL,
|
||||||
|
price NUMERIC(9, 2) NOT NULL,
|
||||||
|
state reservation_state
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE reservation (
|
||||||
|
id BIGSERIAL PRIMARY KEY,
|
||||||
|
"from" TIME NOT NULL,
|
||||||
|
"to" TIME NOT NULL,
|
||||||
|
property INTEGER REFERENCES property(id) NOT NULL,
|
||||||
|
summary BIGINT REFERENCES reservation_sum(id) NOT NULL
|
||||||
|
);
|
||||||
@@ -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 home_page;
|
||||||
pub mod server_fn;
|
pub mod server_fn;
|
||||||
pub mod locales;
|
pub mod locales;
|
||||||
|
pub mod backend;
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
|||||||
+11
-3
@@ -1,3 +1,6 @@
|
|||||||
|
use sqlx::migrate;
|
||||||
|
use sqlx::postgres::PgPoolOptions;
|
||||||
|
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
@@ -6,10 +9,11 @@ async fn main() -> std::io::Result<()> {
|
|||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_actix::{generate_route_list, LeptosRoutes};
|
use leptos_actix::{generate_route_list, LeptosRoutes};
|
||||||
use rezervator::app::*;
|
use rezervator::app::*;
|
||||||
//use rezervator::server_fn::*;
|
use rezervator::backend::*;
|
||||||
use actix_session::storage::CookieSessionStore;
|
use actix_session::storage::CookieSessionStore;
|
||||||
use actix_session::SessionMiddleware;
|
use actix_session::SessionMiddleware;
|
||||||
use actix_web::cookie::Key;
|
use actix_web::cookie::Key;
|
||||||
|
use actix_web::web::Data;
|
||||||
|
|
||||||
let conf = get_configuration(None).await.unwrap();
|
let conf = get_configuration(None).await.unwrap();
|
||||||
let addr = conf.leptos_options.site_addr;
|
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 routes = generate_route_list(|cx| view! { cx, <App/> });
|
||||||
let key = Key::generate();
|
let key = Key::generate();
|
||||||
|
|
||||||
//SetSession::register();
|
let pool = PgPoolOptions::new()
|
||||||
//GetSession::register();
|
.max_connections(10)
|
||||||
|
.connect("postgres://pepa:mkoijn@localhost/rezervator").await.unwrap();
|
||||||
|
|
||||||
|
migrate!().run(&pool).await.expect("could not run SQLx migrations");
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
let leptos_options = &conf.leptos_options;
|
let leptos_options = &conf.leptos_options;
|
||||||
let site_root = &leptos_options.site_root;
|
let site_root = &leptos_options.site_root;
|
||||||
|
|
||||||
App::new()
|
App::new()
|
||||||
|
.app_data(Data::new(AppData::new(pool.clone())))
|
||||||
.wrap(SessionMiddleware::new(
|
.wrap(SessionMiddleware::new(
|
||||||
CookieSessionStore::default(),
|
CookieSessionStore::default(),
|
||||||
key.clone()
|
key.clone()
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ use leptos::*;
|
|||||||
pub async fn set_session(cx: Scope) -> Result<(), ServerFnError> {
|
pub async fn set_session(cx: Scope) -> Result<(), ServerFnError> {
|
||||||
use leptos_actix::extract;
|
use leptos_actix::extract;
|
||||||
use actix_session::*;
|
use actix_session::*;
|
||||||
|
use actix_web::web::Data;
|
||||||
|
//use crate::DataPok;
|
||||||
|
|
||||||
extract(cx, |session: Session| async move {
|
extract(cx, |session: Session| async move {
|
||||||
leptos::log!("extract");
|
leptos::log!("extract");
|
||||||
|
|||||||
Reference in New Issue
Block a user