A whole list of types
This commit is contained in:
parent
a6bc84dfb3
commit
9a87e497ce
@ -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;
|
||||
|
36
src/domain/project_condition/impls.rs
Normal file
36
src/domain/project_condition/impls.rs
Normal 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()
|
||||
}
|
||||
}
|
36
src/domain/project_condition/mod.rs
Normal file
36
src/domain/project_condition/mod.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
36
src/domain/project_state/impls.rs
Normal file
36
src/domain/project_state/impls.rs
Normal 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()
|
||||
}
|
||||
}
|
35
src/domain/project_state/mod.rs
Normal file
35
src/domain/project_state/mod.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
36
src/domain/project_type/impls.rs
Normal file
36
src/domain/project_type/impls.rs
Normal 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()
|
||||
}
|
||||
}
|
52
src/domain/project_type/mod.rs
Normal file
52
src/domain/project_type/mod.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
36
src/domain/property_sale_type/impls.rs
Normal file
36
src/domain/property_sale_type/impls.rs
Normal 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()
|
||||
}
|
||||
}
|
36
src/domain/property_sale_type/mod.rs
Normal file
36
src/domain/property_sale_type/mod.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
36
src/domain/property_type/impls.rs
Normal file
36
src/domain/property_type/impls.rs
Normal 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()
|
||||
}
|
||||
}
|
44
src/domain/property_type/mod.rs
Normal file
44
src/domain/property_type/mod.rs
Normal 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),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
pub mod domain;
|
||||
pub mod dto;
|
||||
pub mod dto;
|
||||
pub mod traits;
|
1
src/traits/impls/mod.rs
Normal file
1
src/traits/impls/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod readable;
|
3
src/traits/impls/readable.rs
Normal file
3
src/traits/impls/readable.rs
Normal file
@ -0,0 +1,3 @@
|
||||
use crate::traits::readable::Readable;
|
||||
|
||||
|
2
src/traits/mod.rs
Normal file
2
src/traits/mod.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod readable;
|
||||
pub mod impls;
|
4
src/traits/readable.rs
Normal file
4
src/traits/readable.rs
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
pub trait Readable {
|
||||
fn to_human_readable(&self) -> String;
|
||||
}
|
Loading…
Reference in New Issue
Block a user