Add ordering to categories, gallery images, and team members (#501)

This commit is contained in:
triphora
2022-12-23 14:34:04 -05:00
committed by GitHub
parent 9fed1cde25
commit 16d5a70c08
11 changed files with 1217 additions and 1041 deletions

View File

@@ -44,6 +44,7 @@ pub struct GalleryItem {
pub title: Option<String>,
pub description: Option<String>,
pub created: DateTime<Utc>,
pub ordering: i64,
}
impl GalleryItem {
@@ -55,17 +56,18 @@ impl GalleryItem {
sqlx::query!(
"
INSERT INTO mods_gallery (
mod_id, image_url, featured, title, description
mod_id, image_url, featured, title, description, ordering
)
VALUES (
$1, $2, $3, $4, $5
$1, $2, $3, $4, $5, $6
)
",
project_id as ProjectId,
self.image_url,
self.featured,
self.title,
self.description
self.description,
self.ordering
)
.execute(&mut *transaction)
.await?;
@@ -668,7 +670,7 @@ impl Project {
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
JSONB_AGG(DISTINCT jsonb_build_object('id', v.id, 'date_published', v.date_published)) filter (where v.id is not null) versions,
JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created)) filter (where mg.image_url is not null) gallery,
JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created, 'ordering', mg.ordering)) filter (where mg.image_url is not null) gallery,
JSONB_AGG(DISTINCT jsonb_build_object('platform_id', md.joining_platform_id, 'platform_short', dp.short, 'platform_name', dp.name,'url', md.url)) filter (where md.joining_platform_id is not null) donations
FROM mods m
INNER JOIN project_types pt ON pt.id = m.project_type
@@ -747,11 +749,16 @@ impl Project {
versions.into_iter().map(|x| x.id).collect()
},
gallery_items: serde_json::from_value(
m.gallery.unwrap_or_default(),
)
.ok()
.unwrap_or_default(),
gallery_items: {
let mut gallery: Vec<GalleryItem> =
serde_json::from_value(m.gallery.unwrap_or_default())
.ok()
.unwrap_or_default();
gallery.sort_by(|a, b| a.ordering.cmp(&b.ordering));
gallery
},
donation_urls: serde_json::from_value(
m.donations.unwrap_or_default(),
)
@@ -791,7 +798,7 @@ impl Project {
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is false) categories,
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_categories,
JSONB_AGG(DISTINCT jsonb_build_object('id', v.id, 'date_published', v.date_published)) filter (where v.id is not null) versions,
JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created)) filter (where mg.image_url is not null) gallery,
JSONB_AGG(DISTINCT jsonb_build_object('image_url', mg.image_url, 'featured', mg.featured, 'title', mg.title, 'description', mg.description, 'created', mg.created, 'ordering', mg.ordering)) filter (where mg.image_url is not null) gallery,
JSONB_AGG(DISTINCT jsonb_build_object('platform_id', md.joining_platform_id, 'platform_short', dp.short, 'platform_name', dp.name,'url', md.url)) filter (where md.joining_platform_id is not null) donations
FROM mods m
INNER JOIN project_types pt ON pt.id = m.project_type
@@ -870,9 +877,15 @@ impl Project {
versions.into_iter().map(|x| x.id).collect()
},
gallery_items: serde_json::from_value(
m.gallery.unwrap_or_default(),
).ok().unwrap_or_default(),
gallery_items: {
let mut gallery: Vec<GalleryItem> = serde_json::from_value(
m.gallery.unwrap_or_default(),
).ok().unwrap_or_default();
gallery.sort_by(|a, b| a.ordering.cmp(&b.ordering));
gallery
},
donation_urls: serde_json::from_value(
m.donations.unwrap_or_default(),
).ok().unwrap_or_default(),