//use chrono::{NaiveDate, NaiveTime, Weekday}; //use rust_decimal::Decimal; #![allow(unused_variables)] use serde::{Deserialize, Serialize}; //use uuid::Uuid; use validator::Validate; #[derive(Serialize, Deserialize, Clone, Debug)] pub enum ApiResponse { Data(T), Error(String) } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate, Default)] #[cfg_attr(feature = "ssr", derive(sqlx::FromRow))] pub struct Company { id: i32, #[validate(length(min = 1,message = "Name cannot be empty"))] pub name: String, #[validate(length(min = 1,message = "Street cannot be empty"))] pub street: String, #[validate(length(min = 1,message = "House number cannot be empty"))] pub house_number: String, pub zip_code: String, pub city: String, } impl Company { pub fn id(&self) -> i32 { self.id } } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate, Default)] #[cfg_attr(feature = "ssr", derive(sqlx::FromRow))] pub struct User { id: i32, pub login: String, pub password: String, pub full_name: Option, #[validate(email(message = "Enter valid email address"))] pub email: Option, pub admin: bool, pub get_emails: bool, } impl User { pub fn id(&self) -> i32 { self.id } } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate, Default)] pub struct UserProfile { #[validate(length(min = 1,message = "Username cannot be empty"))] login: String, #[validate(must_match(other = "password_ver", message = "Passwords doesn't match"))] password: Option, password_ver: Option, full_name: String, #[validate(email(message = "Enter valid email address"))] email: String, get_emails: Option, admin: Option } impl UserProfile { pub fn login(&self) -> &str { &self.login } pub fn full_name(&self) -> &str { &self.full_name } pub fn email(&self) -> &str { &self.email } pub fn get_emails(&self) -> bool { self.get_emails.is_some() } pub fn admin(&self) -> bool { self.admin.is_some() } pub fn password(&self) -> &Option { &self.password } } #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq, Validate, Default)] pub struct PwdChange { login: String, old_password: String, #[validate(length(min = 1, message = "Enter new password"), must_match(other = "password_ver", message = "Passwords doesn't match"))] password: String, password_ver: String } impl PwdChange { pub fn login(&self) -> &str { &self.login } pub fn old_password(&self) -> &str { &self.old_password } pub fn password(&self) -> &str { &self.password } pub fn password_ver(&self) -> &str { &self.password_ver } } /*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, customer: Customer, price: Decimal, state: ReservationState, }*/