You've already forked AstralRinth
forked from didirus/AstralRinth
Make gallery item featuring exclusive (#241)
* Make gallery featured value exclusive * Run prepare
This commit is contained in:
@@ -2168,6 +2168,19 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"61a7f29e024bf2f1368370e3f6e8ef70317c7e8545b5b6d4235f21164948ba27": {
|
||||
"query": "\n UPDATE mods_gallery\n SET featured = $2\n WHERE mod_id = $1\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
},
|
||||
"67d021f0776276081d3c50ca97afa6b78b98860bf929009e845e9c00a192e3b5": {
|
||||
"query": "\n SELECT id FROM report_types\n WHERE name = $1\n ",
|
||||
"describe": {
|
||||
|
||||
@@ -442,6 +442,12 @@ pub async fn project_create_inner(
|
||||
}
|
||||
|
||||
if let Some(gallery_items) = &project_create_data.gallery_items {
|
||||
if gallery_items.iter().filter(|a| a.featured).count() > 1 {
|
||||
return Err(CreateError::InvalidInput(String::from(
|
||||
"Only one gallery image can be featured.",
|
||||
)));
|
||||
}
|
||||
|
||||
if let Some(item) = gallery_items.iter().find(|x| x.item == name) {
|
||||
let mut data = Vec::new();
|
||||
while let Some(chunk) = field.next().await {
|
||||
|
||||
@@ -1153,6 +1153,20 @@ pub async fn add_gallery_item(
|
||||
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
if item.featured {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods_gallery
|
||||
SET featured = $2
|
||||
WHERE mod_id = $1
|
||||
",
|
||||
project_item.id as database::models::ids::ProjectId,
|
||||
false,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
database::models::project_item::GalleryItem {
|
||||
project_id: project_item.id,
|
||||
image_url: format!("{}/{}", cdn_url, url),
|
||||
@@ -1256,6 +1270,20 @@ pub async fn edit_gallery_item(
|
||||
let mut transaction = pool.begin().await?;
|
||||
|
||||
if let Some(featured) = item.featured {
|
||||
if featured {
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods_gallery
|
||||
SET featured = $2
|
||||
WHERE mod_id = $1
|
||||
",
|
||||
project_item.id as database::models::ids::ProjectId,
|
||||
false,
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
}
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE mods_gallery
|
||||
|
||||
Reference in New Issue
Block a user