A whole list of types

This commit is contained in:
Franklin 2023-05-03 12:29:29 -04:00
parent a6bc84dfb3
commit 9a87e497ce
16 changed files with 400 additions and 2 deletions

View File

@ -7,6 +7,10 @@ pub mod thing_pk;
pub mod click;
pub mod clickable;
pub mod trackable;
pub mod project_condition;
pub mod project_state;
pub mod property_sale_type;
pub mod property_type;
pub mod error;
pub mod project_type;

View File

@ -0,0 +1,36 @@
use sqlx::{
encode::IsNull,
error::BoxDynError,
postgres::{PgArgumentBuffer, PgTypeInfo, PgValueRef},
Postgres,
};
use super::ProjectCondition;
use std::str::FromStr;
impl sqlx::Encode<'_, Postgres> for ProjectCondition {
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
let binding = self.to_string();
<&str as sqlx::Encode<Postgres>>::encode(&binding, buf)
}
}
impl sqlx::Decode<'_, Postgres> for ProjectCondition {
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
let column = value.as_str()?;
match Self::from_str(column) {
Ok(listing_state) => Ok(listing_state),
Err(error) => Err(Box::new(error)),
}
}
}
impl sqlx::Type<Postgres> for ProjectCondition {
fn type_info() -> PgTypeInfo {
PgTypeInfo::with_name("VARCHAR")
}
fn compatible(ty: &<Postgres as sqlx::Database>::TypeInfo) -> bool {
*ty == Self::type_info()
}
}

View File

@ -0,0 +1,36 @@
use std::{fmt::Display, str::FromStr};
use serde::{Deserialize, Serialize};
use super::error::{FromStrError};
#[cfg(feature = "sqlx")]
pub mod impls;
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum ProjectCondition {
#[default]
New,
Resale,
}
impl Display for ProjectCondition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProjectCondition::New => write!(f, "New"),
ProjectCondition::Resale => write!(f, "Resale"),
}
}
}
impl FromStr for ProjectCondition {
type Err = FromStrError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"New" => Ok(Self::New),
"Resale" => Ok(Self::Resale),
_ => Err(FromStrError),
}
}
}

View File

@ -0,0 +1,36 @@
use sqlx::{
encode::IsNull,
error::BoxDynError,
postgres::{PgArgumentBuffer, PgTypeInfo, PgValueRef},
Postgres,
};
use super::ProjectState;
use std::str::FromStr;
impl sqlx::Encode<'_, Postgres> for ProjectState {
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
let binding = self.to_string();
<&str as sqlx::Encode<Postgres>>::encode(&binding, buf)
}
}
impl sqlx::Decode<'_, Postgres> for ProjectState {
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
let column = value.as_str()?;
match Self::from_str(column) {
Ok(listing_state) => Ok(listing_state),
Err(error) => Err(Box::new(error)),
}
}
}
impl sqlx::Type<Postgres> for ProjectState {
fn type_info() -> PgTypeInfo {
PgTypeInfo::with_name("VARCHAR")
}
fn compatible(ty: &<Postgres as sqlx::Database>::TypeInfo) -> bool {
*ty == Self::type_info()
}
}

View File

@ -0,0 +1,35 @@
#[cfg(feature = "sqlx")]
pub mod impls;
use serde::{Deserialize, Serialize};
use std::{fmt::Display, str::FromStr};
use super::error::FromStrError;
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
pub enum ProjectState {
#[default]
Finished,
InConstruction,
}
impl Display for ProjectState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProjectState::Finished => write!(f, "Finished"),
ProjectState::InConstruction => write!(f, "InConstruction"),
}
}
}
impl FromStr for ProjectState {
type Err = FromStrError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Finished" => Ok(Self::Finished),
"InConstruction" => Ok(Self::InConstruction),
_ => Err(FromStrError),
}
}
}

View File

@ -0,0 +1,36 @@
use sqlx::{
encode::IsNull,
error::BoxDynError,
postgres::{PgArgumentBuffer, PgTypeInfo, PgValueRef},
Postgres,
};
use super::ProjectType;
use std::str::FromStr;
impl sqlx::Encode<'_, Postgres> for ProjectType {
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
let binding = self.to_string();
<&str as sqlx::Encode<Postgres>>::encode(&binding, buf)
}
}
impl sqlx::Decode<'_, Postgres> for ProjectType {
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
let column = value.as_str()?;
match Self::from_str(column) {
Ok(listing_state) => Ok(listing_state),
Err(error) => Err(Box::new(error)),
}
}
}
impl sqlx::Type<Postgres> for ProjectType {
fn type_info() -> PgTypeInfo {
PgTypeInfo::with_name("VARCHAR")
}
fn compatible(ty: &<Postgres as sqlx::Database>::TypeInfo) -> bool {
*ty == Self::type_info()
}
}

View File

