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

@@ -71,7 +71,7 @@ pub async fn count_download(
.ok()
.flatten();
let project_id: crate::database::models::ids::ProjectId =
let project_id: crate::database::models::ids::DBProjectId =
download_body.project_id.into();
let id_option =
@@ -97,7 +97,7 @@ pub async fn count_download(
WHERE ((version_number = $1 OR id = $3) AND mod_id = $2)
",
download_body.version_name,
project_id as crate::database::models::ids::ProjectId,
project_id as crate::database::models::ids::DBProjectId,
id_option
)
.fetch_optional(pool.as_ref())
@@ -255,7 +255,7 @@ pub async fn delphi_result_ingest(
let mut transaction = pool.begin().await?;
ThreadMessageBuilder {
author_id: Some(crate::database::models::UserId(AUTOMOD_ID)),
author_id: Some(crate::database::models::DBUserId(AUTOMOD_ID)),
body: MessageBody::Text {
body: thread_header,
private: true,

View File

@@ -85,7 +85,7 @@ pub async fn products(
#[derive(Deserialize)]
struct SubscriptionsQuery {
pub user_id: Option<crate::models::ids::UserId>,
pub user_id: Option<ariadne::ids::UserId>,
}
#[get("subscriptions")]
@@ -600,7 +600,7 @@ pub async fn user_customer(
#[derive(Deserialize)]
pub struct ChargesQuery {
pub user_id: Option<crate::models::ids::UserId>,
pub user_id: Option<ariadne::ids::UserId>,
}
#[get("payments")]
@@ -944,7 +944,7 @@ pub async fn active_servers(
#[derive(Serialize)]
struct ActiveServer {
pub user_id: crate::models::ids::UserId,
pub user_id: ariadne::ids::UserId,
pub server_id: String,
pub price_id: crate::models::ids::ProductPriceId,
pub interval: PriceDuration,
@@ -1439,7 +1439,7 @@ pub async fn stripe_webhook(
let user_id = if let Some(user_id) = metadata
.get("modrinth_user_id")
.and_then(|x| parse_base62(x).ok())
.map(|x| crate::database::models::ids::UserId(x as i64))
.map(|x| crate::database::models::ids::DBUserId(x as i64))
{
user_id
} else {
@@ -1464,7 +1464,7 @@ pub async fn stripe_webhook(
let charge_id = if let Some(charge_id) = metadata
.get("modrinth_charge_id")
.and_then(|x| parse_base62(x).ok())
.map(|x| crate::database::models::ids::ChargeId(x as i64))
.map(|x| crate::database::models::ids::DBChargeId(x as i64))
{
charge_id
} else {
@@ -1557,7 +1557,7 @@ pub async fn stripe_webhook(
.get("modrinth_price_id")
.and_then(|x| parse_base62(x).ok())
.map(|x| {
crate::database::models::ids::ProductPriceId(
crate::database::models::ids::DBProductPriceId(
x as i64,
)
}) {
@@ -1601,7 +1601,7 @@ pub async fn stripe_webhook(
.get("modrinth_subscription_id")
.and_then(|x| parse_base62(x).ok())
.map(|x| {
crate::database::models::ids::UserSubscriptionId(x as i64)
crate::database::models::ids::DBUserSubscriptionId(x as i64)
}) {
subscription_id
} else {
@@ -1736,7 +1736,7 @@ pub async fn stripe_webhook(
",
badges.bits() as i64,
metadata.user_item.id
as crate::database::models::ids::UserId,
as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -2061,7 +2061,7 @@ pub async fn stripe_webhook(
}
async fn get_or_create_customer(
user_id: crate::models::ids::UserId,
user_id: ariadne::ids::UserId,
stripe_customer_id: Option<&str>,
user_email: Option<&str>,
client: &stripe::Client,
@@ -2212,7 +2212,7 @@ pub async fn index_subscriptions(pool: PgPool, redis: RedisPool) {
WHERE (id = $2)
",
badges.bits() as i64,
user.id as crate::database::models::ids::UserId,
user.id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;

View File

@@ -74,7 +74,7 @@ impl TempUser {
client: &PgPool,
file_host: &Arc<dyn FileHost + Send + Sync>,
redis: &RedisPool,
) -> Result<crate::database::models::UserId, AuthenticationError> {
) -> Result<crate::database::models::DBUserId, AuthenticationError> {
if let Some(email) = &self.email {
if crate::database::models::User::get_email(email, client)
.await?
@@ -115,47 +115,45 @@ impl TempUser {
}
}
let (avatar_url, raw_avatar_url) =
if let Some(avatar_url) = self.avatar_url {
let res = reqwest::get(&avatar_url).await?;
let headers = res.headers().clone();
let (avatar_url, raw_avatar_url) = if let Some(avatar_url) =
self.avatar_url
{
let res = reqwest::get(&avatar_url).await?;
let headers = res.headers().clone();
let img_data = if let Some(content_type) = headers
.get(reqwest::header::CONTENT_TYPE)
.and_then(|ct| ct.to_str().ok())
{
get_image_ext(content_type)
} else {
avatar_url.rsplit('.').next()
};
let img_data = if let Some(content_type) = headers
.get(reqwest::header::CONTENT_TYPE)
.and_then(|ct| ct.to_str().ok())
{
get_image_ext(content_type)
} else {
avatar_url.rsplit('.').next()
};
if let Some(ext) = img_data {
let bytes = res.bytes().await?;
if let Some(ext) = img_data {
let bytes = res.bytes().await?;
let upload_result = upload_image_optimized(
&format!(
"user/{}",
crate::models::users::UserId::from(user_id)
),
bytes,
ext,
Some(96),
Some(1.0),
&**file_host,
)
.await;
let upload_result = upload_image_optimized(
&format!("user/{}", ariadne::ids::UserId::from(user_id)),
bytes,
ext,
Some(96),
Some(1.0),
&**file_host,
)
.await;
if let Ok(upload_result) = upload_result {
(Some(upload_result.url), Some(upload_result.raw_url))
} else {
(None, None)
}
if let Ok(upload_result) = upload_result {
(Some(upload_result.url), Some(upload_result.raw_url))
} else {
(None, None)
}
} else {
(None, None)
};
}
} else {
(None, None)
};
if let Some(username) = username {
crate::database::models::User {
@@ -823,7 +821,7 @@ impl AuthProvider {
&self,
id: &str,
executor: E,
) -> Result<Option<crate::database::models::UserId>, AuthenticationError>
) -> Result<Option<crate::database::models::DBUserId>, AuthenticationError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
@@ -837,7 +835,7 @@ impl AuthProvider {
.fetch_optional(executor)
.await?;
value.map(|x| crate::database::models::UserId(x.id))
value.map(|x| crate::database::models::DBUserId(x.id))
}
AuthProvider::Discord => {
let value = sqlx::query!(
@@ -848,7 +846,7 @@ impl AuthProvider {
.fetch_optional(executor)
.await?;
value.map(|x| crate::database::models::UserId(x.id))
value.map(|x| crate::database::models::DBUserId(x.id))
}
AuthProvider::Microsoft => {
let value = sqlx::query!(
@@ -858,7 +856,7 @@ impl AuthProvider {
.fetch_optional(executor)
.await?;
value.map(|x| crate::database::models::UserId(x.id))
value.map(|x| crate::database::models::DBUserId(x.id))
}
AuthProvider::GitLab => {
let value = sqlx::query!(
@@ -869,7 +867,7 @@ impl AuthProvider {
.fetch_optional(executor)
.await?;
value.map(|x| crate::database::models::UserId(x.id))
value.map(|x| crate::database::models::DBUserId(x.id))
}
AuthProvider::Google => {
let value = sqlx::query!(
@@ -879,7 +877,7 @@ impl AuthProvider {
.fetch_optional(executor)
.await?;
value.map(|x| crate::database::models::UserId(x.id))
value.map(|x| crate::database::models::DBUserId(x.id))
}
AuthProvider::Steam => {
let value = sqlx::query!(
@@ -890,7 +888,7 @@ impl AuthProvider {
.fetch_optional(executor)
.await?;
value.map(|x| crate::database::models::UserId(x.id))
value.map(|x| crate::database::models::DBUserId(x.id))
}
AuthProvider::PayPal => {
let value = sqlx::query!(
@@ -900,14 +898,14 @@ impl AuthProvider {
.fetch_optional(executor)
.await?;
value.map(|x| crate::database::models::UserId(x.id))
value.map(|x| crate::database::models::DBUserId(x.id))
}
})
}
pub async fn update_user_id(
&self,
user_id: crate::database::models::UserId,
user_id: crate::database::models::DBUserId,
id: Option<&str>,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<(), AuthenticationError> {
@@ -919,7 +917,7 @@ impl AuthProvider {
SET github_id = $2
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
id.and_then(|x| x.parse::<i64>().ok())
)
.execute(&mut **transaction)
@@ -932,7 +930,7 @@ impl AuthProvider {
SET discord_id = $2
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
id.and_then(|x| x.parse::<i64>().ok())
)
.execute(&mut **transaction)
@@ -945,7 +943,7 @@ impl AuthProvider {
SET microsoft_id = $2
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
id,
)
.execute(&mut **transaction)
@@ -958,7 +956,7 @@ impl AuthProvider {
SET gitlab_id = $2
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
id.and_then(|x| x.parse::<i64>().ok())
)
.execute(&mut **transaction)
@@ -971,7 +969,7 @@ impl AuthProvider {
SET google_id = $2
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
id,
)
.execute(&mut **transaction)
@@ -984,7 +982,7 @@ impl AuthProvider {
SET steam_id = $2
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
id.and_then(|x| x.parse::<i64>().ok())
)
.execute(&mut **transaction)
@@ -998,7 +996,7 @@ impl AuthProvider {
SET paypal_country = NULL, paypal_email = NULL, paypal_id = NULL
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
)
.execute(&mut **transaction)
.await?;
@@ -1009,7 +1007,7 @@ impl AuthProvider {
SET paypal_id = $2
WHERE (id = $1)
",
user_id as crate::database::models::UserId,
user_id as crate::database::models::DBUserId,
id,
)
.execute(&mut **transaction)
@@ -1152,7 +1150,7 @@ pub async fn auth_callback(
oauth_user.country,
oauth_user.email,
oauth_user.id,
id as crate::database::models::ids::UserId,
id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -1527,7 +1525,7 @@ async fn validate_2fa_code(
input: String,
secret: String,
allow_backup: bool,
user_id: crate::database::models::UserId,
user_id: crate::database::models::DBUserId,
redis: &RedisPool,
pool: &PgPool,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
@@ -1583,7 +1581,7 @@ async fn validate_2fa_code(
DELETE FROM user_backup_codes
WHERE user_id = $1 AND code = $2
",
user_id as crate::database::models::ids::UserId,
user_id as crate::database::models::ids::DBUserId,
code as i64,
)
.execute(&mut **transaction)
@@ -1746,7 +1744,7 @@ pub async fn finish_2fa_flow(
WHERE (id = $2)
",
secret,
user_id as crate::database::models::ids::UserId,
user_id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -1756,7 +1754,7 @@ pub async fn finish_2fa_flow(
DELETE FROM user_backup_codes
WHERE user_id = $1
",
user_id as crate::database::models::ids::UserId,
user_id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -1776,7 +1774,7 @@ pub async fn finish_2fa_flow(
$1, $2
)
",
user_id as crate::database::models::ids::UserId,
user_id as crate::database::models::ids::DBUserId,
val as i64,
)
.execute(&mut *transaction)
@@ -1869,7 +1867,7 @@ pub async fn remove_2fa(
SET totp_secret = NULL
WHERE (id = $1)
",
user.id as crate::database::models::ids::UserId,
user.id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -1879,7 +1877,7 @@ pub async fn remove_2fa(
DELETE FROM user_backup_codes
WHERE user_id = $1
",
user.id as crate::database::models::ids::UserId,
user.id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -2081,7 +2079,7 @@ pub async fn change_password(
WHERE (id = $2)
",
update_password,
user.id as crate::database::models::ids::UserId,
user.id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -2291,7 +2289,7 @@ pub async fn verify_email(
SET email_verified = TRUE
WHERE (id = $1)
",
user.id as crate::database::models::ids::UserId,
user.id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;

View File

@@ -143,7 +143,7 @@ pub async fn export(
.fetch_all(pool.as_ref())
.await?
.into_iter()
.map(|x| crate::database::models::ids::ThreadMessageId(x.id))
.map(|x| crate::database::models::ids::DBThreadMessageId(x.id))
.collect::<Vec<_>>();
let messages =
@@ -163,7 +163,7 @@ pub async fn export(
.fetch_all(pool.as_ref())
.await?
.into_iter()
.map(|x| crate::database::models::ids::ImageId(x.id))
.map(|x| crate::database::models::ids::DBImageId(x.id))
.collect::<Vec<_>>();
let uploaded_images = crate::database::models::image_item::Image::get_many(

View File

@@ -56,8 +56,8 @@ pub async fn get_projects(
count.count as i64
)
.fetch(&**pool)
.map_ok(|m| database::models::ProjectId(m.id))
.try_collect::<Vec<database::models::ProjectId>>()
.map_ok(|m| database::models::DBProjectId(m.id))
.try_collect::<Vec<database::models::DBProjectId>>()
.await?;
let projects: Vec<_> =

View File

@@ -1,5 +1,5 @@
use crate::auth::{AuthenticationError, get_user_from_headers};
use crate::database::models::UserId;
use crate::database::models::DBUserId;
use crate::database::models::session_item::Session as DBSession;
use crate::database::models::session_item::SessionBuilder;
use crate::database::redis::RedisPool;
@@ -85,7 +85,7 @@ pub async fn get_session_metadata(
pub async fn issue_session(
req: HttpRequest,
user_id: UserId,
user_id: DBUserId,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
redis: &RedisPool,
) -> Result<DBSession, AuthenticationError> {

View File

@@ -4,8 +4,8 @@ use crate::database::models::loader_fields::Loader;
use crate::database::models::project_item::QueryProject;
use crate::database::models::version_item::{QueryFile, QueryVersion};
use crate::database::redis::RedisPool;
use crate::models::ids::{ProjectId, VersionId};
use crate::models::pats::Scopes;
use crate::models::projects::{ProjectId, VersionId};
use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
use crate::{auth::get_user_from_headers, database};
@@ -103,7 +103,7 @@ pub async fn maven_metadata(
WHERE mod_id = $1 AND status = ANY($2)
ORDER BY ordering ASC NULLS LAST, date_published ASC
",
project.inner.id as database::models::ids::ProjectId,
project.inner.id as database::models::ids::DBProjectId,
&*crate::models::projects::VersionStatus::iterator()
.filter(|x| x.is_listed())
.map(|x| x.to_string())

View File

@@ -126,7 +126,7 @@ pub async fn report_get(
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
info: web::Path<(crate::models::reports::ReportId,)>,
info: web::Path<(crate::models::ids::ReportId,)>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {
let response =
@@ -156,7 +156,7 @@ pub async fn report_edit(
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
info: web::Path<(crate::models::reports::ReportId,)>,
info: web::Path<(crate::models::ids::ReportId,)>,
session_queue: web::Data<AuthQueue>,
edit_report: web::Json<EditReport>,
) -> Result<HttpResponse, ApiError> {
@@ -181,7 +181,7 @@ pub async fn report_edit(
pub async fn report_delete(
req: HttpRequest,
pool: web::Data<PgPool>,
info: web::Path<(crate::models::reports::ReportId,)>,
info: web::Path<(crate::models::ids::ReportId,)>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {

View File

@@ -1,12 +1,13 @@
use crate::database::redis::RedisPool;
use crate::models::ids::TeamId;
use crate::models::teams::{
OrganizationPermissions, ProjectPermissions, TeamId, TeamMember,
OrganizationPermissions, ProjectPermissions, TeamMember,
};
use crate::models::users::UserId;
use crate::models::v2::teams::LegacyTeamMember;
use crate::queue::session::AuthQueue;
use crate::routes::{ApiError, v2_reroute, v3};
use actix_web::{HttpRequest, HttpResponse, delete, get, patch, post, web};
use ariadne::ids::UserId;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;

View File

@@ -2,8 +2,8 @@ use std::sync::Arc;
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
use crate::models::ids::ThreadMessageId;
use crate::models::threads::{MessageBody, Thread, ThreadId};
use crate::models::ids::{ThreadId, ThreadMessageId};
use crate::models::threads::{MessageBody, Thread};
use crate::models::v2::threads::LegacyThread;
use crate::queue::session::AuthQueue;
use crate::routes::{ApiError, v2_reroute, v3};

View File

@@ -2,10 +2,9 @@ use crate::database::models::loader_fields::VersionField;
use crate::database::models::{project_item, version_item};
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
use crate::models::ids::ImageId;
use crate::models::ids::{ImageId, ProjectId, VersionId};
use crate::models::projects::{
Dependency, FileType, Loader, ProjectId, Version, VersionId, VersionStatus,
VersionType,
Dependency, FileType, Loader, Version, VersionStatus, VersionType,
};
use crate::models::v2::projects::LegacyVersion;
use crate::queue::moderation::AutomatedModerationQueue;

View File

@@ -599,7 +599,7 @@ async fn filter_allowed_ids(
let team_ids = projects_data
.iter()
.map(|x| x.inner.team_id)
.collect::<Vec<database::models::TeamId>>();
.collect::<Vec<database::models::DBTeamId>>();
let team_members =
database::models::TeamMember::get_from_team_full_many(
&team_ids, &***pool, redis,
@@ -609,7 +609,7 @@ async fn filter_allowed_ids(
let organization_ids = projects_data
.iter()
.filter_map(|x| x.inner.organization_id)
.collect::<Vec<database::models::OrganizationId>>();
.collect::<Vec<database::models::DBOrganizationId>>();
let organizations = database::models::Organization::get_many_ids(
&organization_ids,
&***pool,
@@ -620,7 +620,7 @@ async fn filter_allowed_ids(
let organization_team_ids = organizations
.iter()
.map(|x| x.team_id)
.collect::<Vec<database::models::TeamId>>();
.collect::<Vec<database::models::DBTeamId>>();
let organization_team_members =
database::models::TeamMember::get_from_team_full_many(
&organization_team_ids,

View File

@@ -144,7 +144,7 @@ pub async fn collections_get(
let ids = ids
.into_iter()
.map(|x| {
parse_base62(x).map(|x| database::models::CollectionId(x as i64))
parse_base62(x).map(|x| database::models::DBCollectionId(x as i64))
})
.collect::<Result<Vec<_>, _>>()?;
@@ -177,7 +177,7 @@ pub async fn collection_get(
) -> Result<HttpResponse, ApiError> {
let string = info.into_inner().0;
let id = database::models::CollectionId(parse_base62(&string)? as i64);
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
let collection_data =
database::models::Collection::get(id, &**pool, &redis).await?;
let user_option = get_user_from_headers(
@@ -241,7 +241,7 @@ pub async fn collection_edit(
})?;
let string = info.into_inner().0;
let id = database::models::CollectionId(parse_base62(&string)? as i64);
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
let result = database::models::Collection::get(id, &**pool, &redis).await?;
if let Some(collection_item) = result {
@@ -261,7 +261,7 @@ pub async fn collection_edit(
WHERE (id = $2)
",
name.trim(),
id as database::models::ids::CollectionId,
id as database::models::ids::DBCollectionId,
)
.execute(&mut *transaction)
.await?;
@@ -275,7 +275,7 @@ pub async fn collection_edit(
WHERE (id = $2)
",
description.as_ref(),
id as database::models::ids::CollectionId,
id as database::models::ids::DBCollectionId,
)
.execute(&mut *transaction)
.await?;
@@ -298,7 +298,7 @@ pub async fn collection_edit(
WHERE (id = $2)
",
status.to_string(),
id as database::models::ids::CollectionId,
id as database::models::ids::DBCollectionId,
)
.execute(&mut *transaction)
.await?;
@@ -311,7 +311,7 @@ pub async fn collection_edit(
DELETE FROM collections_mods
WHERE collection_id = $1
",
collection_item.id as database::models::ids::CollectionId,
collection_item.id as database::models::ids::DBCollectionId,
)
.execute(&mut *transaction)
.await?;
@@ -352,7 +352,7 @@ pub async fn collection_edit(
SET updated = NOW()
WHERE id = $1
",
collection_item.id as database::models::ids::CollectionId,
collection_item.id as database::models::ids::DBCollectionId,
)
.execute(&mut *transaction)
.await?;
@@ -395,7 +395,7 @@ pub async fn collection_icon_edit(
.1;
let string = info.into_inner().0;
let id = database::models::CollectionId(parse_base62(&string)? as i64);
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
let collection_item =
database::models::Collection::get(id, &**pool, &redis)
.await?
@@ -445,7 +445,7 @@ pub async fn collection_icon_edit(
upload_result.url,
upload_result.raw_url,
upload_result.color.map(|x| x as i32),
collection_item.id as database::models::ids::CollectionId,
collection_item.id as database::models::ids::DBCollectionId,
)
.execute(&mut *transaction)
.await?;
@@ -476,7 +476,7 @@ pub async fn delete_collection_icon(
.1;
let string = info.into_inner().0;
let id = database::models::CollectionId(parse_base62(&string)? as i64);
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
let collection_item =
database::models::Collection::get(id, &**pool, &redis)
.await?
@@ -503,7 +503,7 @@ pub async fn delete_collection_icon(
SET icon_url = NULL, raw_icon_url = NULL, color = NULL
WHERE (id = $1)
",
collection_item.id as database::models::ids::CollectionId,
collection_item.id as database::models::ids::DBCollectionId,
)
.execute(&mut *transaction)
.await?;
@@ -533,7 +533,7 @@ pub async fn collection_delete(
.1;
let string = info.into_inner().0;
let id = database::models::CollectionId(parse_base62(&string)? as i64);
let id = database::models::DBCollectionId(parse_base62(&string)? as i64);
let collection = database::models::Collection::get(id, &**pool, &redis)
.await?
.ok_or_else(|| {

View File

@@ -1,5 +1,5 @@
use crate::auth::get_user_from_headers;
use crate::database::models::UserId;
use crate::database::models::DBUserId;
use crate::database::redis::RedisPool;
use crate::models::pats::Scopes;
use crate::models::users::UserFriend;
@@ -77,8 +77,8 @@ pub async fn add_friend(
.await?;
async fn send_friend_status(
user_id: UserId,
friend_id: UserId,
user_id: DBUserId,
friend_id: DBUserId,
sockets: &ActiveSockets,
redis: &RedisPool,
) -> Result<(), ApiError> {

View File

@@ -9,9 +9,8 @@ use crate::database::models::{
};
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
use crate::models::ids::{ThreadMessageId, VersionId};
use crate::models::ids::{ReportId, ThreadMessageId, VersionId};
use crate::models::images::{Image, ImageContext};
use crate::models::reports::ReportId;
use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
use crate::util::img::upload_image_optimized;
@@ -205,13 +204,13 @@ pub async fn images_add(
raw_url: upload_result.raw_url,
size: content_length as u64,
created: chrono::Utc::now(),
owner_id: database::models::UserId::from(user.id),
owner_id: database::models::DBUserId::from(user.id),
context: context.context_as_str().to_string(),
project_id: if let ImageContext::Project {
project_id: Some(id),
} = context
{
Some(crate::database::models::ProjectId::from(id))
Some(crate::database::models::DBProjectId::from(id))
} else {
None
},
@@ -219,7 +218,7 @@ pub async fn images_add(
version_id: Some(id),
} = context
{
Some(database::models::VersionId::from(id))
Some(database::models::DBVersionId::from(id))
} else {
None
},
@@ -227,7 +226,7 @@ pub async fn images_add(
thread_message_id: Some(id),
} = context
{
Some(database::models::ThreadMessageId::from(id))
Some(database::models::DBThreadMessageId::from(id))
} else {
None
},
@@ -235,7 +234,7 @@ pub async fn images_add(
report_id: Some(id),
} = context
{
Some(database::models::ReportId::from(id))
Some(database::models::DBReportId::from(id))
} else {
None
},

View File

@@ -45,7 +45,7 @@ pub async fn notifications_get(
.await?
.1;
use database::models::NotificationId as DBNotificationId;
use database::models::DBNotificationId;
use database::models::notification_item::Notification as DBNotification;
let notification_ids: Vec<DBNotificationId> =
@@ -240,7 +240,7 @@ pub async fn notifications_read(
)
.await?;
let mut notifications: Vec<database::models::ids::NotificationId> =
let mut notifications: Vec<database::models::ids::DBNotificationId> =
Vec::new();
for notification in notifications_data {
@@ -293,7 +293,7 @@ pub async fn notifications_delete(
)
.await?;
let mut notifications: Vec<database::models::ids::NotificationId> =
let mut notifications: Vec<database::models::ids::DBNotificationId> =
Vec::new();
for notification in notifications_data {

View File

@@ -5,7 +5,7 @@ use crate::{
auth::{checks::ValidateAuthorized, get_user_from_headers},
database::{
models::{
DatabaseError, OAuthClientId, User, generate_oauth_client_id,
DBOAuthClientId, DatabaseError, User, generate_oauth_client_id,
generate_oauth_redirect_id,
oauth_client_authorization_item::OAuthClientAuthorization,
oauth_client_item::{OAuthClient, OAuthRedirectUri},
@@ -39,7 +39,7 @@ use sqlx::PgPool;
use validator::Validate;
use crate::database::models::oauth_client_item::OAuthClient as DBOAuthClient;
use crate::models::ids::OAuthClientId as ApiOAuthClientId;
use crate::models::ids::OAuthClientId;
use crate::util::img::{delete_old_images, upload_image_optimized};
pub fn config(cfg: &mut web::ServiceConfig) {
@@ -102,7 +102,7 @@ pub async fn get_user_clients(
#[get("app/{id}")]
pub async fn get_client(
id: web::Path<ApiOAuthClientId>,
id: web::Path<OAuthClientId>,
pool: web::Data<PgPool>,
) -> Result<HttpResponse, ApiError> {
let clients = get_clients_inner(&[id.into_inner()], pool).await?;
@@ -121,7 +121,7 @@ pub async fn get_clients(
let ids: Vec<_> = info
.ids
.iter()
.map(|id| parse_base62(id).map(ApiOAuthClientId))
.map(|id| parse_base62(id).map(OAuthClientId))
.collect::<Result<_, _>>()?;
let clients = get_clients_inner(&ids, pool).await?;
@@ -218,7 +218,7 @@ pub async fn oauth_client_create(
#[delete("app/{id}")]
pub async fn oauth_client_delete(
req: HttpRequest,
client_id: web::Path<ApiOAuthClientId>,
client_id: web::Path<OAuthClientId>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
@@ -274,7 +274,7 @@ pub struct OAuthClientEdit {
#[patch("app/{id}")]
pub async fn oauth_client_edit(
req: HttpRequest,
client_id: web::Path<ApiOAuthClientId>,
client_id: web::Path<OAuthClientId>,
client_updates: web::Json<OAuthClientEdit>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
@@ -351,7 +351,7 @@ pub struct Extension {
pub async fn oauth_client_icon_edit(
web::Query(ext): web::Query<Extension>,
req: HttpRequest,
client_id: web::Path<ApiOAuthClientId>,
client_id: web::Path<OAuthClientId>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
file_host: web::Data<Arc<dyn FileHost + Send + Sync>>,
@@ -419,7 +419,7 @@ pub async fn oauth_client_icon_edit(
#[delete("app/{id}/icon")]
pub async fn oauth_client_icon_delete(
req: HttpRequest,
client_id: web::Path<ApiOAuthClientId>,
client_id: web::Path<OAuthClientId>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
file_host: web::Data<Arc<dyn FileHost + Send + Sync>>,
@@ -532,7 +532,7 @@ fn generate_oauth_client_secret() -> String {
async fn create_redirect_uris(
uri_strings: impl IntoIterator<Item = impl Display>,
client_id: OAuthClientId,
client_id: DBOAuthClientId,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<Vec<OAuthRedirectUri>, DatabaseError> {
let mut redirect_uris = vec![];
@@ -581,10 +581,10 @@ async fn edit_redirects(
}
pub async fn get_clients_inner(
ids: &[ApiOAuthClientId],
ids: &[OAuthClientId],
pool: web::Data<PgPool>,
) -> Result<Vec<models::oauth_clients::OAuthClient>, ApiError> {
let ids: Vec<OAuthClientId> = ids.iter().map(|i| (*i).into()).collect();
let ids: Vec<DBOAuthClientId> = ids.iter().map(|i| (*i).into()).collect();
let clients = OAuthClient::get_many(&ids, &**pool).await?;
Ok(clients.into_iter().map(|c| c.into()).collect_vec())

View File

@@ -9,8 +9,7 @@ use crate::database::models::{
};
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
use crate::models::ids::UserId;
use crate::models::organizations::OrganizationId;
use crate::models::ids::OrganizationId;
use crate::models::pats::Scopes;
use crate::models::teams::{OrganizationPermissions, ProjectPermissions};
use crate::queue::session::AuthQueue;
@@ -20,6 +19,7 @@ use crate::util::routes::read_from_payload;
use crate::util::validate::validation_errors_to_string;
use crate::{database, models};
use actix_web::{HttpRequest, HttpResponse, web};
use ariadne::ids::UserId;
use ariadne::ids::base62_impl::parse_base62;
use futures::TryStreamExt;
use rust_decimal::Decimal;
@@ -77,10 +77,10 @@ pub async fn organization_projects_get(
INNER JOIN mods m ON m.organization_id = o.id
WHERE o.id = $1
",
organization.id as database::models::ids::OrganizationId
organization.id as database::models::ids::DBOrganizationId
)
.fetch(&**pool)
.map_ok(|m| database::models::ProjectId(m.id))
.map_ok(|m| database::models::DBProjectId(m.id))
.try_collect::<Vec<_>>()
.await?;
@@ -256,7 +256,7 @@ pub async fn organization_get(
logged_in
|| x.accepted
|| user_id
.map(|y: crate::database::models::UserId| {
.map(|y: crate::database::models::DBUserId| {
y == x.user_id
})
.unwrap_or(false)
@@ -344,7 +344,7 @@ pub async fn organizations_get(
logged_in
|| x.accepted
|| user_id
.map(|y: crate::database::models::UserId| {
.map(|y: crate::database::models::DBUserId| {
y == x.user_id
})
.unwrap_or(false)
@@ -437,7 +437,7 @@ pub async fn organizations_edit(
WHERE (id = $2)
",
description,
id as database::models::ids::OrganizationId,
id as database::models::ids::DBOrganizationId,
)
.execute(&mut *transaction)
.await?;
@@ -457,7 +457,7 @@ pub async fn organizations_edit(
WHERE (id = $2)
",
name,
id as database::models::ids::OrganizationId,
id as database::models::ids::DBOrganizationId,
)
.execute(&mut *transaction)
.await?;
@@ -519,7 +519,7 @@ pub async fn organizations_edit(
WHERE (id = $2)
",
Some(slug),
id as database::models::ids::OrganizationId,
id as database::models::ids::DBOrganizationId,
)
.execute(&mut *transaction)
.await?;
@@ -607,12 +607,12 @@ pub async fn organization_delete(
SELECT user_id FROM team_members
WHERE team_id = $1 AND is_owner = TRUE
",
organization.team_id as database::models::ids::TeamId
organization.team_id as database::models::ids::DBTeamId
)
.fetch_one(&**pool)
.await?
.user_id;
let owner_id = database::models::ids::UserId(owner_id);
let owner_id = database::models::ids::DBUserId(owner_id);
let mut transaction = pool.begin().await?;
@@ -626,10 +626,10 @@ pub async fn organization_delete(
INNER JOIN teams t ON t.id = m.team_id
WHERE o.id = $1 AND $1 IS NOT NULL
",
organization.id as database::models::ids::OrganizationId
organization.id as database::models::ids::DBOrganizationId
)
.fetch(&mut *transaction)
.map_ok(|c| database::models::TeamId(c.id))
.map_ok(|c| database::models::DBTeamId(c.id))
.try_collect::<Vec<_>>()
.await?;
@@ -777,8 +777,8 @@ pub async fn organization_projects_add(
SET organization_id = $1
WHERE (id = $2)
",
organization.id as database::models::OrganizationId,
project_item.inner.id as database::models::ids::ProjectId
organization.id as database::models::DBOrganizationId,
project_item.inner.id as database::models::ids::DBProjectId
)
.execute(&mut *transaction)
.await?;
@@ -794,20 +794,20 @@ pub async fn organization_projects_add(
INNER JOIN users u ON u.id = team_members.user_id
WHERE team_id = $1 AND is_owner = TRUE
",
organization.team_id as database::models::ids::TeamId
organization.team_id as database::models::ids::DBTeamId
)
.fetch_one(&mut *transaction)
.await?;
let organization_owner_user_id =
database::models::ids::UserId(organization_owner_user_id.id);
database::models::ids::DBUserId(organization_owner_user_id.id);
sqlx::query!(
"
DELETE FROM team_members
WHERE team_id = $1 AND (is_owner = TRUE OR user_id = $2)
",
project_item.inner.team_id as database::models::ids::TeamId,
organization_owner_user_id as database::models::ids::UserId,
project_item.inner.team_id as database::models::ids::DBTeamId,
organization_owner_user_id as database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -980,7 +980,7 @@ pub async fn organization_projects_remove(
role = 'Inherited Owner'
WHERE (id = $1)
",
new_owner.id as database::models::ids::TeamMemberId,
new_owner.id as database::models::ids::DBTeamMemberId,
ProjectPermissions::all().bits() as i64
)
.execute(&mut *transaction)
@@ -992,7 +992,7 @@ pub async fn organization_projects_remove(
SET organization_id = NULL
WHERE (id = $1)
",
project_item.inner.id as database::models::ids::ProjectId
project_item.inner.id as database::models::ids::DBProjectId
)
.execute(&mut *transaction)
.await?;
@@ -1119,7 +1119,7 @@ pub async fn organization_icon_edit(
upload_result.url,
upload_result.raw_url,
upload_result.color.map(|x| x as i32),
organization_item.id as database::models::ids::OrganizationId,
organization_item.id as database::models::ids::DBOrganizationId,
)
.execute(&mut *transaction)
.await?;
@@ -1201,7 +1201,7 @@ pub async fn delete_organization_icon(
SET icon_url = NULL, raw_icon_url = NULL, color = NULL
WHERE (id = $1)
",
organization_item.id as database::models::ids::OrganizationId,
organization_item.id as database::models::ids::DBOrganizationId,
)
.execute(&mut *transaction)
.await?;

View File

@@ -161,7 +161,10 @@ pub async fn paypal_webhook(
transaction.commit().await?;
crate::database::models::user_item::User::clear_caches(
&[(crate::database::models::UserId(result.user_id), None)],
&[(
crate::database::models::DBUserId(result.user_id),
None,
)],
&redis,
)
.await?;
@@ -268,7 +271,10 @@ pub async fn tremendous_webhook(
transaction.commit().await?;
crate::database::models::user_item::User::clear_caches(
&[(crate::database::models::UserId(result.user_id), None)],
&[(
crate::database::models::DBUserId(result.user_id),
None,
)],
&redis,
)
.await?;
@@ -788,7 +794,7 @@ pub async fn get_balance(
}
async fn get_user_balance(
user_id: crate::database::models::ids::UserId,
user_id: crate::database::models::ids::DBUserId,
pool: &PgPool,
) -> Result<UserBalance, sqlx::Error> {
let payouts = sqlx::query!(

View File

@@ -8,16 +8,14 @@ use crate::database::models::{self, User, image_item};
use crate::database::redis::RedisPool;
use crate::file_hosting::{FileHost, FileHostingError};
use crate::models::error::ApiError;
use crate::models::ids::{ImageId, OrganizationId};
use crate::models::ids::{ImageId, OrganizationId, ProjectId, VersionId};
use crate::models::images::{Image, ImageContext};
use crate::models::pats::Scopes;
use crate::models::projects::{
License, Link, MonetizationStatus, ProjectId, ProjectStatus, VersionId,
VersionStatus,
License, Link, MonetizationStatus, ProjectStatus, VersionStatus,
};
use crate::models::teams::{OrganizationPermissions, ProjectPermissions};
use crate::models::threads::ThreadType;
use crate::models::users::UserId;
use crate::queue::session::AuthQueue;
use crate::search::indexing::IndexingError;
use crate::util::img::upload_image_optimized;
@@ -27,6 +25,7 @@ use actix_multipart::{Field, Multipart};
use actix_web::http::StatusCode;
use actix_web::web::{self, Data};
use actix_web::{HttpRequest, HttpResponse};
use ariadne::ids::UserId;
use ariadne::ids::base62_impl::to_base62;
use chrono::Utc;
use futures::stream::StreamExt;
@@ -397,13 +396,13 @@ async fn project_create_inner(
serde_json::from_str(&format!("\"{}\"", create_data.slug)).ok();
if let Some(slug_project_id) = slug_project_id_option {
let slug_project_id: models::ids::ProjectId =
let slug_project_id: models::ids::DBProjectId =
slug_project_id.into();
let results = sqlx::query!(
"
SELECT EXISTS(SELECT 1 FROM mods WHERE id=$1)
",
slug_project_id as models::ids::ProjectId
slug_project_id as models::ids::DBProjectId
)
.fetch_one(&mut **transaction)
.await
@@ -817,7 +816,7 @@ async fn project_create_inner(
SET mod_id = $1
WHERE id = $2
",
id as models::ids::ProjectId,
id as models::ids::DBProjectId,
image_id.0 as i64
)
.execute(&mut **transaction)

View File

@@ -11,11 +11,12 @@ use crate::database::redis::RedisPool;
use crate::database::{self, models as db_models};
use crate::file_hosting::FileHost;
use crate::models;
use crate::models::ids::ProjectId;
use crate::models::images::ImageContext;
use crate::models::notifications::NotificationBody;
use crate::models::pats::Scopes;
use crate::models::projects::{
MonetizationStatus, Project, ProjectId, ProjectStatus, SearchRequest,
MonetizationStatus, Project, ProjectStatus, SearchRequest,
};
use crate::models::teams::ProjectPermissions;
use crate::models::threads::MessageBody;
@@ -103,7 +104,7 @@ pub async fn random_projects_get(
.collect::<Vec<String>>(),
)
.fetch(&**pool)
.map_ok(|m| db_ids::ProjectId(m.id))
.map_ok(|m| db_ids::DBProjectId(m.id))
.try_collect::<Vec<_>>()
.await?;
@@ -303,7 +304,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
name.trim(),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -324,7 +325,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
summary,
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -363,7 +364,7 @@ pub async fn project_edit(
SET moderation_message = NULL, moderation_message_body = NULL, queued = NOW()
WHERE (id = $1)
",
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -382,7 +383,7 @@ pub async fn project_edit(
SET approved = NOW()
WHERE id = $1 AND approved IS NULL
",
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -407,7 +408,7 @@ pub async fn project_edit(
SET webhook_sent = TRUE
WHERE id = $1
",
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -447,10 +448,10 @@ pub async fn project_edit(
FROM team_members tm
WHERE tm.team_id = $1 AND tm.accepted
",
project_item.inner.team_id as db_ids::TeamId
project_item.inner.team_id as db_ids::DBTeamId
)
.fetch(&mut *transaction)
.map_ok(|c| db_models::UserId(c.id))
.map_ok(|c| db_models::DBUserId(c.id))
.try_collect::<Vec<_>>()
.await?;
@@ -484,7 +485,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
status.as_str(),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -528,7 +529,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
requested_status.map(|x| x.as_str()),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -541,7 +542,7 @@ pub async fn project_edit(
DELETE FROM mods_categories
WHERE joining_mod_id = $1 AND is_additional = FALSE
",
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -553,7 +554,7 @@ pub async fn project_edit(
DELETE FROM mods_categories
WHERE joining_mod_id = $1 AND is_additional = TRUE
",
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -564,7 +565,7 @@ pub async fn project_edit(
edit_project_categories(
categories,
&perms,
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
false,
&mut transaction,
)
@@ -575,7 +576,7 @@ pub async fn project_edit(
edit_project_categories(
categories,
&perms,
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
true,
&mut transaction,
)
@@ -597,7 +598,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
license_url.as_deref(),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -663,7 +664,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
Some(slug),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -696,7 +697,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
license,
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -720,7 +721,7 @@ pub async fn project_edit(
SELECT id FROM link_platforms WHERE name = ANY($2)
)
",
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
&ids_to_delete
)
.execute(&mut *transaction)
@@ -747,7 +748,7 @@ pub async fn project_edit(
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
VALUES ($1, $2, $3)
",
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
platform_id as db_ids::LinkPlatformId,
url
)
@@ -775,7 +776,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
moderation_message.as_deref(),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -801,7 +802,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
moderation_message_body.as_deref(),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -822,7 +823,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
description,
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -856,7 +857,7 @@ pub async fn project_edit(
WHERE (id = $2)
",
monetization_status.as_str(),
id as db_ids::ProjectId,
id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -905,7 +906,7 @@ pub async fn project_edit(
pub async fn edit_project_categories(
categories: &Vec<String>,
perms: &ProjectPermissions,
project_id: db_ids::ProjectId,
project_id: db_ids::DBProjectId,
is_additional: bool,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
) -> Result<(), ApiError> {
@@ -1051,7 +1052,7 @@ pub async fn dependency_list(
.iter()
.filter_map(|x| x.0)
.unique()
.collect::<Vec<db_models::VersionId>>();
.collect::<Vec<db_models::DBVersionId>>();
let (projects_result, versions_result) = futures::future::try_join(
database::Project::get_many_ids(&project_ids, &**pool, &redis),
database::Version::get_many(&dep_version_ids, &**pool, &redis),
@@ -1133,7 +1134,7 @@ pub async fn projects_edit(
ApiError::Validation(validation_errors_to_string(err, None))
})?;
let project_ids: Vec<db_ids::ProjectId> =
let project_ids: Vec<db_ids::DBProjectId> =
serde_json::from_str::<Vec<ProjectId>>(&ids.ids)?
.into_iter()
.map(|x| x.into())
@@ -1155,7 +1156,7 @@ pub async fn projects_edit(
let team_ids = projects_data
.iter()
.map(|x| x.inner.team_id)
.collect::<Vec<db_models::TeamId>>();
.collect::<Vec<db_models::DBTeamId>>();
let team_members = db_models::TeamMember::get_from_team_full_many(
&team_ids, &**pool, &redis,
)
@@ -1164,7 +1165,7 @@ pub async fn projects_edit(
let organization_ids = projects_data
.iter()
.filter_map(|x| x.inner.organization_id)
.collect::<Vec<db_models::OrganizationId>>();
.collect::<Vec<db_models::DBOrganizationId>>();
let organizations = db_models::Organization::get_many_ids(
&organization_ids,
&**pool,
@@ -1175,7 +1176,7 @@ pub async fn projects_edit(
let organization_team_ids = organizations
.iter()
.map(|x| x.team_id)
.collect::<Vec<db_models::TeamId>>();
.collect::<Vec<db_models::DBTeamId>>();
let organization_team_members =
db_models::TeamMember::get_from_team_full_many(
&organization_team_ids,
@@ -1243,7 +1244,7 @@ pub async fn projects_edit(
bulk_edit_project_categories(
&categories,
&project.categories,
project.inner.id as db_ids::ProjectId,
project.inner.id as db_ids::DBProjectId,
CategoryChanges {
categories: &bulk_edit_project.categories,
add_categories: &bulk_edit_project.add_categories,
@@ -1258,7 +1259,7 @@ pub async fn projects_edit(
bulk_edit_project_categories(
&categories,
&project.additional_categories,
project.inner.id as db_ids::ProjectId,
project.inner.id as db_ids::DBProjectId,
CategoryChanges {
categories: &bulk_edit_project.additional_categories,
add_categories: &bulk_edit_project.add_additional_categories,
@@ -1281,7 +1282,7 @@ pub async fn projects_edit(
SELECT id FROM link_platforms WHERE name = ANY($2)
)
",
project.inner.id as db_ids::ProjectId,
project.inner.id as db_ids::DBProjectId,
&ids_to_delete
)
.execute(&mut *transaction)
@@ -1304,7 +1305,7 @@ pub async fn projects_edit(
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
VALUES ($1, $2, $3)
",
project.inner.id as db_ids::ProjectId,
project.inner.id as db_ids::DBProjectId,
platform_id as db_ids::LinkPlatformId,
url
)
@@ -1331,7 +1332,7 @@ pub async fn projects_edit(
pub async fn bulk_edit_project_categories(
all_db_categories: &[db_models::categories::Category],
project_categories: &Vec<String>,
project_id: db_ids::ProjectId,
project_id: db_ids::DBProjectId,
bulk_changes: CategoryChanges<'_>,
max_num_categories: usize,
is_additional: bool,
@@ -1369,7 +1370,7 @@ pub async fn bulk_edit_project_categories(
DELETE FROM mods_categories
WHERE joining_mod_id = $1 AND is_additional = $2
",
project_id as db_ids::ProjectId,
project_id as db_ids::DBProjectId,
is_additional
)
.execute(&mut **transaction)
@@ -1501,7 +1502,7 @@ pub async fn project_icon_edit(
upload_result.url,
upload_result.raw_url,
upload_result.color.map(|x| x as i32),
project_item.inner.id as db_ids::ProjectId,
project_item.inner.id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -1590,7 +1591,7 @@ pub async fn delete_project_icon(
SET icon_url = NULL, raw_icon_url = NULL, color = NULL
WHERE (id = $1)
",
project_item.inner.id as db_ids::ProjectId,
project_item.inner.id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -1727,7 +1728,7 @@ pub async fn add_gallery_item(
SET featured = $2
WHERE mod_id = $1
",
project_item.inner.id as db_ids::ProjectId,
project_item.inner.id as db_ids::DBProjectId,
false,
)
.execute(&mut *transaction)
@@ -1822,7 +1823,7 @@ pub async fn edit_gallery_item(
})?;
let project_item = db_models::Project::get_id(
database::models::ProjectId(result.mod_id),
database::models::DBProjectId(result.mod_id),
&**pool,
&redis,
)
@@ -1873,7 +1874,7 @@ pub async fn edit_gallery_item(
SET featured = $2
WHERE mod_id = $1
",
project_item.inner.id as db_ids::ProjectId,
project_item.inner.id as db_ids::DBProjectId,
false,
)
.execute(&mut *transaction)
@@ -1985,7 +1986,7 @@ pub async fn delete_gallery_item(
})?;
let project_item = db_models::Project::get_id(
database::models::ProjectId(item.mod_id),
database::models::DBProjectId(item.mod_id),
&**pool,
&redis,
)
@@ -2131,7 +2132,7 @@ pub async fn project_delete(
DELETE FROM collections_mods
WHERE mod_id = $1
",
project.inner.id as db_ids::ProjectId,
project.inner.id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -2185,8 +2186,8 @@ pub async fn project_follow(
)
})?;
let user_id: db_ids::UserId = user.id.into();
let project_id: db_ids::ProjectId = result.inner.id;
let user_id: db_ids::DBUserId = user.id.into();
let project_id: db_ids::DBProjectId = result.inner.id;
if !is_visible_project(&result.inner, &Some(user), &pool, false).await? {
return Err(ApiError::NotFound);
@@ -2196,8 +2197,8 @@ pub async fn project_follow(
"
SELECT EXISTS(SELECT 1 FROM mod_follows mf WHERE mf.follower_id = $1 AND mf.mod_id = $2)
",
user_id as db_ids::UserId,
project_id as db_ids::ProjectId
user_id as db_ids::DBUserId,
project_id as db_ids::DBProjectId
)
.fetch_one(&**pool)
.await?
@@ -2213,7 +2214,7 @@ pub async fn project_follow(
SET follows = follows + 1
WHERE id = $1
",
project_id as db_ids::ProjectId,
project_id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -2223,8 +2224,8 @@ pub async fn project_follow(
INSERT INTO mod_follows (follower_id, mod_id)
VALUES ($1, $2)
",
user_id as db_ids::UserId,
project_id as db_ids::ProjectId
user_id as db_ids::DBUserId,
project_id as db_ids::DBProjectId
)
.execute(&mut *transaction)
.await?;
@@ -2265,15 +2266,15 @@ pub async fn project_unfollow(
)
})?;
let user_id: db_ids::UserId = user.id.into();
let user_id: db_ids::DBUserId = user.id.into();
let project_id = result.inner.id;
let following = sqlx::query!(
"
SELECT EXISTS(SELECT 1 FROM mod_follows mf WHERE mf.follower_id = $1 AND mf.mod_id = $2)
",
user_id as db_ids::UserId,
project_id as db_ids::ProjectId
user_id as db_ids::DBUserId,
project_id as db_ids::DBProjectId
)
.fetch_one(&**pool)
.await?
@@ -2289,7 +2290,7 @@ pub async fn project_unfollow(
SET follows = follows - 1
WHERE id = $1
",
project_id as db_ids::ProjectId,
project_id as db_ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -2299,8 +2300,8 @@ pub async fn project_unfollow(
DELETE FROM mod_follows
WHERE follower_id = $1 AND mod_id = $2
",
user_id as db_ids::UserId,
project_id as db_ids::ProjectId
user_id as db_ids::DBUserId,
project_id as db_ids::DBProjectId
)
.execute(&mut *transaction)
.await?;
@@ -2384,7 +2385,7 @@ pub async fn project_get_organization(
logged_in
|| x.accepted
|| user_id
.map(|y: crate::database::models::UserId| {
.map(|y: crate::database::models::DBUserId| {
y == x.user_id
})
.unwrap_or(false)

View File

@@ -6,7 +6,7 @@ use crate::database::models::thread_item::{
};
use crate::database::redis::RedisPool;
use crate::models::ids::ImageId;
use crate::models::ids::{ProjectId, UserId, VersionId};
use crate::models::ids::{ProjectId, VersionId};
use crate::models::images::{Image, ImageContext};
use crate::models::pats::Scopes;
use crate::models::reports::{ItemType, Report};
@@ -15,6 +15,7 @@ use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
use crate::util::img;
use actix_web::{HttpRequest, HttpResponse, web};
use ariadne::ids::UserId;
use ariadne::ids::base62_impl::parse_base62;
use chrono::Utc;
use futures::StreamExt;
@@ -271,8 +272,8 @@ pub async fn reports(
count.count as i64
)
.fetch(&**pool)
.map_ok(|m| crate::database::models::ids::ReportId(m.id))
.try_collect::<Vec<crate::database::models::ids::ReportId>>()
.map_ok(|m| crate::database::models::ids::DBReportId(m.id))
.try_collect::<Vec<crate::database::models::ids::DBReportId>>()
.await?
} else {
sqlx::query!(
@@ -286,8 +287,8 @@ pub async fn reports(
count.count as i64
)
.fetch(&**pool)
.map_ok(|m| crate::database::models::ids::ReportId(m.id))
.try_collect::<Vec<crate::database::models::ids::ReportId>>()
.map_ok(|m| crate::database::models::ids::DBReportId(m.id))
.try_collect::<Vec<crate::database::models::ids::DBReportId>>()
.await?
};
@@ -318,7 +319,7 @@ pub async fn reports_get(
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {
let report_ids: Vec<crate::database::models::ids::ReportId> =
let report_ids: Vec<crate::database::models::ids::DBReportId> =
serde_json::from_str::<Vec<crate::models::ids::ReportId>>(&ids.ids)?
.into_iter()
.map(|x| x.into())
@@ -353,7 +354,7 @@ pub async fn report_get(
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
info: web::Path<(crate::models::reports::ReportId,)>,
info: web::Path<(crate::models::ids::ReportId,)>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {
let user = get_user_from_headers(
@@ -393,7 +394,7 @@ pub async fn report_edit(
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
info: web::Path<(crate::models::reports::ReportId,)>,
info: web::Path<(crate::models::ids::ReportId,)>,
session_queue: web::Data<AuthQueue>,
edit_report: web::Json<EditReport>,
) -> Result<HttpResponse, ApiError> {
@@ -426,7 +427,7 @@ pub async fn report_edit(
WHERE (id = $2)
",
edit_body,
id as crate::database::models::ids::ReportId,
id as crate::database::models::ids::DBReportId,
)
.execute(&mut *transaction)
.await?;
@@ -459,7 +460,7 @@ pub async fn report_edit(
WHERE (id = $2)
",
edit_closed,
id as crate::database::models::ids::ReportId,
id as crate::database::models::ids::DBReportId,
)
.execute(&mut *transaction)
.await?;
@@ -492,7 +493,7 @@ pub async fn report_edit(
pub async fn report_delete(
req: HttpRequest,
pool: web::Data<PgPool>,
info: web::Path<(crate::models::reports::ReportId,)>,
info: web::Path<(crate::models::ids::ReportId,)>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {

View File

@@ -5,15 +5,14 @@ use crate::database::models::notification_item::NotificationBuilder;
use crate::database::models::team_item::TeamAssociationId;
use crate::database::models::{Organization, Team, TeamMember, User};
use crate::database::redis::RedisPool;
use crate::models::ids::TeamId;
use crate::models::notifications::NotificationBody;
use crate::models::pats::Scopes;
use crate::models::teams::{
OrganizationPermissions, ProjectPermissions, TeamId,
};
use crate::models::users::UserId;
use crate::models::teams::{OrganizationPermissions, ProjectPermissions};
use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
use actix_web::{HttpRequest, HttpResponse, web};
use ariadne::ids::UserId;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
@@ -102,7 +101,7 @@ pub async fn team_members_get_project(
logged_in
|| x.accepted
|| user_id
.map(|y: crate::database::models::UserId| {
.map(|y: crate::database::models::DBUserId| {
y == x.user_id
})
.unwrap_or(false)
@@ -177,7 +176,7 @@ pub async fn team_members_get_organization(
logged_in
|| x.accepted
|| user_id
.map(|y: crate::database::models::UserId| {
.map(|y: crate::database::models::DBUserId| {
y == x.user_id
})
.unwrap_or(false)
@@ -243,7 +242,7 @@ pub async fn team_members_get(
logged_in
|| x.accepted
|| user_id
.map(|y: crate::database::models::UserId| y == x.user_id)
.map(|y: crate::database::models::DBUserId| y == x.user_id)
.unwrap_or(false)
})
.flat_map(|data| {
@@ -277,7 +276,7 @@ pub async fn teams_get(
let team_ids = serde_json::from_str::<Vec<TeamId>>(&ids.ids)?
.into_iter()
.map(|x| x.into())
.collect::<Vec<crate::database::models::ids::TeamId>>();
.collect::<Vec<crate::database::models::ids::DBTeamId>>();
let teams_data =
TeamMember::get_from_team_full_many(&team_ids, &**pool, &redis).await?;
@@ -997,10 +996,11 @@ pub async fn transfer_ownership(
.fetch_all(&mut *transaction)
.await?;
let team_ids: Vec<crate::database::models::ids::TeamId> = team_ids
.into_iter()
.map(|x| TeamId(x.team_id as u64).into())
.collect();
let team_ids: Vec<crate::database::models::ids::DBTeamId> =
team_ids
.into_iter()
.map(|x| TeamId(x.team_id as u64).into())
.collect();
// If the owner of the organization is a member of the project, remove them
for team_id in team_ids.iter() {

View File

@@ -7,12 +7,12 @@ use crate::database::models::notification_item::NotificationBuilder;
use crate::database::models::thread_item::ThreadMessageBuilder;
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
use crate::models::ids::ThreadMessageId;
use crate::models::ids::{ThreadId, ThreadMessageId};
use crate::models::images::{Image, ImageContext};
use crate::models::notifications::NotificationBody;
use crate::models::pats::Scopes;
use crate::models::projects::ProjectStatus;
use crate::models::threads::{MessageBody, Thread, ThreadId, ThreadType};
use crate::models::threads::{MessageBody, Thread, ThreadType};
use crate::models::users::User;
use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
@@ -42,14 +42,14 @@ pub async fn is_authorized_thread(
return Ok(true);
}
let user_id: database::models::UserId = user.id.into();
let user_id: database::models::DBUserId = user.id.into();
Ok(match thread.type_ {
ThreadType::Report => {
if let Some(report_id) = thread.report_id {
let report_exists = sqlx::query!(
"SELECT EXISTS(SELECT 1 FROM reports WHERE id = $1 AND reporter = $2)",
report_id as database::models::ids::ReportId,
user_id as database::models::ids::UserId,
report_id as database::models::ids::DBReportId,
user_id as database::models::ids::DBUserId,
)
.fetch_one(pool)
.await?
@@ -64,8 +64,8 @@ pub async fn is_authorized_thread(
if let Some(project_id) = thread.project_id {
let project_exists = sqlx::query!(
"SELECT EXISTS(SELECT 1 FROM mods m INNER JOIN team_members tm ON tm.team_id = m.team_id AND tm.user_id = $2 WHERE m.id = $1)",
project_id as database::models::ids::ProjectId,
user_id as database::models::ids::UserId,
project_id as database::models::ids::DBProjectId,
user_id as database::models::ids::DBUserId,
)
.fetch_one(pool)
.await?
@@ -74,8 +74,8 @@ pub async fn is_authorized_thread(
if !project_exists.unwrap_or(false) {
let org_exists = sqlx::query!(
"SELECT EXISTS(SELECT 1 FROM mods m INNER JOIN organizations o ON m.organization_id = o.id INNER JOIN team_members tm ON tm.team_id = o.team_id AND tm.user_id = $2 WHERE m.id = $1)",
project_id as database::models::ids::ProjectId,
user_id as database::models::ids::UserId,
project_id as database::models::ids::DBProjectId,
user_id as database::models::ids::DBUserId,
)
.fetch_one(pool)
.await?
@@ -99,7 +99,7 @@ pub async fn filter_authorized_threads(
pool: &web::Data<PgPool>,
redis: &RedisPool,
) -> Result<Vec<Thread>, ApiError> {
let user_id: database::models::UserId = user.id.into();
let user_id: database::models::DBUserId = user.id.into();
let mut return_threads = Vec::new();
let mut check_threads = Vec::new();
@@ -130,7 +130,7 @@ pub async fn filter_authorized_threads(
WHERE m.id = ANY($1)
",
&*project_thread_ids,
user_id as database::models::ids::UserId,
user_id as database::models::ids::DBUserId,
)
.fetch(&***pool)
.map_ok(|row| {
@@ -163,7 +163,7 @@ pub async fn filter_authorized_threads(
WHERE m.id = ANY($1)
",
&*project_thread_ids,
user_id as database::models::ids::UserId,
user_id as database::models::ids::DBUserId,
)
.fetch(&***pool)
.map_ok(|row| {
@@ -194,7 +194,7 @@ pub async fn filter_authorized_threads(
WHERE id = ANY($1) AND reporter = $2
",
&*report_thread_ids,
user_id as database::models::ids::UserId,
user_id as database::models::ids::DBUserId,
)
.fetch(&***pool)
.map_ok(|row| {
@@ -216,7 +216,7 @@ pub async fn filter_authorized_threads(
let mut user_ids = return_threads
.iter()
.flat_map(|x| x.members.clone())
.collect::<Vec<database::models::UserId>>();
.collect::<Vec<database::models::DBUserId>>();
user_ids.append(
&mut return_threads
.iter()
@@ -226,7 +226,7 @@ pub async fn filter_authorized_threads(
.filter_map(|x| x.author_id)
.collect::<Vec<_>>()
})
.collect::<Vec<database::models::UserId>>(),
.collect::<Vec<database::models::DBUserId>>(),
);
let users: Vec<User> =
@@ -345,7 +345,7 @@ pub async fn threads_get(
.await?
.1;
let thread_ids: Vec<database::models::ids::ThreadId> =
let thread_ids: Vec<database::models::ids::DBThreadId> =
serde_json::from_str::<Vec<ThreadId>>(&ids.ids)?
.into_iter()
.map(|x| x.into())
@@ -383,7 +383,7 @@ pub async fn thread_send_message(
.await?
.1;
let string: database::models::ThreadId = info.into_inner().0.into();
let string: database::models::DBThreadId = info.into_inner().0.into();
if let MessageBody::Text {
body,

View File

@@ -1,10 +1,5 @@
use std::{collections::HashMap, sync::Arc};
use actix_web::{HttpRequest, HttpResponse, web};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use validator::Validate;
use super::{ApiError, oauth_clients::get_user_clients};
use crate::util::img::delete_old_images;
use crate::{
@@ -13,7 +8,6 @@ use crate::{
file_hosting::FileHost,
models::{
collections::{Collection, CollectionStatus},
ids::UserId,
notifications::Notification,
pats::Scopes,
projects::Project,
@@ -22,6 +16,11 @@ use crate::{
queue::session::AuthQueue,
util::{routes::read_from_payload, validate::validation_errors_to_string},
};
use actix_web::{HttpRequest, HttpResponse, web};
use ariadne::ids::UserId;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use validator::Validate;
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.route("user", web::get().to(user_auth_get));
@@ -89,9 +88,12 @@ pub async fn admin_user_email(
)
})?;
let user =
User::get_id(crate::database::models::UserId(user_id), &**pool, &redis)
.await?;
let user = User::get_id(
crate::database::models::DBUserId(user_id),
&**pool,
&redis,
)
.await?;
if let Some(user) = user {
Ok(HttpResponse::Ok().json(user))
@@ -420,7 +422,7 @@ pub async fn user_edit(
WHERE (id = $2)
",
username,
id as crate::database::models::ids::UserId,
id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -439,7 +441,7 @@ pub async fn user_edit(
WHERE (id = $2)
",
bio.as_deref(),
id as crate::database::models::ids::UserId,
id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -462,7 +464,7 @@ pub async fn user_edit(
WHERE (id = $2)
",
role,
id as crate::database::models::ids::UserId,
id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -483,7 +485,7 @@ pub async fn user_edit(
WHERE (id = $2)
",
badges.bits() as i64,
id as crate::database::models::ids::UserId,
id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -504,7 +506,7 @@ pub async fn user_edit(
WHERE (id = $2)
",
venmo_handle,
id as crate::database::models::ids::UserId,
id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -518,7 +520,7 @@ pub async fn user_edit(
WHERE (id = $2)
",
allow_friend_requests,
id as crate::database::models::ids::UserId,
id as crate::database::models::ids::DBUserId,
)
.execute(&mut *transaction)
.await?;
@@ -606,7 +608,7 @@ pub async fn user_icon_edit(
",
upload_result.url,
upload_result.raw_url,
actual_user.id as crate::database::models::ids::UserId,
actual_user.id as crate::database::models::ids::DBUserId,
)
.execute(&**pool)
.await?;
@@ -658,7 +660,7 @@ pub async fn user_icon_delete(
SET avatar_url = NULL, raw_avatar_url = NULL
WHERE (id = $1)
",
actual_user.id as crate::database::models::ids::UserId,
actual_user.id as crate::database::models::ids::DBUserId,
)
.execute(&**pool)
.await?;

View File

@@ -10,13 +10,14 @@ use crate::database::models::version_item::{
use crate::database::models::{self, Organization, image_item};
use crate::database::redis::RedisPool;
use crate::file_hosting::FileHost;
use crate::models::images::{Image, ImageContext, ImageId};
use crate::models::ids::{ImageId, ProjectId, VersionId};
use crate::models::images::{Image, ImageContext};
use crate::models::notifications::NotificationBody;
use crate::models::pack::PackFileHash;
use crate::models::pats::Scopes;
use crate::models::projects::{
Dependency, FileType, Loader, ProjectId, Version, VersionFile, VersionId,
VersionStatus, VersionType,
Dependency, FileType, Loader, Version, VersionFile, VersionStatus,
VersionType,
};
use crate::models::projects::{DependencyType, ProjectStatus, skip_nulls};
use crate::models::teams::ProjectPermissions;
@@ -212,7 +213,7 @@ async fn version_create_inner(
));
}
let project_id: models::ProjectId = version_create_data.project_id.unwrap().into();
let project_id: models::DBProjectId = version_create_data.project_id.unwrap().into();
// Ensure that the project this version is being added to exists
if models::Project::get_id(project_id, &mut **transaction, redis)
@@ -402,11 +403,11 @@ async fn version_create_inner(
SELECT follower_id FROM mod_follows
WHERE mod_id = $1
",
builder.project_id as crate::database::models::ids::ProjectId
builder.project_id as crate::database::models::ids::DBProjectId
)
.fetch(&mut **transaction)
.map_ok(|m| models::ids::UserId(m.follower_id))
.try_collect::<Vec<models::ids::UserId>>()
.map_ok(|m| models::ids::DBUserId(m.follower_id))
.try_collect::<Vec<models::ids::DBUserId>>()
.await?;
let project_id: ProjectId = builder.project_id.into();
@@ -516,7 +517,7 @@ async fn version_create_inner(
let project_status = sqlx::query!(
"SELECT status FROM mods WHERE id = $1",
project_id as models::ProjectId,
project_id as models::DBProjectId,
)
.fetch_optional(pool)
.await?;
@@ -542,7 +543,7 @@ pub async fn upload_file_to_version(
let mut transaction = client.begin().await?;
let mut uploaded_files = Vec::new();
let version_id = models::VersionId::from(url_data.into_inner().0);
let version_id = models::DBVersionId::from(url_data.into_inner().0);
let result = upload_file_to_version_inner(
req,
@@ -585,7 +586,7 @@ async fn upload_file_to_version_inner(
redis: Data<RedisPool>,
file_host: &dyn FileHost,
uploaded_files: &mut Vec<UploadedFile>,
version_id: models::VersionId,
version_id: models::DBVersionId,
session_queue: &AuthQueue,
) -> Result<HttpResponse, CreateError> {
let cdn_url = dotenvy::var("CDN_URL")?;
@@ -903,8 +904,8 @@ pub async fn upload_file(
.map(|x| x.as_bytes())
}) {
dependencies.push(DependencyBuilder {
project_id: Some(models::ProjectId(dep.project_id)),
version_id: Some(models::VersionId(dep.version_id)),
project_id: Some(models::DBProjectId(dep.project_id)),
version_id: Some(models::DBVersionId(dep.version_id)),
file_name: None,
dependency_type: DependencyType::Embedded.to_string(),
});

View File

@@ -370,10 +370,10 @@ pub async fn update_files(
&update_data.version_types.clone().unwrap_or_default().iter().map(|x| x.to_string()).collect::<Vec<_>>(),
)
.fetch(&**pool)
.try_fold(DashMap::new(), |acc : DashMap<_,Vec<database::models::ids::VersionId>>, m| {
acc.entry(database::models::ProjectId(m.mod_id))
.try_fold(DashMap::new(), |acc : DashMap<_,Vec<database::models::ids::DBVersionId>>, m| {
acc.entry(database::models::DBProjectId(m.mod_id))
.or_default()
.push(database::models::VersionId(m.version_id));
.push(database::models::DBVersionId(m.version_id));
async move { Ok(acc) }
})
.await?;

View File

@@ -132,7 +132,7 @@ pub async fn versions_get(
serde_json::from_str::<Vec<models::ids::VersionId>>(&ids.ids)?
.into_iter()
.map(|x| x.into())
.collect::<Vec<database::models::VersionId>>();
.collect::<Vec<database::models::DBVersionId>>();
let versions_data =
database::models::Version::get_many(&version_ids, &**pool, &redis)
.await?;
@@ -345,7 +345,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
name.trim(),
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -359,7 +359,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
number,
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -373,7 +373,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
version_type.as_str(),
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -384,7 +384,7 @@ pub async fn version_edit_helper(
"
DELETE FROM dependencies WHERE dependent_id = $1
",
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -448,7 +448,7 @@ pub async fn version_edit_helper(
WHERE version_id = $1
AND field_id = ANY($2)
",
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
&loader_field_ids
)
.execute(&mut *transaction)
@@ -493,7 +493,7 @@ pub async fn version_edit_helper(
"
DELETE FROM loaders_versions WHERE version_id = $1
",
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -538,7 +538,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
featured,
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -552,7 +552,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
body,
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -572,7 +572,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
*downloads as i32,
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -587,7 +587,7 @@ pub async fn version_edit_helper(
",
diff as i32,
version_item.inner.project_id
as database::models::ids::ProjectId,
as database::models::ids::DBProjectId,
)
.execute(&mut *transaction)
.await?;
@@ -607,7 +607,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
status.as_str(),
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;
@@ -655,7 +655,7 @@ pub async fn version_edit_helper(
WHERE (id = $2)
",
ordering.to_owned() as Option<i32>,
version_id as database::models::ids::VersionId,
version_id as database::models::ids::DBVersionId,
)
.execute(&mut *transaction)
.await?;