add: products api

This commit is contained in:
trisua 2025-07-13 15:28:55 -04:00
parent 2be2409d66
commit cf2af1e1e9
6 changed files with 241 additions and 9 deletions

View file

@ -74,6 +74,8 @@ pub enum AppScope {
UserReadDomains,
/// Read the user's services.
UserReadServices,
/// Read the user's products.
UserReadProducts,
/// Create posts as the user.
UserCreatePosts,
/// Create messages as the user.
@ -98,6 +100,8 @@ pub enum AppScope {
UserCreateDomains,
/// Create services on behalf of the user.
UserCreateServices,
/// Create products on behalf of the user.
UserCreateProducts,
/// Delete posts owned by the user.
UserDeletePosts,
/// Delete messages owned by the user.
@ -138,6 +142,8 @@ pub enum AppScope {
UserManageDomains,
/// Manage the user's services.
UserManageServices,
/// Manage the user's products.
UserManageProducts,
/// Edit posts created by the user.
UserEditPosts,
/// Edit drafts created by the user.

View file

@ -1,3 +1,5 @@
use std::fmt::Display;
use serde::{Serialize, Deserialize};
use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp};
@ -11,14 +13,13 @@ pub struct Product {
pub likes: isize,
pub dislikes: isize,
pub product_type: ProductType,
pub stripe_id: String,
pub price: ProductPrice,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ProductType {
/// Text + images.
Message,
Data,
/// When a commission product is purchased, the creator will receive a request
/// prompting them to respond with text + images.
///
@ -26,12 +27,39 @@ pub enum ProductType {
/// customer, as seller input is required.
///
/// If the request is deleted, the purchase should be immediately refunded.
///
/// Commissions are paid beforehand to prevent theft. This means it is vital
/// that refunds are enforced.
Commission,
}
/// A currency.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Currency {
USD,
EUR,
GBP,
}
impl Display for Currency {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Currency::USD => "$",
Currency::EUR => "",
Currency::GBP => "£",
})
}
}
/// Price in USD. `(dollars, cents)`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProductPrice(u64, u64);
pub struct ProductPrice(u64, u64, Currency);
impl Display for ProductPrice {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&format!("{}{}.{}", self.2, self.0, self.1))
}
}
impl Product {
/// Create a new [`Product`].
@ -51,7 +79,6 @@ impl Product {
likes: 0,
dislikes: 0,
product_type: r#type,
stripe_id: String::new(),
price,
}
}