@ -0,0 +1,52 @@
#[cfg(feature = "sqlx")]
pub mod impls;
use std::{fmt::Display, str::FromStr};
use serde::{Deserialize, Serialize};
use super::error::{FromStrError};
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum ProjectType {
#[default]
FamilyBuilding,
/// A building with commercial
OfficeBuilding,
/// A mall?
Commercial,
Community,
/// A group of houses (Residencial)
Housing,
/// Fields (cap cana, pc, quintas)
Project,
}
impl Display for ProjectType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProjectType::FamilyBuilding => write!(f, "FamilyBuilding"),
ProjectType::OfficeBuilding => write!(f, "OfficeBuilding"),
ProjectType::Commercial => write!(f, "Commercial"),
ProjectType::Community => write!(f, "Community"),
ProjectType::Housing => write!(f, "Housing"),
ProjectType::Project => write!(f, "Project"),
}
}
}
impl FromStr for ProjectType {
type Err = FromStrError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"FamilyBuilding" => Ok(Self::FamilyBuilding),
"OfficeBuilding" => Ok(Self::OfficeBuilding),
"Community" => Ok(Self::Community),
"Commercial" => Ok(Self::Commercial),
"Housing" => Ok(Self::Housing),
"Project" => Ok(Self::Project),
_ => Err(FromStrError),
}
}
}

View File

@ -0,0 +1,36 @@
use sqlx::{
encode::IsNull,
error::BoxDynError,
postgres::{PgArgumentBuffer, PgTypeInfo, PgValueRef},
Postgres,
};
use super::PropertySaleType;
use std::str::FromStr;
impl sqlx::Encode<'_, Postgres> for PropertySaleType {
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
let binding = self.to_string();
<&str as sqlx::Encode<Postgres>>::encode(&binding, buf)
}
}
impl sqlx::Decode<'_, Postgres> for PropertySaleType {
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
let column = value.as_str()?;
match Self::from_str(column) {
Ok(listing_state) => Ok(listing_state),
Err(error) => Err(Box::new(error)),
}
}
}
impl sqlx::Type<Postgres> for PropertySaleType {
fn type_info() -> PgTypeInfo {
PgTypeInfo::with_name("VARCHAR")
}
fn compatible(ty: &<Postgres as sqlx::Database>::TypeInfo) -> bool {
*ty == Self::type_info()
}
}

View File

@ -0,0 +1,36 @@
#[cfg(feature = "sqlx")]
pub mod impls;
use std::{fmt::Display, str::FromStr};
use serde::{Deserialize, Serialize};
use super::error::FromStrError;
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum PropertySaleType {
#[default]
ForSale,
NotForSale,
}
impl Display for PropertySaleType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PropertySaleType::ForSale => write!(f, "ForSale"),
PropertySaleType::NotForSale => write!(f, "NotForSale"),
}
}
}
impl FromStr for PropertySaleType {
type Err = FromStrError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"ForSale" => Ok(Self::ForSale),
"NotForSale" => Ok(Self::NotForSale),
_ => Err(FromStrError),
}
}
}

View File

@ -0,0 +1,36 @@
use sqlx::{
encode::IsNull,
error::BoxDynError,
postgres::{PgArgumentBuffer, PgTypeInfo, PgValueRef},
Postgres,
};
use super::PropertyType;
use std::str::FromStr;
impl sqlx::Encode<'_, Postgres> for PropertyType {
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
let binding = self.to_string();
<&str as sqlx::Encode<Postgres>>::encode(&binding, buf)
}
}
impl sqlx::Decode<'_, Postgres> for PropertyType {
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
let column = value.as_str()?;
match Self::from_str(column) {
Ok(listing_state) => Ok(listing_state),
Err(error) => Err(Box::new(error)),
}
}
}
impl sqlx::Type<Postgres> for PropertyType {
fn type_info() -> PgTypeInfo {
PgTypeInfo::with_name("VARCHAR")
}
fn compatible(ty: &<Postgres as sqlx::Database>::TypeInfo) -> bool {
*ty == Self::type_info()
}
}

View File

@ -0,0 +1,44 @@
#[cfg(feature = "sqlx")]
pub mod impls;
use std::{fmt::Display, str::FromStr};
use serde::{Deserialize, Serialize};
use super::error::FromStrError;
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum PropertyType {
#[default]
Apartment,
House,
Office,
Commercial,
Terrain,
}
impl Display for PropertyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PropertyType::Apartment => write!(f, "Apartment"),
PropertyType::House => write!(f, "House"),
PropertyType::Office => write!(f, "Office"),
PropertyType::Commercial => write!(f, "Commercial"),
PropertyType::Terrain => write!(f, "Terrain"),
}
}
}
impl FromStr for PropertyType {
type Err = FromStrError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Apartment" => Ok(Self::Apartment),
"House" => Ok(Self::House),
"Office" => Ok(Self::Office),
"Commercial" => Ok(Self::Commercial),
"Terrain" => Ok(Self::Terrain),
_ => Err(FromStrError),
}
}
}

View File

@ -1,2 +1,3 @@
pub mod domain;
pub mod dto;
pub mod dto;
pub mod traits;

1
src/traits/impls/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod readable;

View File

@ -0,0 +1,3 @@
use crate::traits::readable::Readable;

2
src/traits/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod readable;
pub mod impls;

4
src/traits/readable.rs Normal file
View File

@ -0,0 +1,4 @@
pub trait Readable {
fn to_human_readable(&self) -> String;
}