add: user seller_data

This commit is contained in:
trisua 2025-07-12 18:06:36 -04:00
parent fdaa81422a
commit e4468e4768
14 changed files with 150 additions and 777 deletions

View file

@ -173,6 +173,8 @@ pub struct ConnectionsConfig {
/// - Use testing card numbers: <https://docs.stripe.com/testing?testing-method=card-numbers#visa>
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct StripeConfig {
/// Your Stripe API secret.
pub secret: String,
/// Payment links from the Stripe dashboard.
///
/// 1. Create a product and set the price for your membership

View file

@ -1,7 +1,8 @@
use super::common::NAME_REGEX;
use oiseau::cache::Cache;
use crate::model::auth::{
Achievement, AchievementName, AchievementRarity, Notification, UserConnections, ACHIEVEMENTS,
Achievement, AchievementName, AchievementRarity, Notification, StripeSellerData,
UserConnections, ACHIEVEMENTS,
};
use crate::model::moderation::AuditLogEntry;
use crate::model::oauth::AuthGrant;
@ -117,6 +118,7 @@ impl DataManager {
awaiting_purchase: get!(x->24(i32)) as i8 == 1,
was_purchased: get!(x->25(i32)) as i8 == 1,
browser_session: get!(x->26(String)),
seller_data: serde_json::from_str(&get!(x->27(String)).to_string()).unwrap(),
}
}
@ -273,7 +275,7 @@ impl DataManager {
let res = execute!(
&conn,
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27)",
"INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)",
params![
&(data.id as i64),
&(data.created as i64),
@ -302,6 +304,7 @@ impl DataManager {
&if data.awaiting_purchase { 1_i32 } else { 0_i32 },
&if data.was_purchased { 1_i32 } else { 0_i32 },
&data.browser_session,
&serde_json::to_string(&data.seller_data).unwrap(),
]
);
@ -997,6 +1000,7 @@ impl DataManager {
auto_method!(update_user_achievements(Vec<Achievement>)@get_user_by_id -> "UPDATE users SET achievements = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_invite_code(i64)@get_user_by_id -> "UPDATE users SET invite_code = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_browser_session(&str)@get_user_by_id -> "UPDATE users SET browser_session = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);
auto_method!(update_user_seller_data(StripeSellerData)@get_user_by_id -> "UPDATE users SET seller_data = $1 WHERE id = $2" --serde --cache-key-tmpl=cache_clear_user);
auto_method!(get_user_by_stripe_id(&str)@get_user_from_row -> "SELECT * FROM users WHERE stripe_id = $1" --name="user" --returns=User);
auto_method!(update_user_stripe_id(&str)@get_user_by_id -> "UPDATE users SET stripe_id = $1 WHERE id = $2" --cache-key-tmpl=cache_clear_user);

View file

@ -80,6 +80,9 @@ pub struct User {
/// view pages which require authentication (all `$` routes).
#[serde(default)]
pub browser_session: String,
/// Stripe connected account information (for Tetratto marketplace).
#[serde(default)]
pub seller_data: StripeSellerData,
}
pub type UserConnections =
@ -327,6 +330,12 @@ pub struct UserSettings {
pub private_biography: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct StripeSellerData {
#[serde(default)]
pub account_id: Option<String>,
}
fn mime_avif() -> String {
"image/avif".to_string()
}
@ -371,6 +380,7 @@ impl User {
awaiting_purchase: false,
was_purchased: false,
browser_session: String::new(),
seller_data: StripeSellerData::default(),
}
}