Finished todo
This commit is contained in:
parent
205eebbfa5
commit
3695967ec9
|
@ -7,4 +7,5 @@ pub mod project_state;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod credential;
|
pub mod credential;
|
||||||
pub mod unit_type;
|
pub mod unit_type;
|
||||||
pub mod media;
|
pub mod media;
|
||||||
|
pub mod project_condition;
|
|
@ -4,7 +4,6 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use super::{media::MediaList, project_type::ProjectType};
|
use super::{media::MediaList, project_type::ProjectType};
|
||||||
|
|
||||||
//TODO: Add ProjectCondition enum (New or Resale)
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
use sqlx::{Postgres, postgres::{PgValueRef, PgTypeInfo, PgArgumentBuffer}, error::BoxDynError, encode::IsNull};
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
use std::{fmt::Display, str::FromStr};
|
||||||
|
|
||||||
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
|
use super::error::Error;
|
||||||
|
|
||||||
|
#[cfg(feature = "sqlx")]
|
||||||
|
pub mod impls;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum ProjectCondition {
|
||||||
|
New,
|
||||||
|
Resale,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for ProjectCondition {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
ProjectCondition::New => write!(f, "Nuevo"),
|
||||||
|
ProjectCondition::Resale => write!(f, "Reventa"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for ProjectCondition {
|
||||||
|
type Err = Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
_ => Err(Error::Parsing),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue