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:
Josiah Glosson
2025-05-22 03:34:36 -05:00
committed by GitHub
parent c6022ad977
commit 9e527ff141
111 changed files with 1477 additions and 1965 deletions

View File

@@ -3,12 +3,12 @@ use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use super::{DatabaseError, PayoutId, UserId};
use super::{DBPayoutId, DBUserId, DatabaseError};
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Payout {
pub id: PayoutId,
pub user_id: UserId,
pub id: DBPayoutId,
pub user_id: DBUserId,
pub created: DateTime<Utc>,
pub status: PayoutStatus,
pub amount: Decimal,
@@ -49,7 +49,7 @@ impl Payout {
}
pub async fn get<'a, 'b, E>(
id: PayoutId,
id: DBPayoutId,
executor: E,
) -> Result<Option<Payout>, DatabaseError>
where
@@ -61,7 +61,7 @@ impl Payout {
}
pub async fn get_many<'a, E>(
payout_ids: &[PayoutId],
payout_ids: &[DBPayoutId],
exec: E,
) -> Result<Vec<Payout>, DatabaseError>
where
@@ -79,8 +79,8 @@ impl Payout {
)
.fetch(exec)
.map_ok(|r| Payout {
id: PayoutId(r.id),
user_id: UserId(r.user_id),
id: DBPayoutId(r.id),
user_id: DBUserId(r.user_id),
created: r.created,
status: PayoutStatus::from_string(&r.status),
amount: r.amount,
@@ -96,9 +96,9 @@ impl Payout {
}
pub async fn get_all_for_user(
user_id: UserId,
user_id: DBUserId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<PayoutId>, DatabaseError> {
) -> Result<Vec<DBPayoutId>, DatabaseError> {
let results = sqlx::query!(
"
SELECT id
@@ -112,7 +112,7 @@ impl Payout {
Ok(results
.into_iter()
.map(|r| PayoutId(r.id))
.map(|r| DBPayoutId(r.id))
.collect::<Vec<_>>())
}
}