You've already forked AstralRinth
forked from didirus/AstralRinth
Labrinth ID cleanup (#3681)
* Put all ID types in the labrinth::models::ids, and reduce code duplication with them * Rewrite labrinth::database::models::ids and rename most DB interface ID structs to be prefixed with DB * Run sqlx prepare --------- Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::database::models::{
|
||||
ChargeId, DatabaseError, ProductPriceId, UserId, UserSubscriptionId,
|
||||
DBChargeId, DBProductPriceId, DBUserId, DBUserSubscriptionId, DatabaseError,
|
||||
};
|
||||
use crate::models::billing::{
|
||||
ChargeStatus, ChargeType, PaymentPlatform, PriceDuration,
|
||||
@@ -8,9 +8,9 @@ use chrono::{DateTime, Utc};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
|
||||
pub struct ChargeItem {
|
||||
pub id: ChargeId,
|
||||
pub user_id: UserId,
|
||||
pub price_id: ProductPriceId,
|
||||
pub id: DBChargeId,
|
||||
pub user_id: DBUserId,
|
||||
pub price_id: DBProductPriceId,
|
||||
pub amount: i64,
|
||||
pub currency_code: String,
|
||||
pub status: ChargeStatus,
|
||||
@@ -18,13 +18,13 @@ pub struct ChargeItem {
|
||||
pub last_attempt: Option<DateTime<Utc>>,
|
||||
|
||||
pub type_: ChargeType,
|
||||
pub subscription_id: Option<UserSubscriptionId>,
|
||||
pub subscription_id: Option<DBUserSubscriptionId>,
|
||||
pub subscription_interval: Option<PriceDuration>,
|
||||
|
||||
pub payment_platform: PaymentPlatform,
|
||||
pub payment_platform_id: Option<String>,
|
||||
|
||||
pub parent_charge_id: Option<ChargeId>,
|
||||
pub parent_charge_id: Option<DBChargeId>,
|
||||
|
||||
// Net is always in USD
|
||||
pub net: Option<i64>,
|
||||
@@ -53,22 +53,22 @@ impl TryFrom<ChargeResult> for ChargeItem {
|
||||
|
||||
fn try_from(r: ChargeResult) -> Result<Self, Self::Error> {
|
||||
Ok(ChargeItem {
|
||||
id: ChargeId(r.id),
|
||||
user_id: UserId(r.user_id),
|
||||
price_id: ProductPriceId(r.price_id),
|
||||
id: DBChargeId(r.id),
|
||||
user_id: DBUserId(r.user_id),
|
||||
price_id: DBProductPriceId(r.price_id),
|
||||
amount: r.amount,
|
||||
currency_code: r.currency_code,
|
||||
status: ChargeStatus::from_string(&r.status),
|
||||
due: r.due,
|
||||
last_attempt: r.last_attempt,
|
||||
type_: ChargeType::from_string(&r.charge_type),
|
||||
subscription_id: r.subscription_id.map(UserSubscriptionId),
|
||||
subscription_id: r.subscription_id.map(DBUserSubscriptionId),
|
||||
subscription_interval: r
|
||||
.subscription_interval
|
||||
.map(|x| PriceDuration::from_string(&x)),
|
||||
payment_platform: PaymentPlatform::from_string(&r.payment_platform),
|
||||
payment_platform_id: r.payment_platform_id,
|
||||
parent_charge_id: r.parent_charge_id.map(ChargeId),
|
||||
parent_charge_id: r.parent_charge_id.map(DBChargeId),
|
||||
net: r.net,
|
||||
})
|
||||
}
|
||||
@@ -100,7 +100,7 @@ impl ChargeItem {
|
||||
pub async fn upsert(
|
||||
&self,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<ChargeId, DatabaseError> {
|
||||
) -> Result<DBChargeId, DatabaseError> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO charges (id, user_id, price_id, amount, currency_code, charge_type, status, due, last_attempt, subscription_id, subscription_interval, payment_platform, payment_platform_id, parent_charge_id, net)
|
||||
@@ -144,7 +144,7 @@ impl ChargeItem {
|
||||
}
|
||||
|
||||
pub async fn get(
|
||||
id: ChargeId,
|
||||
id: DBChargeId,
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Option<ChargeItem>, DatabaseError> {
|
||||
let id = id.0;
|
||||
@@ -156,7 +156,7 @@ impl ChargeItem {
|
||||
}
|
||||
|
||||
pub async fn get_from_user(
|
||||
user_id: UserId,
|
||||
user_id: DBUserId,
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Vec<ChargeItem>, DatabaseError> {
|
||||
let user_id = user_id.0;
|
||||
@@ -174,7 +174,7 @@ impl ChargeItem {
|
||||
}
|
||||
|
||||
pub async fn get_children(
|
||||
charge_id: ChargeId,
|
||||
charge_id: DBChargeId,
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Vec<ChargeItem>, DatabaseError> {
|
||||
let charge_id = charge_id.0;
|
||||
@@ -192,7 +192,7 @@ impl ChargeItem {
|
||||
}
|
||||
|
||||
pub async fn get_open_subscription(
|
||||
user_subscription_id: UserSubscriptionId,
|
||||
user_subscription_id: DBUserSubscriptionId,
|
||||
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
|
||||
) -> Result<Option<ChargeItem>, DatabaseError> {
|
||||
let user_subscription_id = user_subscription_id.0;
|
||||
@@ -255,7 +255,7 @@ impl ChargeItem {
|
||||
}
|
||||
|
||||
pub async fn remove(
|
||||
id: ChargeId,
|
||||
id: DBChargeId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
sqlx::query!(
|
||||
|
||||
Reference in New Issue
Block a user