bazzar/crates/model/src/v4/cart.rs
2023-06-03 13:31:57 +02:00

200 lines
5.7 KiB
Rust

//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use super::sea_orm_active_enums::CartTypes;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"cart"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq, Serialize, Deserialize)]
pub struct Model {
pub id: String,
pub email: Option<String>,
pub billing_address_id: Option<String>,
pub shipping_address_id: Option<String>,
pub region_id: String,
pub customer_id: Option<String>,
pub payment_id: Option<String>,
pub r#type: CartTypes,
pub completed_at: Option<DateTimeWithTimeZone>,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub deleted_at: Option<DateTimeWithTimeZone>,
pub metadata: Option<Json>,
pub idempotency_key: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Id,
Email,
BillingAddressId,
ShippingAddressId,
RegionId,
CustomerId,
PaymentId,
Type,
CompletedAt,
CreatedAt,
UpdatedAt,
DeletedAt,
Metadata,
IdempotencyKey,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = String;
fn auto_increment() -> bool {
false
}
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
Addresses2,
Addresses1,
Customers,
LineItems,
Order,
PaymentSessions,
Payments,
Regions,
ShippingMethods,
Swap,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::String(None).def(),
Self::Email => ColumnType::String(None).def().null(),
Self::BillingAddressId => ColumnType::String(None).def().null(),
Self::ShippingAddressId => ColumnType::String(None).def().null(),
Self::RegionId => ColumnType::String(None).def(),
Self::CustomerId => ColumnType::String(None).def().null(),
Self::PaymentId => ColumnType::String(None).def().null().unique(),
Self::Type => CartTypes::db_type().def(),
Self::CompletedAt => ColumnType::TimestampWithTimeZone.def().null(),
Self::CreatedAt => ColumnType::TimestampWithTimeZone.def(),
Self::UpdatedAt => ColumnType::TimestampWithTimeZone.def(),
Self::DeletedAt => ColumnType::TimestampWithTimeZone.def().null(),
Self::Metadata => ColumnType::JsonBinary.def().null(),
Self::IdempotencyKey => ColumnType::String(None).def().null(),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Addresses2 => Entity::belongs_to(super::addresses::Entity)
.from(Column::BillingAddressId)
.to(super::addresses::Column::Id)
.into(),
Self::Addresses1 => Entity::belongs_to(super::addresses::Entity)
.from(Column::ShippingAddressId)
.to(super::addresses::Column::Id)
.into(),
Self::Customers => Entity::belongs_to(super::customers::Entity)
.from(Column::CustomerId)
.to(super::customers::Column::Id)
.into(),
Self::LineItems => Entity::has_many(super::line_items::Entity).into(),
Self::Order => Entity::has_one(super::order::Entity).into(),
Self::PaymentSessions => Entity::has_many(super::payment_sessions::Entity).into(),
Self::Payments => Entity::belongs_to(super::payments::Entity)
.from(Column::PaymentId)
.to(super::payments::Column::Id)
.into(),
Self::Regions => Entity::belongs_to(super::regions::Entity)
.from(Column::RegionId)
.to(super::regions::Column::Id)
.into(),
Self::ShippingMethods => Entity::has_many(super::shipping_methods::Entity).into(),
Self::Swap => Entity::has_one(super::swap::Entity).into(),
}
}
}
impl Related<super::customers::Entity> for Entity {
fn to() -> RelationDef {
Relation::Customers.def()
}
}
impl Related<super::line_items::Entity> for Entity {
fn to() -> RelationDef {
Relation::LineItems.def()
}
}
impl Related<super::order::Entity> for Entity {
fn to() -> RelationDef {
Relation::Order.def()
}
}
impl Related<super::payment_sessions::Entity> for Entity {
fn to() -> RelationDef {
Relation::PaymentSessions.def()
}
}
impl Related<super::payments::Entity> for Entity {
fn to() -> RelationDef {
Relation::Payments.def()
}
}
impl Related<super::regions::Entity> for Entity {
fn to() -> RelationDef {
Relation::Regions.def()
}
}
impl Related<super::shipping_methods::Entity> for Entity {
fn to() -> RelationDef {
Relation::ShippingMethods.def()
}
}
impl Related<super::swap::Entity> for Entity {
fn to() -> RelationDef {
Relation::Swap.def()
}
}
impl Related<super::discounts::Entity> for Entity {
fn to() -> RelationDef {
super::cart_discounts::Relation::Discounts.def()
}
fn via() -> Option<RelationDef> {
Some(super::cart_discounts::Relation::Cart.def().rev())
}
}
impl Related<super::gift_cards::Entity> for Entity {
fn to() -> RelationDef {
super::cart_gift_cards::Relation::GiftCards.def()
}
fn via() -> Option<RelationDef> {
Some(super::cart_gift_cards::Relation::Cart.def().rev())
}
}
impl ActiveModelBehavior for ActiveModel {}