Implemented settings for properties of reservation. Fixed bugs on empty database.

This commit is contained in:
2023-12-08 17:02:00 +01:00
parent d7e33e4342
commit 55ca93406a
14 changed files with 456 additions and 21 deletions
+45 -11
View File
@@ -2,9 +2,11 @@
//use rust_decimal::Decimal;
#![allow(unused_variables)]
use std::fmt::Display;
use chrono::{NaiveTime, Weekday};
use lazy_static::lazy_static;
use regex::Regex;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
//use uuid::Uuid;
use validator::{Validate, ValidationError};
@@ -162,19 +164,21 @@ impl DayHours {
}
}
impl ToString for DayHours {
fn to_string(&self) -> String {
impl Display for DayHours {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0.is_empty() {
return "".to_string()
return write!(f, "{}", "".to_string())
}
self.0.iter().map(|h| {
let str = self.0.iter().map(|h| {
let discount = if let Some(d) = h.discount() {
format!(" ({})", d).to_string()
} else { "".to_string() };
format!("{} - {}{}", h.from().format("%H:%M"), h.to().format("%H:%M"), discount).to_string()})
format!("{} - {}{}", h.from().format("%H:%M"), h.to().format("%H:%M"), discount).to_string()
})
.collect::<Vec<String>>()
.join(", ")
.join(", ");
write!(f, "{}", str)
}
}
@@ -289,13 +293,43 @@ impl WeekHours {
}
}
/*pub struct Property {
id: u16,
name: String,
description: String,
price: Decimal
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Default)]
#[cfg_attr(feature = "ssr", derive(sqlx::Type))]
#[cfg_attr(feature = "ssr", sqlx(type_name = "slot_type"))]
pub enum SlotType {
Quarter,
Half,
#[default]
Hour,
Day
}
fn def_true() -> bool {
true
}
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate, Default)]
#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))]
pub struct ResProperty {
id: i32,
#[validate(length(min = 1,message = "Name cannot be empty"))]
pub name: String,
pub description: String,
pub price: Decimal,
pub slot: SlotType,
#[serde(default = "def_true")]
pub allow_multi: bool,
#[serde(default = "def_true")]
pub active: bool
}
impl ResProperty {
pub fn id(&self) -> i32 {
self.id
}
}
/*
pub enum MessageType {
NewReservation,
NewReservationCust,