Commonize and distinguish a lot of struct names in labrinth::database::models (#3691)

This commit is contained in:
Josiah Glosson
2025-05-24 04:38:43 -05:00
committed by GitHub
parent 9c1bdf16e4
commit 4e4a7be7ef
78 changed files with 1075 additions and 1009 deletions

View File

@@ -7,7 +7,7 @@ use crate::models::billing::{
use chrono::{DateTime, Utc};
use std::convert::{TryFrom, TryInto};
pub struct ChargeItem {
pub struct DBCharge {
pub id: DBChargeId,
pub user_id: DBUserId,
pub price_id: DBProductPriceId,
@@ -30,7 +30,7 @@ pub struct ChargeItem {
pub net: Option<i64>,
}
struct ChargeResult {
struct ChargeQueryResult {
id: i64,
user_id: i64,
price_id: i64,
@@ -48,11 +48,11 @@ struct ChargeResult {
net: Option<i64>,
}
impl TryFrom<ChargeResult> for ChargeItem {
impl TryFrom<ChargeQueryResult> for DBCharge {
type Error = serde_json::Error;
fn try_from(r: ChargeResult) -> Result<Self, Self::Error> {
Ok(ChargeItem {
fn try_from(r: ChargeQueryResult) -> Result<Self, Self::Error> {
Ok(DBCharge {
id: DBChargeId(r.id),
user_id: DBUserId(r.user_id),
price_id: DBProductPriceId(r.price_id),
@@ -77,7 +77,7 @@ impl TryFrom<ChargeResult> for ChargeItem {
macro_rules! select_charges_with_predicate {
($predicate:tt, $param:ident) => {
sqlx::query_as!(
ChargeResult,
ChargeQueryResult,
r#"
SELECT
id, user_id, price_id, amount, currency_code, status, due, last_attempt,
@@ -96,7 +96,7 @@ macro_rules! select_charges_with_predicate {
};
}
impl ChargeItem {
impl DBCharge {
pub async fn upsert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -146,7 +146,7 @@ impl ChargeItem {
pub async fn get(
id: DBChargeId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<ChargeItem>, DatabaseError> {
) -> Result<Option<DBCharge>, DatabaseError> {
let id = id.0;
let res = select_charges_with_predicate!("WHERE id = $1", id)
.fetch_optional(exec)
@@ -158,7 +158,7 @@ impl ChargeItem {
pub async fn get_from_user(
user_id: DBUserId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ChargeItem>, DatabaseError> {
) -> Result<Vec<DBCharge>, DatabaseError> {
let user_id = user_id.0;
let res = select_charges_with_predicate!(
"WHERE user_id = $1 ORDER BY due DESC",
@@ -176,7 +176,7 @@ impl ChargeItem {
pub async fn get_children(
charge_id: DBChargeId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ChargeItem>, DatabaseError> {
) -> Result<Vec<DBCharge>, DatabaseError> {
let charge_id = charge_id.0;
let res = select_charges_with_predicate!(
"WHERE parent_charge_id = $1",
@@ -194,7 +194,7 @@ impl ChargeItem {
pub async fn get_open_subscription(
user_subscription_id: DBUserSubscriptionId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<ChargeItem>, DatabaseError> {
) -> Result<Option<DBCharge>, DatabaseError> {
let user_subscription_id = user_subscription_id.0;
let res = select_charges_with_predicate!(
"WHERE subscription_id = $1 AND (status = 'open' OR status = 'cancelled')",
@@ -208,7 +208,7 @@ impl ChargeItem {
pub async fn get_chargeable(
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ChargeItem>, DatabaseError> {
) -> Result<Vec<DBCharge>, DatabaseError> {
let charge_type = ChargeType::Subscription.as_str();
let res = select_charges_with_predicate!(
r#"
@@ -232,7 +232,7 @@ impl ChargeItem {
pub async fn get_unprovision(
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ChargeItem>, DatabaseError> {
) -> Result<Vec<DBCharge>, DatabaseError> {
let charge_type = ChargeType::Subscription.as_str();
let res = select_charges_with_predicate!(
r#"

View File

@@ -25,7 +25,7 @@ impl CollectionBuilder {
self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<DBCollectionId, DatabaseError> {
let collection_struct = Collection {
let collection_struct = DBCollection {
id: self.collection_id,
name: self.name,
user_id: self.user_id,
@@ -44,7 +44,7 @@ impl CollectionBuilder {
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Collection {
pub struct DBCollection {
pub id: DBCollectionId,
pub user_id: DBUserId,
pub name: String,
@@ -58,7 +58,7 @@ pub struct Collection {
pub projects: Vec<DBProjectId>,
}
impl Collection {
impl DBCollection {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -131,7 +131,7 @@ impl Collection {
.execute(&mut **transaction)
.await?;
models::Collection::clear_cache(collection.id, redis).await?;
models::DBCollection::clear_cache(collection.id, redis).await?;
Ok(Some(()))
} else {
@@ -143,11 +143,11 @@ impl Collection {
id: DBCollectionId,
executor: E,
redis: &RedisPool,
) -> Result<Option<Collection>, DatabaseError>
) -> Result<Option<DBCollection>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
Collection::get_many(&[id], executor, redis)
DBCollection::get_many(&[id], executor, redis)
.await
.map(|x| x.into_iter().next())
}
@@ -156,7 +156,7 @@ impl Collection {
collection_ids: &[DBCollectionId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<Collection>, DatabaseError>
) -> Result<Vec<DBCollection>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -180,7 +180,7 @@ impl Collection {
)
.fetch(exec)
.try_fold(DashMap::new(), |acc, m| {
let collection = Collection {
let collection = DBCollection {
id: DBCollectionId(m.id),
user_id: DBUserId(m.user_id),
name: m.name.clone(),

View File

@@ -15,7 +15,7 @@ const FLOWS_NAMESPACE: &str = "flows";
#[derive(Deserialize, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Flow {
pub enum DBFlow {
OAuth {
user_id: Option<DBUserId>,
url: String,
@@ -53,7 +53,7 @@ pub enum Flow {
},
}
impl Flow {
impl DBFlow {
pub async fn insert(
&self,
expires: Duration,
@@ -81,7 +81,7 @@ impl Flow {
pub async fn get(
id: &str,
redis: &RedisPool,
) -> Result<Option<Flow>, DatabaseError> {
) -> Result<Option<DBFlow>, DatabaseError> {
let mut redis = redis.connect().await?;
redis.get_deserialized_from_json(FLOWS_NAMESPACE, id).await
@@ -91,9 +91,9 @@ impl Flow {
/// The predicate should validate that the flow being removed is the correct one, as a security measure
pub async fn take_if(
id: &str,
predicate: impl FnOnce(&Flow) -> bool,
predicate: impl FnOnce(&DBFlow) -> bool,
redis: &RedisPool,
) -> Result<Option<Flow>, DatabaseError> {
) -> Result<Option<DBFlow>, DatabaseError> {
let flow = Self::get(id, redis).await?;
if let Some(flow) = flow.as_ref() {
if predicate(flow) {

View File

@@ -1,14 +1,14 @@
use crate::database::models::DBUserId;
use chrono::{DateTime, Utc};
pub struct FriendItem {
pub struct DBFriend {
pub user_id: DBUserId,
pub friend_id: DBUserId,
pub created: DateTime<Utc>,
pub accepted: bool,
}
impl FriendItem {
impl DBFriend {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -33,7 +33,7 @@ impl FriendItem {
user_id: DBUserId,
friend_id: DBUserId,
exec: E,
) -> Result<Option<FriendItem>, sqlx::Error>
) -> Result<Option<DBFriend>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -48,7 +48,7 @@ impl FriendItem {
)
.fetch_optional(exec)
.await?
.map(|row| FriendItem {
.map(|row| DBFriend {
user_id: DBUserId(row.user_id),
friend_id: DBUserId(row.friend_id),
created: row.created,
@@ -84,7 +84,7 @@ impl FriendItem {
user_id: DBUserId,
accepted: Option<bool>,
exec: E,
) -> Result<Vec<FriendItem>, sqlx::Error>
) -> Result<Vec<DBFriend>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -99,7 +99,7 @@ impl FriendItem {
.fetch_all(exec)
.await?
.into_iter()
.map(|row| FriendItem {
.map(|row| DBFriend {
user_id: DBUserId(row.user_id),
friend_id: DBUserId(row.friend_id),
created: row.created,

View File

@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
const IMAGES_NAMESPACE: &str = "images";
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Image {
pub struct DBImage {
pub id: DBImageId,
pub url: String,
pub raw_url: String,
@@ -25,7 +25,7 @@ pub struct Image {
pub report_id: Option<DBReportId>,
}
impl Image {
impl DBImage {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -75,7 +75,7 @@ impl Image {
.execute(&mut **transaction)
.await?;
Image::clear_cache(image.id, redis).await?;
DBImage::clear_cache(image.id, redis).await?;
Ok(Some(()))
} else {
@@ -86,7 +86,7 @@ impl Image {
pub async fn get_many_contexted(
context: ImageContext,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<Vec<Image>, sqlx::Error> {
) -> Result<Vec<DBImage>, sqlx::Error> {
// Set all of project_id, version_id, thread_message_id, report_id to None
// Then set the one that is relevant to Some
@@ -141,7 +141,7 @@ impl Image {
.map_ok(|row| {
let id = DBImageId(row.id);
Image {
DBImage {
id,
url: row.url,
raw_url: row.raw_url,
@@ -155,7 +155,7 @@ impl Image {
report_id: row.report_id.map(DBReportId),
}
})
.try_collect::<Vec<Image>>()
.try_collect::<Vec<DBImage>>()
.await
}
@@ -163,11 +163,11 @@ impl Image {
id: DBImageId,
executor: E,
redis: &RedisPool,
) -> Result<Option<Image>, DatabaseError>
) -> Result<Option<DBImage>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
Image::get_many(&[id], executor, redis)
DBImage::get_many(&[id], executor, redis)
.await
.map(|x| x.into_iter().next())
}
@@ -176,7 +176,7 @@ impl Image {
image_ids: &[DBImageId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<Image>, DatabaseError>
) -> Result<Vec<DBImage>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -197,7 +197,7 @@ impl Image {
)
.fetch(exec)
.try_fold(DashMap::new(), |acc, i| {
let img = Image {
let img = DBImage {
id: DBImageId(i.id),
url: i.url,
raw_url: i.raw_url,

View File

@@ -26,17 +26,17 @@ pub mod user_item;
pub mod user_subscription_item;
pub mod version_item;
pub use collection_item::Collection;
pub use collection_item::DBCollection;
pub use ids::*;
pub use image_item::Image;
pub use oauth_client_item::OAuthClient;
pub use organization_item::Organization;
pub use project_item::Project;
pub use team_item::Team;
pub use team_item::TeamMember;
pub use thread_item::{Thread, ThreadMessage};
pub use user_item::User;
pub use version_item::Version;
pub use image_item::DBImage;
pub use oauth_client_item::DBOAuthClient;
pub use organization_item::DBOrganization;
pub use project_item::DBProject;
pub use team_item::DBTeam;
pub use team_item::DBTeamMember;
pub use thread_item::{DBThread, DBThreadMessage};
pub use user_item::DBUser;
pub use version_item::DBVersion;
#[derive(Error, Debug)]
pub enum DatabaseError {

View File

@@ -12,7 +12,7 @@ pub struct NotificationBuilder {
}
#[derive(Serialize, Deserialize)]
pub struct Notification {
pub struct DBNotification {
pub id: DBNotificationId,
pub user_id: DBUserId,
pub body: NotificationBody,
@@ -21,7 +21,7 @@ pub struct Notification {
}
#[derive(Serialize, Deserialize)]
pub struct NotificationAction {
pub struct DBNotificationAction {
pub id: NotificationActionId,
pub notification_id: DBNotificationId,
pub name: String,
@@ -72,13 +72,13 @@ impl NotificationBuilder {
.execute(&mut **transaction)
.await?;
Notification::clear_user_notifications_cache(&users, redis).await?;
DBNotification::clear_user_notifications_cache(&users, redis).await?;
Ok(())
}
}
impl Notification {
impl DBNotification {
pub async fn get<'a, 'b, E>(
id: DBNotificationId,
executor: E,
@@ -94,7 +94,7 @@ impl Notification {
pub async fn get_many<'a, E>(
notification_ids: &[DBNotificationId],
exec: E,
) -> Result<Vec<Notification>, sqlx::Error>
) -> Result<Vec<DBNotification>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
@@ -116,7 +116,7 @@ impl Notification {
.map_ok(|row| {
let id = DBNotificationId(row.id);
Notification {
DBNotification {
id,
user_id: DBUserId(row.user_id),
read: row.read,
@@ -140,7 +140,7 @@ impl Notification {
}),
}
})
.try_collect::<Vec<Notification>>()
.try_collect::<Vec<DBNotification>>()
.await
}
@@ -148,13 +148,13 @@ impl Notification {
user_id: DBUserId,
exec: E,
redis: &RedisPool,
) -> Result<Vec<Notification>, DatabaseError>
) -> Result<Vec<DBNotification>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
let mut redis = redis.connect().await?;
let cached_notifications: Option<Vec<Notification>> = redis
let cached_notifications: Option<Vec<DBNotification>> = redis
.get_deserialized_from_json(
USER_NOTIFICATIONS_NAMESPACE,
&user_id.0.to_string(),
@@ -180,7 +180,7 @@ impl Notification {
.map_ok(|row| {
let id = DBNotificationId(row.id);
Notification {
DBNotification {
id,
user_id: DBUserId(row.user_id),
read: row.read,
@@ -204,7 +204,7 @@ impl Notification {
}),
}
})
.try_collect::<Vec<Notification>>()
.try_collect::<Vec<DBNotification>>()
.await?;
redis
@@ -249,7 +249,7 @@ impl Notification {
.try_collect::<Vec<_>>()
.await?;
Notification::clear_user_notifications_cache(
DBNotification::clear_user_notifications_cache(
affected_users.iter(),
redis,
)
@@ -297,7 +297,7 @@ impl Notification {
.try_collect::<Vec<_>>()
.await?;
Notification::clear_user_notifications_cache(
DBNotification::clear_user_notifications_cache(
affected_users.iter(),
redis,
)

View File

@@ -9,7 +9,7 @@ use super::{
};
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct OAuthClientAuthorization {
pub struct DBOAuthClientAuthorization {
pub id: DBOAuthClientAuthorizationId,
pub client_id: DBOAuthClientId,
pub user_id: DBUserId,
@@ -17,7 +17,7 @@ pub struct OAuthClientAuthorization {
pub created: DateTime<Utc>,
}
struct AuthorizationQueryResult {
struct DBAuthClientAuthorizationQueryResult {
id: i64,
client_id: i64,
user_id: i64,
@@ -25,9 +25,9 @@ struct AuthorizationQueryResult {
created: DateTime<Utc>,
}
impl From<AuthorizationQueryResult> for OAuthClientAuthorization {
fn from(value: AuthorizationQueryResult) -> Self {
OAuthClientAuthorization {
impl From<DBAuthClientAuthorizationQueryResult> for DBOAuthClientAuthorization {
fn from(value: DBAuthClientAuthorizationQueryResult) -> Self {
DBOAuthClientAuthorization {
id: DBOAuthClientAuthorizationId(value.id),
client_id: DBOAuthClientId(value.client_id),
user_id: DBUserId(value.user_id),
@@ -37,14 +37,14 @@ impl From<AuthorizationQueryResult> for OAuthClientAuthorization {
}
}
impl OAuthClientAuthorization {
impl DBOAuthClientAuthorization {
pub async fn get(
client_id: DBOAuthClientId,
user_id: DBUserId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<OAuthClientAuthorization>, DatabaseError> {
) -> Result<Option<DBOAuthClientAuthorization>, DatabaseError> {
let value = sqlx::query_as!(
AuthorizationQueryResult,
DBAuthClientAuthorizationQueryResult,
"
SELECT id, client_id, user_id, scopes, created
FROM oauth_client_authorizations
@@ -62,9 +62,9 @@ impl OAuthClientAuthorization {
pub async fn get_all_for_user(
user_id: DBUserId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<OAuthClientAuthorization>, DatabaseError> {
) -> Result<Vec<DBOAuthClientAuthorization>, DatabaseError> {
let results = sqlx::query_as!(
AuthorizationQueryResult,
DBAuthClientAuthorizationQueryResult,
"
SELECT id, client_id, user_id, scopes, created
FROM oauth_client_authorizations

View File

@@ -7,28 +7,28 @@ use super::{DBOAuthClientId, DBOAuthRedirectUriId, DBUserId, DatabaseError};
use crate::models::pats::Scopes;
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct OAuthRedirectUri {
pub struct DBOAuthRedirectUri {
pub id: DBOAuthRedirectUriId,
pub client_id: DBOAuthClientId,
pub uri: String,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct OAuthClient {
pub struct DBOAuthClient {
pub id: DBOAuthClientId,
pub name: String,
pub icon_url: Option<String>,
pub raw_icon_url: Option<String>,
pub max_scopes: Scopes,
pub secret_hash: String,
pub redirect_uris: Vec<OAuthRedirectUri>,
pub redirect_uris: Vec<DBOAuthRedirectUri>,
pub created: DateTime<Utc>,
pub created_by: DBUserId,
pub url: Option<String>,
pub description: Option<String>,
}
struct ClientQueryResult {
struct OAuthClientQueryResult {
id: i64,
name: String,
icon_url: Option<String>,
@@ -49,7 +49,7 @@ macro_rules! select_clients_with_predicate {
// the combination of the JOIN and filter using ANY makes sqlx think all columns are nullable
// https://docs.rs/sqlx/latest/sqlx/macro.query.html#force-nullable
sqlx::query_as!(
ClientQueryResult,
OAuthClientQueryResult,
r#"
SELECT
clients.id as "id!",
@@ -77,18 +77,18 @@ macro_rules! select_clients_with_predicate {
};
}
impl OAuthClient {
impl DBOAuthClient {
pub async fn get(
id: DBOAuthClientId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<OAuthClient>, DatabaseError> {
) -> Result<Option<DBOAuthClient>, DatabaseError> {
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
}
pub async fn get_many(
ids: &[DBOAuthClientId],
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<OAuthClient>, DatabaseError> {
) -> Result<Vec<DBOAuthClient>, DatabaseError> {
let ids = ids.iter().map(|id| id.0).collect_vec();
let ids_ref: &[i64] = &ids;
let results = select_clients_with_predicate!(
@@ -104,7 +104,7 @@ impl OAuthClient {
pub async fn get_all_user_clients(
user_id: DBUserId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<OAuthClient>, DatabaseError> {
) -> Result<Vec<DBOAuthClient>, DatabaseError> {
let user_id_param = user_id.0;
let clients = select_clients_with_predicate!(
"WHERE created_by = $1",
@@ -208,7 +208,7 @@ impl OAuthClient {
}
pub async fn insert_redirect_uris(
uris: &[OAuthRedirectUri],
uris: &[DBOAuthRedirectUri],
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<(), DatabaseError> {
let (ids, client_ids, uris): (Vec<_>, Vec<_>, Vec<_>) = uris
@@ -235,14 +235,14 @@ impl OAuthClient {
}
}
impl From<ClientQueryResult> for OAuthClient {
fn from(r: ClientQueryResult) -> Self {
impl From<OAuthClientQueryResult> for DBOAuthClient {
fn from(r: OAuthClientQueryResult) -> Self {
let redirects = if let (Some(ids), Some(uris)) =
(r.uri_ids.as_ref(), r.uri_vals.as_ref())
{
ids.iter()
.zip(uris.iter())
.map(|(id, uri)| OAuthRedirectUri {
.map(|(id, uri)| DBOAuthRedirectUri {
id: DBOAuthRedirectUriId(*id),
client_id: DBOAuthClientId(r.id),
uri: uri.to_string(),
@@ -252,7 +252,7 @@ impl From<ClientQueryResult> for OAuthClient {
vec![]
};
OAuthClient {
DBOAuthClient {
id: DBOAuthClientId(r.id),
name: r.name,
icon_url: r.icon_url,

View File

@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use sha2::Digest;
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct OAuthAccessToken {
pub struct DBOAuthAccessToken {
pub id: DBOAuthAccessTokenId,
pub authorization_id: DBOAuthClientAuthorizationId,
pub token_hash: String,
@@ -22,11 +22,11 @@ pub struct OAuthAccessToken {
pub user_id: DBUserId,
}
impl OAuthAccessToken {
impl DBOAuthAccessToken {
pub async fn get(
token_hash: String,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<OAuthAccessToken>, DatabaseError> {
) -> Result<Option<DBOAuthAccessToken>, DatabaseError> {
let value = sqlx::query!(
"
SELECT
@@ -49,7 +49,7 @@ impl OAuthAccessToken {
.fetch_optional(exec)
.await?;
Ok(value.map(|r| OAuthAccessToken {
Ok(value.map(|r| DBOAuthAccessToken {
id: DBOAuthAccessTokenId(r.id),
authorization_id: DBOAuthClientAuthorizationId(r.authorization_id),
token_hash: r.token_hash,

View File

@@ -5,7 +5,7 @@ use futures::TryStreamExt;
use std::fmt::{Debug, Display};
use std::hash::Hash;
use super::{TeamMember, ids::*};
use super::{DBTeamMember, ids::*};
use serde::{Deserialize, Serialize};
const ORGANIZATIONS_NAMESPACE: &str = "organizations";
@@ -13,7 +13,7 @@ const ORGANIZATIONS_TITLES_NAMESPACE: &str = "organizations_titles";
#[derive(Deserialize, Serialize, Clone, Debug)]
/// An organization of users who together control one or more projects and organizations.
pub struct Organization {
pub struct DBOrganization {
/// The id of the organization
pub id: DBOrganizationId,
@@ -35,7 +35,7 @@ pub struct Organization {
pub color: Option<u32>,
}
impl Organization {
impl DBOrganization {
pub async fn insert(
self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -142,7 +142,7 @@ impl Organization {
)
.fetch(exec)
.try_fold(DashMap::new(), |acc, m| {
let org = Organization {
let org = DBOrganization {
id: DBOrganizationId(m.id),
slug: m.slug.clone(),
name: m.name,
@@ -188,7 +188,7 @@ impl Organization {
.await?;
if let Some(result) = result {
Ok(Some(Organization {
Ok(Some(DBOrganization {
id: DBOrganizationId(result.id),
slug: result.slug,
name: result.name,
@@ -221,7 +221,7 @@ impl Organization {
.execute(&mut **transaction)
.await?;
TeamMember::clear_cache(organization.team_id, redis).await?;
DBTeamMember::clear_cache(organization.team_id, redis).await?;
sqlx::query!(
"

View File

@@ -15,7 +15,7 @@ const PATS_TOKENS_NAMESPACE: &str = "pats_tokens";
const PATS_USERS_NAMESPACE: &str = "pats_users";
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct PersonalAccessToken {
pub struct DBPersonalAccessToken {
pub id: DBPatId,
pub name: String,
pub access_token: String,
@@ -26,7 +26,7 @@ pub struct PersonalAccessToken {
pub last_used: Option<DateTime<Utc>>,
}
impl PersonalAccessToken {
impl DBPersonalAccessToken {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -63,7 +63,7 @@ impl PersonalAccessToken {
id: T,
exec: E,
redis: &RedisPool,
) -> Result<Option<PersonalAccessToken>, DatabaseError>
) -> Result<Option<DBPersonalAccessToken>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -76,7 +76,7 @@ impl PersonalAccessToken {
pat_ids: &[DBPatId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<PersonalAccessToken>, DatabaseError>
) -> Result<Vec<DBPersonalAccessToken>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -84,7 +84,7 @@ impl PersonalAccessToken {
.iter()
.map(|x| crate::models::ids::PatId::from(*x))
.collect::<Vec<_>>();
PersonalAccessToken::get_many(&ids, exec, redis).await
DBPersonalAccessToken::get_many(&ids, exec, redis).await
}
pub async fn get_many<
@@ -95,7 +95,7 @@ impl PersonalAccessToken {
pat_strings: &[T],
exec: E,
redis: &RedisPool,
) -> Result<Vec<PersonalAccessToken>, DatabaseError>
) -> Result<Vec<DBPersonalAccessToken>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -125,7 +125,7 @@ impl PersonalAccessToken {
)
.fetch(exec)
.try_fold(DashMap::new(), |acc, x| {
let pat = PersonalAccessToken {
let pat = DBPersonalAccessToken {
id: DBPatId(x.id),
name: x.name,
access_token: x.access_token.clone(),

View File

@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use super::{DBPayoutId, DBUserId, DatabaseError};
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Payout {
pub struct DBPayout {
pub id: DBPayoutId,
pub user_id: DBUserId,
pub created: DateTime<Utc>,
@@ -19,7 +19,7 @@ pub struct Payout {
pub platform_id: Option<String>,
}
impl Payout {
impl DBPayout {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -51,11 +51,11 @@ impl Payout {
pub async fn get<'a, 'b, E>(
id: DBPayoutId,
executor: E,
) -> Result<Option<Payout>, DatabaseError>
) -> Result<Option<DBPayout>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
Payout::get_many(&[id], executor)
DBPayout::get_many(&[id], executor)
.await
.map(|x| x.into_iter().next())
}
@@ -63,7 +63,7 @@ impl Payout {
pub async fn get_many<'a, E>(
payout_ids: &[DBPayoutId],
exec: E,
) -> Result<Vec<Payout>, DatabaseError>
) -> Result<Vec<DBPayout>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -78,7 +78,7 @@ impl Payout {
&payout_ids.into_iter().map(|x| x.0).collect::<Vec<_>>()
)
.fetch(exec)
.map_ok(|r| Payout {
.map_ok(|r| DBPayout {
id: DBPayoutId(r.id),
user_id: DBUserId(r.user_id),
created: r.created,
@@ -89,7 +89,7 @@ impl Payout {
platform_id: r.platform_id,
fee: r.fee,
})
.try_collect::<Vec<Payout>>()
.try_collect::<Vec<DBPayout>>()
.await?;
Ok(results)

View File

@@ -11,13 +11,13 @@ use std::convert::TryInto;
const PRODUCTS_NAMESPACE: &str = "products";
pub struct ProductItem {
pub struct DBProduct {
pub id: DBProductId,
pub metadata: ProductMetadata,
pub unitary: bool,
}
struct ProductResult {
struct ProductQueryResult {
id: i64,
metadata: serde_json::Value,
unitary: bool,
@@ -26,7 +26,7 @@ struct ProductResult {
macro_rules! select_products_with_predicate {
($predicate:tt, $param:ident) => {
sqlx::query_as!(
ProductResult,
ProductQueryResult,
r#"
SELECT id, metadata, unitary
FROM products
@@ -37,11 +37,11 @@ macro_rules! select_products_with_predicate {
};
}
impl TryFrom<ProductResult> for ProductItem {
impl TryFrom<ProductQueryResult> for DBProduct {
type Error = serde_json::Error;
fn try_from(r: ProductResult) -> Result<Self, Self::Error> {
Ok(ProductItem {
fn try_from(r: ProductQueryResult) -> Result<Self, Self::Error> {
Ok(DBProduct {
id: DBProductId(r.id),
metadata: serde_json::from_value(r.metadata)?,
unitary: r.unitary,
@@ -49,18 +49,18 @@ impl TryFrom<ProductResult> for ProductItem {
}
}
impl ProductItem {
impl DBProduct {
pub async fn get(
id: DBProductId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<ProductItem>, DatabaseError> {
) -> Result<Option<DBProduct>, DatabaseError> {
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
}
pub async fn get_many(
ids: &[DBProductId],
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ProductItem>, DatabaseError> {
) -> Result<Vec<DBProduct>, DatabaseError> {
let ids = ids.iter().map(|id| id.0).collect_vec();
let ids_ref: &[i64] = &ids;
let results = select_products_with_predicate!(
@@ -78,7 +78,7 @@ impl ProductItem {
pub async fn get_all(
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ProductItem>, DatabaseError> {
) -> Result<Vec<DBProduct>, DatabaseError> {
let one = 1;
let results = select_products_with_predicate!("WHERE 1 = $1", one)
.fetch_all(exec)
@@ -92,24 +92,24 @@ impl ProductItem {
}
#[derive(Deserialize, Serialize)]
pub struct QueryProduct {
pub struct QueryProductWithPrices {
pub id: DBProductId,
pub metadata: ProductMetadata,
pub unitary: bool,
pub prices: Vec<ProductPriceItem>,
pub prices: Vec<DBProductPrice>,
}
impl QueryProduct {
impl QueryProductWithPrices {
pub async fn list<'a, E>(
exec: E,
redis: &RedisPool,
) -> Result<Vec<QueryProduct>, DatabaseError>
) -> Result<Vec<QueryProductWithPrices>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
let mut redis = redis.connect().await?;
let res: Option<Vec<QueryProduct>> = redis
let res: Option<Vec<QueryProductWithPrices>> = redis
.get_deserialized_from_json(PRODUCTS_NAMESPACE, "all")
.await?;
@@ -117,8 +117,8 @@ impl QueryProduct {
return Ok(res);
}
let all_products = product_item::ProductItem::get_all(exec).await?;
let prices = product_item::ProductPriceItem::get_all_products_prices(
let all_products = product_item::DBProduct::get_all(exec).await?;
let prices = product_item::DBProductPrice::get_all_products_prices(
&all_products.iter().map(|x| x.id).collect::<Vec<_>>(),
exec,
)
@@ -126,7 +126,7 @@ impl QueryProduct {
let products = all_products
.into_iter()
.map(|x| QueryProduct {
.map(|x| QueryProductWithPrices {
id: x.id,
metadata: x.metadata,
prices: prices
@@ -134,7 +134,7 @@ impl QueryProduct {
.map(|x| x.1)
.unwrap_or_default()
.into_iter()
.map(|x| ProductPriceItem {
.map(|x| DBProductPrice {
id: x.id,
product_id: x.product_id,
prices: x.prices,
@@ -154,14 +154,14 @@ impl QueryProduct {
}
#[derive(Deserialize, Serialize)]
pub struct ProductPriceItem {
pub struct DBProductPrice {
pub id: DBProductPriceId,
pub product_id: DBProductId,
pub prices: Price,
pub currency_code: String,
}
struct ProductPriceResult {
struct ProductPriceQueryResult {
id: i64,
product_id: i64,
prices: serde_json::Value,
@@ -171,7 +171,7 @@ struct ProductPriceResult {
macro_rules! select_prices_with_predicate {
($predicate:tt, $param:ident) => {
sqlx::query_as!(
ProductPriceResult,
ProductPriceQueryResult,
r#"
SELECT id, product_id, prices, currency_code
FROM products_prices
@@ -182,11 +182,11 @@ macro_rules! select_prices_with_predicate {
};
}
impl TryFrom<ProductPriceResult> for ProductPriceItem {
impl TryFrom<ProductPriceQueryResult> for DBProductPrice {
type Error = serde_json::Error;
fn try_from(r: ProductPriceResult) -> Result<Self, Self::Error> {
Ok(ProductPriceItem {
fn try_from(r: ProductPriceQueryResult) -> Result<Self, Self::Error> {
Ok(DBProductPrice {
id: DBProductPriceId(r.id),
product_id: DBProductId(r.product_id),
prices: serde_json::from_value(r.prices)?,
@@ -195,18 +195,18 @@ impl TryFrom<ProductPriceResult> for ProductPriceItem {
}
}
impl ProductPriceItem {
impl DBProductPrice {
pub async fn get(
id: DBProductPriceId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<ProductPriceItem>, DatabaseError> {
) -> Result<Option<DBProductPrice>, DatabaseError> {
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
}
pub async fn get_many(
ids: &[DBProductPriceId],
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ProductPriceItem>, DatabaseError> {
) -> Result<Vec<DBProductPrice>, DatabaseError> {
let ids = ids.iter().map(|id| id.0).collect_vec();
let ids_ref: &[i64] = &ids;
let results = select_prices_with_predicate!(
@@ -225,7 +225,7 @@ impl ProductPriceItem {
pub async fn get_all_product_prices(
product_id: DBProductId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ProductPriceItem>, DatabaseError> {
) -> Result<Vec<DBProductPrice>, DatabaseError> {
let res = Self::get_all_products_prices(&[product_id], exec).await?;
Ok(res.remove(&product_id).map(|x| x.1).unwrap_or_default())
@@ -234,8 +234,7 @@ impl ProductPriceItem {
pub async fn get_all_products_prices(
product_ids: &[DBProductId],
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<DashMap<DBProductId, Vec<ProductPriceItem>>, DatabaseError>
{
) -> Result<DashMap<DBProductId, Vec<DBProductPrice>>, DatabaseError> {
let ids = product_ids.iter().map(|id| id.0).collect_vec();
let ids_ref: &[i64] = &ids;
@@ -247,9 +246,9 @@ impl ProductPriceItem {
.fetch(exec)
.try_fold(
DashMap::new(),
|acc: DashMap<DBProductId, Vec<ProductPriceItem>>, x| {
if let Ok(item) = <ProductPriceResult as TryInto<
ProductPriceItem,
|acc: DashMap<DBProductId, Vec<DBProductPrice>>, x| {
if let Ok(item) = <ProductPriceQueryResult as TryInto<
DBProductPrice,
>>::try_into(x)
{
acc.entry(item.product_id).or_default().push(item);

View File

@@ -2,7 +2,7 @@ use super::loader_fields::{
QueryLoaderField, QueryLoaderFieldEnumValue, QueryVersionField,
VersionField,
};
use super::{User, ids::*};
use super::{DBUser, ids::*};
use crate::database::models;
use crate::database::models::DatabaseError;
use crate::database::redis::RedisPool;
@@ -57,7 +57,7 @@ impl LinkUrl {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct GalleryItem {
pub struct DBGalleryItem {
pub image_url: String,
pub raw_image_url: String,
pub featured: bool,
@@ -67,7 +67,7 @@ pub struct GalleryItem {
pub ordering: i64,
}
impl GalleryItem {
impl DBGalleryItem {
pub async fn insert_many(
items: Vec<Self>,
project_id: DBProjectId,
@@ -117,13 +117,13 @@ impl GalleryItem {
}
}
pub struct ModCategory {
pub struct DBModCategory {
pub project_id: DBProjectId,
pub category_id: CategoryId,
pub is_additional: bool,
}
impl ModCategory {
impl DBModCategory {
pub async fn insert_many(
items: Vec<Self>,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -171,7 +171,7 @@ pub struct ProjectBuilder {
pub license: String,
pub slug: Option<String>,
pub link_urls: Vec<LinkUrl>,
pub gallery_items: Vec<GalleryItem>,
pub gallery_items: Vec<DBGalleryItem>,
pub color: Option<u32>,
pub monetization_status: MonetizationStatus,
}
@@ -181,7 +181,7 @@ impl ProjectBuilder {
self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<DBProjectId, DatabaseError> {
let project_struct = Project {
let project_struct = DBProject {
id: self.project_id,
team_id: self.team_id,
organization_id: self.organization_id,
@@ -234,7 +234,7 @@ impl ProjectBuilder {
)
.await?;
GalleryItem::insert_many(
DBGalleryItem::insert_many(
gallery_items,
self.project_id,
&mut *transaction,
@@ -244,26 +244,26 @@ impl ProjectBuilder {
let project_id = self.project_id;
let mod_categories = categories
.into_iter()
.map(|category_id| ModCategory {
.map(|category_id| DBModCategory {
project_id,
category_id,
is_additional: false,
})
.chain(additional_categories.into_iter().map(|category_id| {
ModCategory {
DBModCategory {
project_id,
category_id,
is_additional: true,
}
}))
.collect_vec();
ModCategory::insert_many(mod_categories, &mut *transaction).await?;
DBModCategory::insert_many(mod_categories, &mut *transaction).await?;
Ok(self.project_id)
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Project {
pub struct DBProject {
pub id: DBProjectId,
pub team_id: DBTeamId,
pub organization_id: Option<DBOrganizationId>,
@@ -291,7 +291,7 @@ pub struct Project {
pub loaders: Vec<String>,
}
impl Project {
impl DBProject {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -343,7 +343,7 @@ impl Project {
let project = Self::get_id(id, &mut **transaction, redis).await?;
if let Some(project) = project {
Project::clear_cache(id, project.inner.slug, Some(true), redis)
DBProject::clear_cache(id, project.inner.slug, Some(true), redis)
.await?;
sqlx::query!(
@@ -376,7 +376,8 @@ impl Project {
.execute(&mut **transaction)
.await?;
models::Thread::remove_full(project.thread_id, transaction).await?;
models::DBThread::remove_full(project.thread_id, transaction)
.await?;
sqlx::query!(
"
@@ -410,7 +411,7 @@ impl Project {
.await?;
for version in project.versions {
super::Version::remove_full(version, redis, transaction)
super::DBVersion::remove_full(version, redis, transaction)
.await?;
}
@@ -444,7 +445,7 @@ impl Project {
.execute(&mut **transaction)
.await?;
models::TeamMember::clear_cache(project.inner.team_id, redis)
models::DBTeamMember::clear_cache(project.inner.team_id, redis)
.await?;
let affected_user_ids = sqlx::query!(
@@ -460,7 +461,7 @@ impl Project {
.try_collect::<Vec<_>>()
.await?;
User::clear_project_cache(&affected_user_ids, redis).await?;
DBUser::clear_project_cache(&affected_user_ids, redis).await?;
sqlx::query!(
"
@@ -482,11 +483,11 @@ impl Project {
string: &str,
executor: E,
redis: &RedisPool,
) -> Result<Option<QueryProject>, DatabaseError>
) -> Result<Option<ProjectQueryResult>, DatabaseError>
where
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
{
Project::get_many(&[string], executor, redis)
DBProject::get_many(&[string], executor, redis)
.await
.map(|x| x.into_iter().next())
}
@@ -495,11 +496,11 @@ impl Project {
id: DBProjectId,
executor: E,
redis: &RedisPool,
) -> Result<Option<QueryProject>, DatabaseError>
) -> Result<Option<ProjectQueryResult>, DatabaseError>
where
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
{
Project::get_many(
DBProject::get_many(
&[crate::models::ids::ProjectId::from(id)],
executor,
redis,
@@ -512,7 +513,7 @@ impl Project {
project_ids: &[DBProjectId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<QueryProject>, DatabaseError>
) -> Result<Vec<ProjectQueryResult>, DatabaseError>
where
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
{
@@ -520,7 +521,7 @@ impl Project {
.iter()
.map(|x| crate::models::ids::ProjectId::from(*x))
.collect::<Vec<_>>();
Project::get_many(&ids, exec, redis).await
DBProject::get_many(&ids, exec, redis).await
}
pub async fn get_many<
@@ -531,7 +532,7 @@ impl Project {
project_strings: &[T],
exec: E,
redis: &RedisPool,
) -> Result<Vec<QueryProject>, DatabaseError>
) -> Result<Vec<ProjectQueryResult>, DatabaseError>
where
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
{
@@ -638,7 +639,7 @@ impl Project {
.try_collect()
.await?;
let mods_gallery: DashMap<DBProjectId, Vec<GalleryItem>> = sqlx::query!(
let mods_gallery: DashMap<DBProjectId, Vec<DBGalleryItem>> = sqlx::query!(
"
SELECT DISTINCT mod_id, mg.image_url, mg.raw_image_url, mg.featured, mg.name, mg.description, mg.created, mg.ordering
FROM mods_gallery mg
@@ -648,10 +649,10 @@ impl Project {
&project_ids_parsed,
&slugs
).fetch(&mut *exec)
.try_fold(DashMap::new(), |acc : DashMap<DBProjectId, Vec<GalleryItem>>, m| {
.try_fold(DashMap::new(), |acc : DashMap<DBProjectId, Vec<DBGalleryItem>>, m| {
acc.entry(DBProjectId(m.mod_id))
.or_default()
.push(GalleryItem {
.push(DBGalleryItem {
image_url: m.image_url,
raw_image_url: m.raw_image_url,
featured: m.featured.unwrap_or(false),
@@ -802,8 +803,8 @@ impl Project {
.filter(|x| loader_loader_field_ids.contains(&x.id))
.collect::<Vec<_>>();
let project = QueryProject {
inner: Project {
let project = ProjectQueryResult {
inner: DBProject {
id: DBProjectId(id),
team_id: DBTeamId(m.team_id),
organization_id: m.organization_id.map(DBOrganizationId),
@@ -958,15 +959,15 @@ impl Project {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct QueryProject {
pub inner: Project,
pub struct ProjectQueryResult {
pub inner: DBProject,
pub categories: Vec<String>,
pub additional_categories: Vec<String>,
pub versions: Vec<DBVersionId>,
pub project_types: Vec<String>,
pub games: Vec<String>,
pub urls: Vec<LinkUrl>,
pub gallery_items: Vec<GalleryItem>,
pub gallery_items: Vec<DBGalleryItem>,
pub thread_id: DBThreadId,
pub aggregate_version_fields: Vec<VersionField>,
}

View File

@@ -1,7 +1,7 @@
use super::ids::*;
use chrono::{DateTime, Utc};
pub struct Report {
pub struct DBReport {
pub id: DBReportId,
pub report_type_id: ReportTypeId,
pub project_id: Option<DBProjectId>,
@@ -13,7 +13,7 @@ pub struct Report {
pub closed: bool,
}
pub struct QueryReport {
pub struct ReportQueryResult {
pub id: DBReportId,
pub report_type: String,
pub project_id: Option<DBProjectId>,
@@ -26,7 +26,7 @@ pub struct QueryReport {
pub thread_id: DBThreadId,
}
impl Report {
impl DBReport {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -59,7 +59,7 @@ impl Report {
pub async fn get<'a, E>(
id: DBReportId,
exec: E,
) -> Result<Option<QueryReport>, sqlx::Error>
) -> Result<Option<ReportQueryResult>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -71,7 +71,7 @@ impl Report {
pub async fn get_many<'a, E>(
report_ids: &[DBReportId],
exec: E,
) -> Result<Vec<QueryReport>, sqlx::Error>
) -> Result<Vec<ReportQueryResult>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -91,7 +91,7 @@ impl Report {
&report_ids_parsed
)
.fetch(exec)
.map_ok(|x| QueryReport {
.map_ok(|x| ReportQueryResult {
id: DBReportId(x.id),
report_type: x.name,
project_id: x.mod_id.map(DBProjectId),
@@ -103,7 +103,7 @@ impl Report {
closed: x.closed,
thread_id: DBThreadId(x.thread_id)
})
.try_collect::<Vec<QueryReport>>()
.try_collect::<Vec<ReportQueryResult>>()
.await?;
Ok(reports)
@@ -137,7 +137,7 @@ impl Report {
.await?;
if let Some(thread_id) = thread_id {
crate::database::models::Thread::remove_full(
crate::database::models::DBThread::remove_full(
DBThreadId(thread_id.id),
transaction,
)

View File

@@ -62,7 +62,7 @@ impl SessionBuilder {
}
#[derive(Deserialize, Serialize)]
pub struct Session {
pub struct DBSession {
pub id: DBSessionId,
pub session: String,
pub user_id: DBUserId,
@@ -81,7 +81,7 @@ pub struct Session {
pub ip: String,
}
impl Session {
impl DBSession {
pub async fn get<
'a,
E,
@@ -90,7 +90,7 @@ impl Session {
id: T,
exec: E,
redis: &RedisPool,
) -> Result<Option<Session>, DatabaseError>
) -> Result<Option<DBSession>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -103,11 +103,11 @@ impl Session {
id: DBSessionId,
executor: E,
redis: &RedisPool,
) -> Result<Option<Session>, DatabaseError>
) -> Result<Option<DBSession>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
Session::get_many(
DBSession::get_many(
&[crate::models::ids::SessionId::from(id)],
executor,
redis,
@@ -120,7 +120,7 @@ impl Session {
session_ids: &[DBSessionId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<Session>, DatabaseError>
) -> Result<Vec<DBSession>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -128,7 +128,7 @@ impl Session {
.iter()
.map(|x| crate::models::ids::SessionId::from(*x))
.collect::<Vec<_>>();
Session::get_many(&ids, exec, redis).await
DBSession::get_many(&ids, exec, redis).await
}
pub async fn get_many<
@@ -139,7 +139,7 @@ impl Session {
session_strings: &[T],
exec: E,
redis: &RedisPool,
) -> Result<Vec<Session>, DatabaseError>
) -> Result<Vec<DBSession>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -173,7 +173,7 @@ impl Session {
)
.fetch(exec)
.try_fold(DashMap::new(), |acc, x| {
let session = Session {
let session = DBSession {
id: DBSessionId(x.id),
session: x.session.clone(),
user_id: DBUserId(x.user_id),

View File

@@ -1,4 +1,4 @@
use super::{Organization, Project, ids::*};
use super::{DBOrganization, DBProject, ids::*};
use crate::{
database::redis::RedisPool,
models::teams::{OrganizationPermissions, ProjectPermissions},
@@ -32,7 +32,7 @@ impl TeamBuilder {
) -> Result<DBTeamId, super::DatabaseError> {
let team_id = generate_team_id(transaction).await?;
let team = Team { id: team_id };
let team = DBTeam { id: team_id };
sqlx::query!(
"
@@ -109,7 +109,7 @@ impl TeamBuilder {
}
/// A team of users who control a project
pub struct Team {
pub struct DBTeam {
/// The id of the team
pub id: DBTeamId,
}
@@ -120,7 +120,7 @@ pub enum TeamAssociationId {
Organization(DBOrganizationId),
}
impl Team {
impl DBTeam {
pub async fn get_association<'a, 'b, E>(
id: DBTeamId,
executor: E,
@@ -165,7 +165,7 @@ impl Team {
/// A member of a team
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct TeamMember {
pub struct DBTeamMember {
pub id: DBTeamMemberId,
pub team_id: DBTeamId,
@@ -187,13 +187,13 @@ pub struct TeamMember {
pub ordering: i64,
}
impl TeamMember {
impl DBTeamMember {
// Lists the full members of a team
pub async fn get_from_team_full<'a, 'b, E>(
id: DBTeamId,
executor: E,
redis: &RedisPool,
) -> Result<Vec<TeamMember>, super::DatabaseError>
) -> Result<Vec<DBTeamMember>, super::DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
@@ -204,7 +204,7 @@ impl TeamMember {
team_ids: &[DBTeamId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<TeamMember>, super::DatabaseError>
) -> Result<Vec<DBTeamMember>, super::DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
@@ -228,8 +228,8 @@ impl TeamMember {
&team_ids
)
.fetch(exec)
.try_fold(DashMap::new(), |acc: DashMap<i64, Vec<TeamMember>>, m| {
let member = TeamMember {
.try_fold(DashMap::new(), |acc: DashMap<i64, Vec<DBTeamMember>>, m| {
let member = DBTeamMember {
id: DBTeamMemberId(m.id),
team_id: DBTeamId(m.team_id),
role: m.member_role,
@@ -307,7 +307,7 @@ impl TeamMember {
user_id as DBUserId
)
.fetch(executor)
.map_ok(|m| TeamMember {
.map_ok(|m| DBTeamMember {
id: DBTeamMemberId(m.id),
team_id: DBTeamId(m.team_id),
user_id,
@@ -322,7 +322,7 @@ impl TeamMember {
payouts_split: m.payouts_split,
ordering: m.ordering,
})
.try_collect::<Vec<TeamMember>>()
.try_collect::<Vec<DBTeamMember>>()
.await?;
Ok(team_members)
@@ -354,7 +354,7 @@ impl TeamMember {
.await?;
if let Some(m) = result {
Ok(Some(TeamMember {
Ok(Some(DBTeamMember {
id: DBTeamMemberId(m.id),
team_id: id,
user_id,
@@ -577,7 +577,7 @@ impl TeamMember {
.await?;
if let Some(m) = result {
Ok(Some(TeamMember {
Ok(Some(DBTeamMember {
id: DBTeamMemberId(m.id),
team_id: DBTeamId(m.team_id),
user_id,
@@ -629,7 +629,7 @@ impl TeamMember {
.await?;
if let Some(m) = result {
Ok(Some(TeamMember {
Ok(Some(DBTeamMember {
id: DBTeamMemberId(m.id),
team_id: DBTeamId(m.team_id),
user_id,
@@ -675,7 +675,7 @@ impl TeamMember {
.await?;
if let Some(m) = result {
Ok(Some(TeamMember {
Ok(Some(DBTeamMember {
id: DBTeamMemberId(m.id),
team_id: DBTeamId(m.team_id),
user_id,
@@ -702,7 +702,7 @@ impl TeamMember {
// - project team member (a user's membership to a given project)
// - organization team member (a user's membership to a given organization that owns a given project)
pub async fn get_for_project_permissions<'a, 'b, E>(
project: &Project,
project: &DBProject,
user_id: DBUserId,
executor: E,
) -> Result<(Option<Self>, Option<Self>), super::DatabaseError>
@@ -713,7 +713,7 @@ impl TeamMember {
Self::get_from_user_id(project.team_id, user_id, executor).await?;
let organization =
Organization::get_associated_organization_project_id(
DBOrganization::get_associated_organization_project_id(
project.id, executor,
)
.await?;

View File

@@ -12,14 +12,14 @@ pub struct ThreadBuilder {
}
#[derive(Clone, Serialize)]
pub struct Thread {
pub struct DBThread {
pub id: DBThreadId,
pub project_id: Option<DBProjectId>,
pub report_id: Option<DBReportId>,
pub type_: ThreadType,
pub messages: Vec<ThreadMessage>,
pub messages: Vec<DBThreadMessage>,
pub members: Vec<DBUserId>,
}
@@ -31,7 +31,7 @@ pub struct ThreadMessageBuilder {
}
#[derive(Serialize, Deserialize, Clone)]
pub struct ThreadMessage {
pub struct DBThreadMessage {
pub id: DBThreadMessageId,
pub thread_id: DBThreadId,
pub author_id: Option<DBUserId>,
@@ -111,11 +111,11 @@ impl ThreadBuilder {
}
}
impl Thread {
impl DBThread {
pub async fn get<'a, E>(
id: DBThreadId,
exec: E,
) -> Result<Option<Thread>, sqlx::Error>
) -> Result<Option<DBThread>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
@@ -127,7 +127,7 @@ impl Thread {
pub async fn get_many<'a, E>(
thread_ids: &[DBThreadId],
exec: E,
) -> Result<Vec<Thread>, sqlx::Error>
) -> Result<Vec<DBThread>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
@@ -149,13 +149,13 @@ impl Thread {
&thread_ids_parsed
)
.fetch(exec)
.map_ok(|x| Thread {
.map_ok(|x| DBThread {
id: DBThreadId(x.id),
project_id: x.mod_id.map(DBProjectId),
report_id: x.report_id.map(DBReportId),
type_: ThreadType::from_string(&x.thread_type),
messages: {
let mut messages: Vec<ThreadMessage> = serde_json::from_value(
let mut messages: Vec<DBThreadMessage> = serde_json::from_value(
x.messages.unwrap_or_default(),
)
.ok()
@@ -165,7 +165,7 @@ impl Thread {
},
members: x.members.unwrap_or_default().into_iter().map(DBUserId).collect(),
})
.try_collect::<Vec<Thread>>()
.try_collect::<Vec<DBThread>>()
.await?;
Ok(threads)
@@ -207,11 +207,11 @@ impl Thread {
}
}
impl ThreadMessage {
impl DBThreadMessage {
pub async fn get<'a, E>(
id: DBThreadMessageId,
exec: E,
) -> Result<Option<ThreadMessage>, sqlx::Error>
) -> Result<Option<DBThreadMessage>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -223,7 +223,7 @@ impl ThreadMessage {
pub async fn get_many<'a, E>(
message_ids: &[DBThreadMessageId],
exec: E,
) -> Result<Vec<ThreadMessage>, sqlx::Error>
) -> Result<Vec<DBThreadMessage>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -240,7 +240,7 @@ impl ThreadMessage {
&message_ids_parsed
)
.fetch(exec)
.map_ok(|x| ThreadMessage {
.map_ok(|x| DBThreadMessage {
id: DBThreadMessageId(x.id),
thread_id: DBThreadId(x.thread_id),
author_id: x.author_id.map(DBUserId),
@@ -248,7 +248,7 @@ impl ThreadMessage {
created: x.created,
hide_identity: x.hide_identity,
})
.try_collect::<Vec<ThreadMessage>>()
.try_collect::<Vec<DBThreadMessage>>()
.await?;
Ok(messages)

View File

@@ -1,8 +1,8 @@
use super::ids::{DBProjectId, DBUserId};
use super::{DBCollectionId, DBReportId, DBThreadId};
use crate::database::models;
use crate::database::models::charge_item::ChargeItem;
use crate::database::models::user_subscription_item::UserSubscriptionItem;
use crate::database::models::charge_item::DBCharge;
use crate::database::models::user_subscription_item::DBUserSubscription;
use crate::database::models::{DBOrganizationId, DatabaseError};
use crate::database::redis::RedisPool;
use crate::models::billing::ChargeStatus;
@@ -19,7 +19,7 @@ const USER_USERNAMES_NAMESPACE: &str = "users_usernames";
const USERS_PROJECTS_NAMESPACE: &str = "users_projects";
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct User {
pub struct DBUser {
pub id: DBUserId,
pub github_id: Option<i64>,
@@ -51,7 +51,7 @@ pub struct User {
pub allow_friend_requests: bool,
}
impl User {
impl DBUser {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -104,11 +104,11 @@ impl User {
string: &str,
executor: E,
redis: &RedisPool,
) -> Result<Option<User>, DatabaseError>
) -> Result<Option<DBUser>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
User::get_many(&[string], executor, redis)
DBUser::get_many(&[string], executor, redis)
.await
.map(|x| x.into_iter().next())
}
@@ -117,11 +117,11 @@ impl User {
id: DBUserId,
executor: E,
redis: &RedisPool,
) -> Result<Option<User>, DatabaseError>
) -> Result<Option<DBUser>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
User::get_many(&[ariadne::ids::UserId::from(id)], executor, redis)
DBUser::get_many(&[ariadne::ids::UserId::from(id)], executor, redis)
.await
.map(|x| x.into_iter().next())
}
@@ -130,7 +130,7 @@ impl User {
user_ids: &[DBUserId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<User>, DatabaseError>
) -> Result<Vec<DBUser>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -138,7 +138,7 @@ impl User {
.iter()
.map(|x| ariadne::ids::UserId::from(*x))
.collect::<Vec<_>>();
User::get_many(&ids, exec, redis).await
DBUser::get_many(&ids, exec, redis).await
}
pub async fn get_many<
@@ -149,7 +149,7 @@ impl User {
users_strings: &[T],
exec: E,
redis: &RedisPool,
) -> Result<Vec<User>, DatabaseError>
) -> Result<Vec<DBUser>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -187,7 +187,7 @@ impl User {
)
.fetch(exec)
.try_fold(DashMap::new(), |acc, u| {
let user = User {
let user = DBUser {
id: DBUserId(u.id),
github_id: u.github_id,
discord_id: u.discord_id,
@@ -459,7 +459,7 @@ impl User {
let user = Self::get_id(id, &mut **transaction, redis).await?;
if let Some(delete_user) = user {
User::clear_caches(&[(id, Some(delete_user.username))], redis)
DBUser::clear_caches(&[(id, Some(delete_user.username))], redis)
.await?;
let deleted_user: DBUserId =
@@ -536,7 +536,7 @@ impl User {
.await?;
for collection_id in user_collections {
models::Collection::remove(collection_id, transaction, redis)
models::DBCollection::remove(collection_id, transaction, redis)
.await?;
}
@@ -555,7 +555,7 @@ impl User {
.await?;
for thread_id in report_threads {
models::Thread::remove_full(thread_id, transaction).await?;
models::DBThread::remove_full(thread_id, transaction).await?;
}
sqlx::query!(
@@ -661,12 +661,12 @@ impl User {
.await?;
let open_subscriptions =
UserSubscriptionItem::get_all_user(id, &mut **transaction)
DBUserSubscription::get_all_user(id, &mut **transaction)
.await?;
for x in open_subscriptions {
let charge =
ChargeItem::get_open_subscription(x.id, &mut **transaction)
DBCharge::get_open_subscription(x.id, &mut **transaction)
.await?;
if let Some(mut charge) = charge {
charge.status = ChargeStatus::Cancelled;

View File

@@ -8,7 +8,7 @@ use chrono::{DateTime, Utc};
use itertools::Itertools;
use std::convert::{TryFrom, TryInto};
pub struct UserSubscriptionItem {
pub struct DBUserSubscription {
pub id: DBUserSubscriptionId,
pub user_id: DBUserId,
pub price_id: DBProductPriceId,
@@ -18,7 +18,7 @@ pub struct UserSubscriptionItem {
pub metadata: Option<SubscriptionMetadata>,
}
struct UserSubscriptionResult {
struct UserSubscriptionQueryResult {
id: i64,
user_id: i64,
price_id: i64,
@@ -31,7 +31,7 @@ struct UserSubscriptionResult {
macro_rules! select_user_subscriptions_with_predicate {
($predicate:tt, $param:ident) => {
sqlx::query_as!(
UserSubscriptionResult,
UserSubscriptionQueryResult,
r#"
SELECT
us.id, us.user_id, us.price_id, us.interval, us.created, us.status, us.metadata
@@ -43,11 +43,11 @@ macro_rules! select_user_subscriptions_with_predicate {
};
}
impl TryFrom<UserSubscriptionResult> for UserSubscriptionItem {
impl TryFrom<UserSubscriptionQueryResult> for DBUserSubscription {
type Error = serde_json::Error;
fn try_from(r: UserSubscriptionResult) -> Result<Self, Self::Error> {
Ok(UserSubscriptionItem {
fn try_from(r: UserSubscriptionQueryResult) -> Result<Self, Self::Error> {
Ok(DBUserSubscription {
id: DBUserSubscriptionId(r.id),
user_id: DBUserId(r.user_id),
price_id: DBProductPriceId(r.price_id),
@@ -59,18 +59,18 @@ impl TryFrom<UserSubscriptionResult> for UserSubscriptionItem {
}
}
impl UserSubscriptionItem {
impl DBUserSubscription {
pub async fn get(
id: DBUserSubscriptionId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Option<UserSubscriptionItem>, DatabaseError> {
) -> Result<Option<DBUserSubscription>, DatabaseError> {
Ok(Self::get_many(&[id], exec).await?.into_iter().next())
}
pub async fn get_many(
ids: &[DBUserSubscriptionId],
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<UserSubscriptionItem>, DatabaseError> {
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
let ids = ids.iter().map(|id| id.0).collect_vec();
let ids_ref: &[i64] = &ids;
let results = select_user_subscriptions_with_predicate!(
@@ -89,7 +89,7 @@ impl UserSubscriptionItem {
pub async fn get_all_user(
user_id: DBUserId,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<UserSubscriptionItem>, DatabaseError> {
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
let user_id = user_id.0;
let results = select_user_subscriptions_with_predicate!(
"WHERE us.user_id = $1",
@@ -107,7 +107,7 @@ impl UserSubscriptionItem {
pub async fn get_all_servers(
status: Option<SubscriptionStatus>,
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<UserSubscriptionItem>, DatabaseError> {
) -> Result<Vec<DBUserSubscription>, DatabaseError> {
let status = status.map(|x| x.as_str());
let results = select_user_subscriptions_with_predicate!(

View File

@@ -179,7 +179,7 @@ impl VersionBuilder {
self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<DBVersionId, DatabaseError> {
let version = Version {
let version = DBVersion {
id: self.version_id,
project_id: self.project_id,
author_id: self.author_id,
@@ -229,12 +229,12 @@ impl VersionBuilder {
let loader_versions = loaders
.iter()
.map(|&loader_id| LoaderVersion {
.map(|&loader_id| DBLoaderVersion {
loader_id,
version_id,
})
.collect_vec();
LoaderVersion::insert_many(loader_versions, transaction).await?;
DBLoaderVersion::insert_many(loader_versions, transaction).await?;
VersionField::insert_many(self.version_fields, transaction).await?;
@@ -243,12 +243,12 @@ impl VersionBuilder {
}
#[derive(Serialize, Deserialize)]
pub struct LoaderVersion {
pub struct DBLoaderVersion {
pub loader_id: LoaderId,
pub version_id: DBVersionId,
}
impl LoaderVersion {
impl DBLoaderVersion {
pub async fn insert_many(
items: Vec<Self>,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -273,7 +273,7 @@ impl LoaderVersion {
}
#[derive(Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct Version {
pub struct DBVersion {
pub id: DBVersionId,
pub project_id: DBProjectId,
pub author_id: DBUserId,
@@ -289,7 +289,7 @@ pub struct Version {
pub ordering: Option<i32>,
}
impl Version {
impl DBVersion {
pub async fn insert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -339,7 +339,7 @@ impl Version {
return Ok(None);
};
Version::clear_cache(&result, redis).await?;
DBVersion::clear_cache(&result, redis).await?;
sqlx::query!(
"
@@ -447,7 +447,7 @@ impl Version {
.execute(&mut **transaction)
.await?;
crate::database::models::Project::clear_cache(
crate::database::models::DBProject::clear_cache(
DBProjectId(project_id.mod_id),
None,
None,
@@ -462,7 +462,7 @@ impl Version {
id: DBVersionId,
executor: E,
redis: &RedisPool,
) -> Result<Option<QueryVersion>, DatabaseError>
) -> Result<Option<VersionQueryResult>, DatabaseError>
where
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
{
@@ -475,7 +475,7 @@ impl Version {
version_ids: &[DBVersionId],
exec: E,
redis: &RedisPool,
) -> Result<Vec<QueryVersion>, DatabaseError>
) -> Result<Vec<VersionQueryResult>, DatabaseError>
where
E: sqlx::Acquire<'a, Database = sqlx::Postgres>,
{
@@ -684,7 +684,7 @@ impl Version {
})
.await?;
let dependencies : DashMap<DBVersionId, Vec<QueryDependency>> = sqlx::query!(
let dependencies : DashMap<DBVersionId, Vec<DependencyQueryResult>> = sqlx::query!(
"
SELECT DISTINCT dependent_id as version_id, d.mod_dependency_id as dependency_project_id, d.dependency_id as dependency_version_id, d.dependency_file_name as file_name, d.dependency_type as dependency_type
FROM dependencies d
@@ -692,8 +692,8 @@ impl Version {
",
&version_ids
).fetch(&mut *exec)
.try_fold(DashMap::new(), |acc : DashMap<_,Vec<QueryDependency>>, m| {
let dependency = QueryDependency {
.try_fold(DashMap::new(), |acc : DashMap<_,Vec<DependencyQueryResult>>, m| {
let dependency = DependencyQueryResult {
project_id: m.dependency_project_id.map(DBProjectId),
version_id: m.dependency_version_id.map(DBVersionId),
file_name: m.file_name,
@@ -735,8 +735,8 @@ impl Version {
.filter(|x| loader_loader_field_ids.contains(&x.id))
.collect::<Vec<_>>();
let query_version = QueryVersion {
inner: Version {
let query_version = VersionQueryResult {
inner: DBVersion {
id: DBVersionId(v.id),
project_id: DBProjectId(v.mod_id),
author_id: DBUserId(v.author_id),
@@ -765,7 +765,7 @@ impl Version {
}
}
QueryFile {
FileQueryResult {
id: x.id,
url: x.url.clone(),
filename: x.filename.clone(),
@@ -815,7 +815,7 @@ impl Version {
version_id: Option<DBVersionId>,
executor: E,
redis: &RedisPool,
) -> Result<Option<SingleFile>, DatabaseError>
) -> Result<Option<DBFile>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
@@ -832,7 +832,7 @@ impl Version {
hashes: &[String],
executor: E,
redis: &RedisPool,
) -> Result<Vec<SingleFile>, DatabaseError>
) -> Result<Vec<DBFile>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
@@ -872,7 +872,7 @@ impl Version {
if let Some(hash) = hashes.get(&algorithm) {
let key = format!("{algorithm}_{hash}");
let file = SingleFile {
let file = DBFile {
id: DBFileId(f.id),
version_id: DBVersionId(f.version_id),
project_id: DBProjectId(f.mod_id),
@@ -899,7 +899,7 @@ impl Version {
}
pub async fn clear_cache(
version: &QueryVersion,
version: &VersionQueryResult,
redis: &RedisPool,
) -> Result<(), DatabaseError> {
let mut redis = redis.connect().await?;
@@ -927,19 +927,19 @@ impl Version {
}
#[derive(Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct QueryVersion {
pub inner: Version,
pub struct VersionQueryResult {
pub inner: DBVersion,
pub files: Vec<QueryFile>,
pub files: Vec<FileQueryResult>,
pub version_fields: Vec<VersionField>,
pub loaders: Vec<String>,
pub project_types: Vec<String>,
pub games: Vec<String>,
pub dependencies: Vec<QueryDependency>,
pub dependencies: Vec<DependencyQueryResult>,
}
#[derive(Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct QueryDependency {
pub struct DependencyQueryResult {
pub project_id: Option<DBProjectId>,
pub version_id: Option<DBVersionId>,
pub file_name: Option<String>,
@@ -947,7 +947,7 @@ pub struct QueryDependency {
}
#[derive(Clone, Deserialize, Serialize, PartialEq, Eq)]
pub struct QueryFile {
pub struct FileQueryResult {
pub id: DBFileId,
pub url: String,
pub filename: String,
@@ -958,7 +958,7 @@ pub struct QueryFile {
}
#[derive(Clone, Deserialize, Serialize)]
pub struct SingleFile {
pub struct DBFile {
pub id: DBFileId,
pub version_id: DBVersionId,
pub project_id: DBProjectId,
@@ -970,19 +970,19 @@ pub struct SingleFile {
pub file_type: Option<FileType>,
}
impl std::cmp::Ord for QueryVersion {
impl std::cmp::Ord for VersionQueryResult {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.inner.cmp(&other.inner)
}
}
impl std::cmp::PartialOrd for QueryVersion {
impl std::cmp::PartialOrd for VersionQueryResult {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl std::cmp::Ord for Version {
impl std::cmp::Ord for DBVersion {
fn cmp(&self, other: &Self) -> Ordering {
let ordering_order = match (self.ordering, other.ordering) {
(None, None) => Ordering::Equal,
@@ -998,7 +998,7 @@ impl std::cmp::Ord for Version {
}
}
impl std::cmp::PartialOrd for Version {
impl std::cmp::PartialOrd for DBVersion {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
@@ -1035,8 +1035,8 @@ mod tests {
id: i64,
ordering: Option<i32>,
date_published: DateTime<Utc>,
) -> Version {
Version {
) -> DBVersion {
DBVersion {
id: DBVersionId(id),
ordering,
date_published,