add: product types
This commit is contained in:
parent
aea764948c
commit
2705608903
5 changed files with 89 additions and 11 deletions
|
@ -10,6 +10,7 @@ pub mod littleweb;
|
|||
pub mod moderation;
|
||||
pub mod oauth;
|
||||
pub mod permissions;
|
||||
pub mod products;
|
||||
pub mod reactions;
|
||||
pub mod requests;
|
||||
pub mod socket;
|
||||
|
|
58
crates/core/src/model/products.rs
Normal file
58
crates/core/src/model/products.rs
Normal file
|
@ -0,0 +1,58 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Product {
|
||||
pub id: usize,
|
||||
pub created: usize,
|
||||
pub owner: usize,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub likes: usize,
|
||||
pub dislikes: usize,
|
||||
pub r#type: ProductType,
|
||||
pub stripe_id: String,
|
||||
pub price: ProductPrice,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ProductType {
|
||||
/// Text + images.
|
||||
Message,
|
||||
/// When a commission product is purchased, the creator will receive a request
|
||||
/// prompting them to respond with text + images.
|
||||
///
|
||||
/// This is the only product type which does not immediately return data to the
|
||||
/// customer, as seller input is required.
|
||||
///
|
||||
/// If the request is deleted, the purchase should be immediately refunded.
|
||||
Commission,
|
||||
}
|
||||
|
||||
/// Price in USD. `(dollars, cents)`.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProductPrice(u64, u64);
|
||||
|
||||
impl Product {
|
||||
/// Create a new [`Product`].
|
||||
pub fn new(
|
||||
owner: usize,
|
||||
title: String,
|
||||
description: String,
|
||||
price: ProductPrice,
|
||||
r#type: ProductType,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: Snowflake::new().to_string().parse::<usize>().unwrap(),
|
||||
created: unix_epoch_timestamp(),
|
||||
owner,
|
||||
title,
|
||||
description,
|
||||
likes: 0,
|
||||
dislikes: 0,
|
||||
r#type,
|
||||
stripe_id: String::new(),
|
||||
price,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue