You've already forked AstralRinth
forked from didirus/AstralRinth
Links (#763)
This commit is contained in:
@@ -10,7 +10,7 @@ use crate::models::ids::{ImageId, OrganizationId};
|
||||
use crate::models::images::{Image, ImageContext};
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::projects::{
|
||||
DonationLink, License, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus,
|
||||
License, Link, MonetizationStatus, ProjectId, ProjectStatus, VersionId, VersionStatus,
|
||||
};
|
||||
use crate::models::teams::ProjectPermissions;
|
||||
use crate::models::threads::ThreadType;
|
||||
@@ -187,39 +187,12 @@ pub struct ProjectCreateData {
|
||||
/// A list of the categories that the project is in.
|
||||
pub additional_categories: Vec<String>,
|
||||
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
/// An optional link to where to submit bugs or issues with the project.
|
||||
pub issues_url: Option<String>,
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
/// An optional link to the source code for the project.
|
||||
pub source_url: Option<String>,
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
/// An optional link to the project's wiki page or other relevant information.
|
||||
pub wiki_url: Option<String>,
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
/// An optional link to the project's license page
|
||||
pub license_url: Option<String>,
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
/// An optional link to the project's discord.
|
||||
pub discord_url: Option<String>,
|
||||
/// An optional list of all donation links the project has\
|
||||
#[validate]
|
||||
pub donation_urls: Option<Vec<DonationLink>>,
|
||||
/// An optional list of all donation links the project has
|
||||
#[validate(custom(function = "crate::util::validate::validate_url_hashmap_values"))]
|
||||
#[serde(default)]
|
||||
pub link_urls: HashMap<String, String>,
|
||||
|
||||
/// An optional boolean. If true, the project will be created as a draft.
|
||||
pub is_draft: Option<bool>,
|
||||
@@ -671,27 +644,35 @@ async fn project_create_inner(
|
||||
CreateError::InvalidInput(format!("Invalid SPDX license identifier: {err}"))
|
||||
})?;
|
||||
|
||||
let mut donation_urls = vec![];
|
||||
let mut link_urls = vec![];
|
||||
|
||||
if let Some(urls) = &project_create_data.donation_urls {
|
||||
for url in urls {
|
||||
let platform_id =
|
||||
models::categories::DonationPlatform::get_id(&url.id, &mut **transaction)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
CreateError::InvalidInput(format!(
|
||||
"Donation platform {} does not exist.",
|
||||
url.id.clone()
|
||||
))
|
||||
})?;
|
||||
|
||||
donation_urls.push(models::project_item::DonationUrl {
|
||||
platform_id,
|
||||
platform_short: "".to_string(),
|
||||
platform_name: "".to_string(),
|
||||
url: url.url.clone(),
|
||||
})
|
||||
}
|
||||
let link_platforms =
|
||||
models::categories::LinkPlatform::list(&mut **transaction, redis).await?;
|
||||
for (platform, url) in &project_create_data.link_urls {
|
||||
let platform_id =
|
||||
models::categories::LinkPlatform::get_id(platform, &mut **transaction)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
CreateError::InvalidInput(format!(
|
||||
"Link platform {} does not exist.",
|
||||
platform.clone()
|
||||
))
|
||||
})?;
|
||||
let link_platform = link_platforms
|
||||
.iter()
|
||||
.find(|x| x.id == platform_id)
|
||||
.ok_or_else(|| {
|
||||
CreateError::InvalidInput(format!(
|
||||
"Link platform {} does not exist.",
|
||||
platform.clone()
|
||||
))
|
||||
})?;
|
||||
link_urls.push(models::project_item::LinkUrl {
|
||||
platform_id,
|
||||
platform_name: link_platform.name.clone(),
|
||||
url: url.clone(),
|
||||
donation: link_platform.donation,
|
||||
})
|
||||
}
|
||||
|
||||
let project_builder_actual = models::project_item::ProjectBuilder {
|
||||
@@ -702,12 +683,8 @@ async fn project_create_inner(
|
||||
description: project_create_data.description,
|
||||
body: project_create_data.body,
|
||||
icon_url: icon_data.clone().map(|x| x.0),
|
||||
issues_url: project_create_data.issues_url,
|
||||
source_url: project_create_data.source_url,
|
||||
wiki_url: project_create_data.wiki_url,
|
||||
|
||||
license_url: project_create_data.license_url,
|
||||
discord_url: project_create_data.discord_url,
|
||||
categories,
|
||||
additional_categories,
|
||||
initial_versions: versions,
|
||||
@@ -715,7 +692,7 @@ async fn project_create_inner(
|
||||
requested_status: Some(project_create_data.requested_status),
|
||||
license: license_id.to_string(),
|
||||
slug: Some(project_create_data.slug),
|
||||
donation_urls,
|
||||
link_urls,
|
||||
gallery_items: gallery_urls
|
||||
.iter()
|
||||
.map(|x| models::project_item::GalleryItem {
|
||||
@@ -835,11 +812,12 @@ async fn project_create_inner(
|
||||
.map(|v| v.version_id.into())
|
||||
.collect::<Vec<_>>(),
|
||||
icon_url: project_builder.icon_url.clone(),
|
||||
issues_url: project_builder.issues_url.clone(),
|
||||
source_url: project_builder.source_url.clone(),
|
||||
wiki_url: project_builder.wiki_url.clone(),
|
||||
discord_url: project_builder.discord_url.clone(),
|
||||
donation_urls: project_create_data.donation_urls.clone(),
|
||||
link_urls: project_builder
|
||||
.link_urls
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|x| (x.platform_name.clone(), Link::from(x)))
|
||||
.collect(),
|
||||
gallery: gallery_urls,
|
||||
color: project_builder.color,
|
||||
thread_id: thread_id.into(),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::auth::{filter_authorized_projects, get_user_from_headers, is_authorized};
|
||||
@@ -14,7 +15,7 @@ use crate::models::images::ImageContext;
|
||||
use crate::models::notifications::NotificationBody;
|
||||
use crate::models::pats::Scopes;
|
||||
use crate::models::projects::{
|
||||
DonationLink, MonetizationStatus, Project, ProjectId, ProjectStatus, SearchRequest,
|
||||
MonetizationStatus, Project, ProjectId, ProjectStatus, SearchRequest,
|
||||
};
|
||||
use crate::models::teams::ProjectPermissions;
|
||||
use crate::models::threads::MessageBody;
|
||||
@@ -192,49 +193,10 @@ pub struct EditProject {
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub issues_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub source_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub wiki_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub license_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub discord_url: Option<Option<String>>,
|
||||
#[validate]
|
||||
pub donation_urls: Option<Vec<DonationLink>>,
|
||||
#[validate(custom(function = "crate::util::validate::validate_url_hashmap_optional_values"))]
|
||||
// <name, url> (leave url empty to delete)
|
||||
pub link_urls: Option<HashMap<String, Option<String>>>,
|
||||
pub license_id: Option<String>,
|
||||
#[validate(
|
||||
length(min = 3, max = 64),
|
||||
@@ -592,69 +554,6 @@ pub async fn project_edit(
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(issues_url) = &new_project.issues_url {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have the permissions to edit the issues URL of this project!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET issues_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
issues_url.as_deref(),
|
||||
id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(source_url) = &new_project.source_url {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have the permissions to edit the source URL of this project!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET source_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
source_url.as_deref(),
|
||||
id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(wiki_url) = &new_project.wiki_url {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have the permissions to edit the wiki URL of this project!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET wiki_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
wiki_url.as_deref(),
|
||||
id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(license_url) = &new_project.license_url {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
@@ -676,27 +575,6 @@ pub async fn project_edit(
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(discord_url) = &new_project.discord_url {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have the permissions to edit the discord URL of this project!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET discord_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
discord_url.as_deref(),
|
||||
id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(slug) = &new_project.slug {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
@@ -785,51 +663,59 @@ pub async fn project_edit(
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
if let Some(donations) = &new_project.donation_urls {
|
||||
if let Some(links) = &new_project.link_urls {
|
||||
if !perms.contains(ProjectPermissions::EDIT_DETAILS) {
|
||||
return Err(ApiError::CustomAuthentication(
|
||||
"You do not have the permissions to edit the donation links of this project!"
|
||||
"You do not have the permissions to edit the links of this project!"
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let ids_to_delete = links
|
||||
.iter()
|
||||
.map(|(name, _)| name.clone())
|
||||
.collect::<Vec<String>>();
|
||||
// Deletes all links from hashmap- either will be deleted or be replaced
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM mods_donations
|
||||
WHERE joining_mod_id = $1
|
||||
DELETE FROM mods_links
|
||||
WHERE joining_mod_id = $1 AND joining_platform_id IN (
|
||||
SELECT id FROM link_platforms WHERE name = ANY($2)
|
||||
)
|
||||
",
|
||||
id as db_ids::ProjectId,
|
||||
&ids_to_delete
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
for donation in donations {
|
||||
let platform_id = db_models::categories::DonationPlatform::get_id(
|
||||
&donation.id,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(format!(
|
||||
"Platform {} does not exist.",
|
||||
donation.id.clone()
|
||||
))
|
||||
})?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)
|
||||
VALUES ($1, $2, $3)
|
||||
",
|
||||
id as db_ids::ProjectId,
|
||||
platform_id as db_ids::DonationPlatformId,
|
||||
donation.url
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
for (platform, url) in links {
|
||||
if let Some(url) = url {
|
||||
let platform_id = db_models::categories::LinkPlatform::get_id(
|
||||
platform,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(format!(
|
||||
"Platform {} does not exist.",
|
||||
platform.clone()
|
||||
))
|
||||
})?;
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||
VALUES ($1, $2, $3)
|
||||
",
|
||||
id as db_ids::ProjectId,
|
||||
platform_id as db_ids::LinkPlatformId,
|
||||
url
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(moderation_message) = &new_project.moderation_message {
|
||||
if !user.role.is_mod()
|
||||
&& (!project_item.inner.status.is_approved() || moderation_message.is_some())
|
||||
@@ -1139,53 +1025,8 @@ pub struct BulkEditProject {
|
||||
pub add_additional_categories: Option<Vec<String>>,
|
||||
pub remove_additional_categories: Option<Vec<String>>,
|
||||
|
||||
#[validate]
|
||||
pub donation_urls: Option<Vec<DonationLink>>,
|
||||
#[validate]
|
||||
pub add_donation_urls: Option<Vec<DonationLink>>,
|
||||
#[validate]
|
||||
pub remove_donation_urls: Option<Vec<DonationLink>>,
|
||||
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub issues_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub source_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub wiki_url: Option<Option<String>>,
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
with = "::serde_with::rust::double_option"
|
||||
)]
|
||||
#[validate(
|
||||
custom(function = "crate::util::validate::validate_url"),
|
||||
length(max = 2048)
|
||||
)]
|
||||
pub discord_url: Option<Option<String>>,
|
||||
#[validate(custom(function = " crate::util::validate::validate_url_hashmap_optional_values"))]
|
||||
pub link_urls: Option<HashMap<String, Option<String>>>,
|
||||
}
|
||||
|
||||
pub async fn projects_edit(
|
||||
@@ -1250,7 +1091,7 @@ pub async fn projects_edit(
|
||||
.await?;
|
||||
|
||||
let categories = db_models::categories::Category::list(&**pool, &redis).await?;
|
||||
let donation_platforms = db_models::categories::DonationPlatform::list(&**pool, &redis).await?;
|
||||
let link_platforms = db_models::categories::LinkPlatform::list(&**pool, &redis).await?;
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
@@ -1330,130 +1171,52 @@ pub async fn projects_edit(
|
||||
)
|
||||
.await?;
|
||||
|
||||
let project_donations: Vec<DonationLink> = project
|
||||
.donation_urls
|
||||
.into_iter()
|
||||
.map(|d| DonationLink {
|
||||
id: d.platform_short,
|
||||
platform: d.platform_name,
|
||||
url: d.url,
|
||||
})
|
||||
.collect();
|
||||
let mut set_donation_links =
|
||||
if let Some(donation_links) = bulk_edit_project.donation_urls.clone() {
|
||||
donation_links
|
||||
} else {
|
||||
project_donations.clone()
|
||||
};
|
||||
if let Some(links) = &bulk_edit_project.link_urls {
|
||||
let ids_to_delete = links
|
||||
.iter()
|
||||
.map(|(name, _)| name.clone())
|
||||
.collect::<Vec<String>>();
|
||||
// Deletes all links from hashmap- either will be deleted or be replaced
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM mods_links
|
||||
WHERE joining_mod_id = $1 AND joining_platform_id IN (
|
||||
SELECT id FROM link_platforms WHERE name = ANY($2)
|
||||
)
|
||||
",
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
&ids_to_delete
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
if let Some(delete_donations) = &bulk_edit_project.remove_donation_urls {
|
||||
for donation in delete_donations {
|
||||
if let Some(pos) = set_donation_links
|
||||
.iter()
|
||||
.position(|x| donation.url == x.url && donation.id == x.id)
|
||||
{
|
||||
set_donation_links.remove(pos);
|
||||
for (platform, url) in links {
|
||||
if let Some(url) = url {
|
||||
let platform_id = link_platforms
|
||||
.iter()
|
||||
.find(|x| &x.name == platform)
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(format!(
|
||||
"Platform {} does not exist.",
|
||||
platform.clone()
|
||||
))
|
||||
})?
|
||||
.id;
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO mods_links (joining_mod_id, joining_platform_id, url)
|
||||
VALUES ($1, $2, $3)
|
||||
",
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
platform_id as db_ids::LinkPlatformId,
|
||||
url
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(add_donations) = &bulk_edit_project.add_donation_urls {
|
||||
set_donation_links.append(&mut add_donations.clone());
|
||||
}
|
||||
|
||||
if set_donation_links != project_donations {
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM mods_donations
|
||||
WHERE joining_mod_id = $1
|
||||
",
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
for donation in set_donation_links {
|
||||
let platform_id = donation_platforms
|
||||
.iter()
|
||||
.find(|x| x.short == donation.id)
|
||||
.ok_or_else(|| {
|
||||
ApiError::InvalidInput(format!(
|
||||
"Platform {} does not exist.",
|
||||
donation.id.clone()
|
||||
))
|
||||
})?
|
||||
.id;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO mods_donations (joining_mod_id, joining_platform_id, url)
|
||||
VALUES ($1, $2, $3)
|
||||
",
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
platform_id as db_ids::DonationPlatformId,
|
||||
donation.url
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(issues_url) = &bulk_edit_project.issues_url {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET issues_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
issues_url.as_deref(),
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(source_url) = &bulk_edit_project.source_url {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET source_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
source_url.as_deref(),
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(wiki_url) = &bulk_edit_project.wiki_url {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET wiki_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
wiki_url.as_deref(),
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if let Some(discord_url) = &bulk_edit_project.discord_url {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods
|
||||
SET discord_url = $1
|
||||
WHERE (id = $2)
|
||||
",
|
||||
discord_url.as_deref(),
|
||||
project.inner.id as db_ids::ProjectId,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
db_models::Project::clear_cache(project.inner.id, project.inner.slug, None, &redis).await?;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::ApiError;
|
||||
use crate::database::models::categories::{Category, DonationPlatform, ProjectType, ReportType};
|
||||
use crate::database::models::categories::{Category, LinkPlatform, ProjectType, ReportType};
|
||||
use crate::database::models::loader_fields::{
|
||||
Game, Loader, LoaderField, LoaderFieldEnumValue, LoaderFieldType,
|
||||
};
|
||||
@@ -22,7 +22,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
.route("loader_field", web::get().to(loader_fields_list))
|
||||
.route("license", web::get().to(license_list))
|
||||
.route("license/{id}", web::get().to(license_text))
|
||||
.route("donation_platform", web::get().to(donation_platform_list))
|
||||
.route("link_platform", web::get().to(link_platform_list))
|
||||
.route("report_type", web::get().to(report_type_list))
|
||||
.route("project_type", web::get().to(project_type_list));
|
||||
}
|
||||
@@ -214,23 +214,19 @@ pub async fn license_text(params: web::Path<(String,)>) -> Result<HttpResponse,
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct DonationPlatformQueryData {
|
||||
short: String,
|
||||
name: String,
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct LinkPlatformQueryData {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub async fn donation_platform_list(
|
||||
pub async fn link_platform_list(
|
||||
pool: web::Data<PgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let results: Vec<DonationPlatformQueryData> = DonationPlatform::list(&**pool, &redis)
|
||||
let results: Vec<LinkPlatformQueryData> = LinkPlatform::list(&**pool, &redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|x| DonationPlatformQueryData {
|
||||
short: x.short,
|
||||
name: x.name,
|
||||
})
|
||||
.map(|x| LinkPlatformQueryData { name: x.name })
|
||||
.collect();
|
||||
Ok(HttpResponse::Ok().json(results))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user