You've already forked AstralRinth
forked from didirus/AstralRinth
Add ordering to categories, gallery images, and team members (#501)
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE categories ADD COLUMN ordering BIGINT NOT NULL DEFAULT 0;
|
||||||
|
ALTER TABLE mods_gallery ADD COLUMN ordering BIGINT NOT NULL DEFAULT 0;
|
||||||
|
ALTER TABLE team_members ADD COLUMN ordering BIGINT NOT NULL DEFAULT 0;
|
||||||
+1097
-1008
File diff suppressed because it is too large
Load Diff
@@ -134,7 +134,7 @@ impl Category {
|
|||||||
SELECT c.id id, c.category category, c.icon icon, c.header category_header, pt.name project_type
|
SELECT c.id id, c.category category, c.icon icon, c.header category_header, pt.name project_type
|
||||||
FROM categories c
|
FROM categories c
|
||||||
INNER JOIN project_types pt ON c.project_type = pt.id
|
INNER JOIN project_types pt ON c.project_type = pt.id
|
||||||
ORDER BY c.id
|
ORDER BY c.ordering, c.category
|
||||||
"
|
"
|
||||||
)
|
)
|
||||||
.fetch_many(exec)
|
.fetch_many(exec)
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ pub struct GalleryItem {
|
|||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub created: DateTime<Utc>,
|
pub created: DateTime<Utc>,
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GalleryItem {
|
impl GalleryItem {
|
||||||
@@ -55,17 +56,18 @@ impl GalleryItem {
|
|||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
INSERT INTO mods_gallery (
|
INSERT INTO mods_gallery (
|
||||||
mod_id, image_url, featured, title, description
|
mod_id, image_url, featured, title, description, ordering
|
||||||
)
|
)
|
||||||
VALUES (
|
VALUES (
|
||||||
$1, $2, $3, $4, $5
|
$1, $2, $3, $4, $5, $6
|
||||||
)
|
)
|
||||||
",
|
",
|
||||||
project_id as ProjectId,
|
project_id as ProjectId,
|
||||||
self.image_url,
|
self.image_url,
|
||||||
self.featured,
|
self.featured,
|
||||||
self.title,
|
self.title,
|
||||||
self.description
|
self.description,
|
||||||
|
self.ordering
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.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 false) categories,
|
||||||
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_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('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
|
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
|
FROM mods m
|
||||||
INNER JOIN project_types pt ON pt.id = m.project_type
|
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()
|
versions.into_iter().map(|x| x.id).collect()
|
||||||
},
|
},
|
||||||
gallery_items: serde_json::from_value(
|
gallery_items: {
|
||||||
m.gallery.unwrap_or_default(),
|
let mut gallery: Vec<GalleryItem> =
|
||||||
)
|
serde_json::from_value(m.gallery.unwrap_or_default())
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
gallery.sort_by(|a, b| a.ordering.cmp(&b.ordering));
|
||||||
|
|
||||||
|
gallery
|
||||||
|
},
|
||||||
donation_urls: serde_json::from_value(
|
donation_urls: serde_json::from_value(
|
||||||
m.donations.unwrap_or_default(),
|
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 false) categories,
|
||||||
ARRAY_AGG(DISTINCT c.category) filter (where c.category is not null and mc.is_additional is true) additional_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('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
|
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
|
FROM mods m
|
||||||
INNER JOIN project_types pt ON pt.id = m.project_type
|
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()
|
versions.into_iter().map(|x| x.id).collect()
|
||||||
},
|
},
|
||||||
gallery_items: serde_json::from_value(
|
gallery_items: {
|
||||||
m.gallery.unwrap_or_default(),
|
let mut gallery: Vec<GalleryItem> = serde_json::from_value(
|
||||||
).ok().unwrap_or_default(),
|
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(
|
donation_urls: serde_json::from_value(
|
||||||
m.donations.unwrap_or_default(),
|
m.donations.unwrap_or_default(),
|
||||||
).ok().unwrap_or_default(),
|
).ok().unwrap_or_default(),
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ pub struct TeamMemberBuilder {
|
|||||||
pub permissions: Permissions,
|
pub permissions: Permissions,
|
||||||
pub accepted: bool,
|
pub accepted: bool,
|
||||||
pub payouts_split: Decimal,
|
pub payouts_split: Decimal,
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TeamBuilder {
|
impl TeamBuilder {
|
||||||
@@ -45,12 +46,13 @@ impl TeamBuilder {
|
|||||||
permissions: member.permissions,
|
permissions: member.permissions,
|
||||||
accepted: member.accepted,
|
accepted: member.accepted,
|
||||||
payouts_split: member.payouts_split,
|
payouts_split: member.payouts_split,
|
||||||
|
ordering: member.ordering,
|
||||||
};
|
};
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"
|
"
|
||||||
INSERT INTO team_members (id, team_id, user_id, role, permissions, accepted, payouts_split)
|
INSERT INTO team_members (id, team_id, user_id, role, permissions, accepted, payouts_split, ordering)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||||
",
|
",
|
||||||
team_member.id as TeamMemberId,
|
team_member.id as TeamMemberId,
|
||||||
team_member.team_id as TeamId,
|
team_member.team_id as TeamId,
|
||||||
@@ -59,6 +61,7 @@ impl TeamBuilder {
|
|||||||
team_member.permissions.bits() as i64,
|
team_member.permissions.bits() as i64,
|
||||||
team_member.accepted,
|
team_member.accepted,
|
||||||
team_member.payouts_split,
|
team_member.payouts_split,
|
||||||
|
team_member.ordering,
|
||||||
)
|
)
|
||||||
.execute(&mut *transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -84,6 +87,7 @@ pub struct TeamMember {
|
|||||||
pub permissions: Permissions,
|
pub permissions: Permissions,
|
||||||
pub accepted: bool,
|
pub accepted: bool,
|
||||||
pub payouts_split: Decimal,
|
pub payouts_split: Decimal,
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A member of a team
|
/// A member of a team
|
||||||
@@ -96,6 +100,7 @@ pub struct QueryTeamMember {
|
|||||||
pub permissions: Permissions,
|
pub permissions: Permissions,
|
||||||
pub accepted: bool,
|
pub accepted: bool,
|
||||||
pub payouts_split: Decimal,
|
pub payouts_split: Decimal,
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TeamMember {
|
impl TeamMember {
|
||||||
@@ -111,9 +116,10 @@ impl TeamMember {
|
|||||||
|
|
||||||
let team_members = sqlx::query!(
|
let team_members = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id, user_id, role, permissions, accepted, payouts_split
|
SELECT id, user_id, role, permissions, accepted, payouts_split, ordering
|
||||||
FROM team_members
|
FROM team_members
|
||||||
WHERE team_id = $1
|
WHERE team_id = $1
|
||||||
|
ORDER BY ordering
|
||||||
",
|
",
|
||||||
id as TeamId,
|
id as TeamId,
|
||||||
)
|
)
|
||||||
@@ -129,6 +135,7 @@ impl TeamMember {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split,
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -156,7 +163,7 @@ impl TeamMember {
|
|||||||
|
|
||||||
let team_members = sqlx::query!(
|
let team_members = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT tm.id id, tm.role member_role, tm.permissions permissions, tm.accepted accepted, tm.payouts_split payouts_split,
|
SELECT tm.id id, tm.role member_role, tm.permissions permissions, tm.accepted accepted, tm.payouts_split payouts_split, tm.ordering ordering,
|
||||||
u.id user_id, u.github_id github_id, u.name user_name, u.email email,
|
u.id user_id, u.github_id github_id, u.name user_name, u.email email,
|
||||||
u.avatar_url avatar_url, u.username username, u.bio bio,
|
u.avatar_url avatar_url, u.username username, u.bio bio,
|
||||||
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
||||||
@@ -165,6 +172,7 @@ impl TeamMember {
|
|||||||
FROM team_members tm
|
FROM team_members tm
|
||||||
INNER JOIN users u ON u.id = tm.user_id
|
INNER JOIN users u ON u.id = tm.user_id
|
||||||
WHERE tm.team_id = $1
|
WHERE tm.team_id = $1
|
||||||
|
ORDER BY tm.ordering
|
||||||
",
|
",
|
||||||
id as TeamId,
|
id as TeamId,
|
||||||
)
|
)
|
||||||
@@ -195,7 +203,8 @@ impl TeamMember {
|
|||||||
payout_address: m.payout_address,
|
payout_address: m.payout_address,
|
||||||
flame_anvil_key: m.flame_anvil_key,
|
flame_anvil_key: m.flame_anvil_key,
|
||||||
},
|
},
|
||||||
payouts_split: m.payouts_split
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -225,7 +234,7 @@ impl TeamMember {
|
|||||||
|
|
||||||
let teams = sqlx::query!(
|
let teams = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT tm.id id, tm.team_id team_id, tm.role member_role, tm.permissions permissions, tm.accepted accepted, tm.payouts_split payouts_split,
|
SELECT tm.id id, tm.team_id team_id, tm.role member_role, tm.permissions permissions, tm.accepted accepted, tm.payouts_split payouts_split, tm.ordering,
|
||||||
u.id user_id, u.github_id github_id, u.name user_name, u.email email,
|
u.id user_id, u.github_id github_id, u.name user_name, u.email email,
|
||||||
u.avatar_url avatar_url, u.username username, u.bio bio,
|
u.avatar_url avatar_url, u.username username, u.bio bio,
|
||||||
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
u.created created, u.role user_role, u.badges badges, u.balance balance,
|
||||||
@@ -234,7 +243,7 @@ impl TeamMember {
|
|||||||
FROM team_members tm
|
FROM team_members tm
|
||||||
INNER JOIN users u ON u.id = tm.user_id
|
INNER JOIN users u ON u.id = tm.user_id
|
||||||
WHERE tm.team_id = ANY($1)
|
WHERE tm.team_id = ANY($1)
|
||||||
ORDER BY tm.team_id
|
ORDER BY tm.team_id, tm.ordering
|
||||||
",
|
",
|
||||||
&team_ids_parsed
|
&team_ids_parsed
|
||||||
)
|
)
|
||||||
@@ -265,7 +274,8 @@ impl TeamMember {
|
|||||||
payout_address: m.payout_address,
|
payout_address: m.payout_address,
|
||||||
flame_anvil_key: m.flame_anvil_key,
|
flame_anvil_key: m.flame_anvil_key,
|
||||||
},
|
},
|
||||||
payouts_split: m.payouts_split
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -293,9 +303,10 @@ impl TeamMember {
|
|||||||
|
|
||||||
let team_members = sqlx::query!(
|
let team_members = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id, team_id, role, permissions, accepted, payouts_split
|
SELECT id, team_id, role, permissions, accepted, payouts_split, ordering
|
||||||
FROM team_members
|
FROM team_members
|
||||||
WHERE (user_id = $1 AND accepted = TRUE)
|
WHERE (user_id = $1 AND accepted = TRUE)
|
||||||
|
ORDER BY ordering
|
||||||
",
|
",
|
||||||
id as UserId,
|
id as UserId,
|
||||||
)
|
)
|
||||||
@@ -311,6 +322,7 @@ impl TeamMember {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split,
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -338,9 +350,10 @@ impl TeamMember {
|
|||||||
|
|
||||||
let team_members = sqlx::query!(
|
let team_members = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id, team_id, role, permissions, accepted, payouts_split
|
SELECT id, team_id, role, permissions, accepted, payouts_split, ordering
|
||||||
FROM team_members
|
FROM team_members
|
||||||
WHERE user_id = $1
|
WHERE user_id = $1
|
||||||
|
ORDER BY ordering
|
||||||
",
|
",
|
||||||
id as UserId,
|
id as UserId,
|
||||||
)
|
)
|
||||||
@@ -356,6 +369,7 @@ impl TeamMember {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split,
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -382,7 +396,7 @@ impl TeamMember {
|
|||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id, user_id, role, permissions, accepted, payouts_split
|
SELECT id, user_id, role, permissions, accepted, payouts_split, ordering
|
||||||
FROM team_members
|
FROM team_members
|
||||||
WHERE (team_id = $1 AND user_id = $2 AND accepted = TRUE)
|
WHERE (team_id = $1 AND user_id = $2 AND accepted = TRUE)
|
||||||
",
|
",
|
||||||
@@ -402,6 +416,7 @@ impl TeamMember {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split,
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -424,9 +439,10 @@ impl TeamMember {
|
|||||||
|
|
||||||
let team_members = sqlx::query!(
|
let team_members = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id, team_id, user_id, role, permissions, accepted, payouts_split
|
SELECT id, team_id, user_id, role, permissions, accepted, payouts_split, ordering
|
||||||
FROM team_members
|
FROM team_members
|
||||||
WHERE (team_id = ANY($1) AND user_id = $2 AND accepted = TRUE)
|
WHERE (team_id = ANY($1) AND user_id = $2 AND accepted = TRUE)
|
||||||
|
ORDER BY ordering
|
||||||
",
|
",
|
||||||
&team_ids_parsed,
|
&team_ids_parsed,
|
||||||
user_id as UserId
|
user_id as UserId
|
||||||
@@ -441,7 +457,8 @@ impl TeamMember {
|
|||||||
role: m.role,
|
role: m.role,
|
||||||
permissions: Permissions::from_bits(m.permissions as u64).unwrap_or_default(),
|
permissions: Permissions::from_bits(m.permissions as u64).unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -468,7 +485,7 @@ impl TeamMember {
|
|||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT id, user_id, role, permissions, accepted, payouts_split
|
SELECT id, user_id, role, permissions, accepted, payouts_split, ordering
|
||||||
FROM team_members
|
FROM team_members
|
||||||
WHERE (team_id = $1 AND user_id = $2)
|
WHERE (team_id = $1 AND user_id = $2)
|
||||||
",
|
",
|
||||||
@@ -488,6 +505,7 @@ impl TeamMember {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split,
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -559,6 +577,7 @@ impl TeamMember {
|
|||||||
new_role: Option<String>,
|
new_role: Option<String>,
|
||||||
new_accepted: Option<bool>,
|
new_accepted: Option<bool>,
|
||||||
new_payouts_split: Option<Decimal>,
|
new_payouts_split: Option<Decimal>,
|
||||||
|
new_ordering: Option<i64>,
|
||||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||||
) -> Result<(), super::DatabaseError> {
|
) -> Result<(), super::DatabaseError> {
|
||||||
if let Some(permissions) = new_permissions {
|
if let Some(permissions) = new_permissions {
|
||||||
@@ -622,6 +641,21 @@ impl TeamMember {
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(ordering) = new_ordering {
|
||||||
|
sqlx::query!(
|
||||||
|
"
|
||||||
|
UPDATE team_members
|
||||||
|
SET ordering = $1
|
||||||
|
WHERE (team_id = $2 AND user_id = $3)
|
||||||
|
",
|
||||||
|
ordering,
|
||||||
|
id as TeamId,
|
||||||
|
user_id as UserId,
|
||||||
|
)
|
||||||
|
.execute(&mut *transaction)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,7 +669,7 @@ impl TeamMember {
|
|||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT tm.id, tm.team_id, tm.user_id, tm.role, tm.permissions, tm.accepted, tm.payouts_split FROM mods m
|
SELECT tm.id, tm.team_id, tm.user_id, tm.role, tm.permissions, tm.accepted, tm.payouts_split, tm.ordering FROM mods m
|
||||||
INNER JOIN team_members tm ON tm.team_id = m.team_id AND user_id = $2 AND accepted = TRUE
|
INNER JOIN team_members tm ON tm.team_id = m.team_id AND user_id = $2 AND accepted = TRUE
|
||||||
WHERE m.id = $1
|
WHERE m.id = $1
|
||||||
",
|
",
|
||||||
@@ -655,6 +689,7 @@ impl TeamMember {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split,
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -671,7 +706,7 @@ impl TeamMember {
|
|||||||
{
|
{
|
||||||
let result = sqlx::query!(
|
let result = sqlx::query!(
|
||||||
"
|
"
|
||||||
SELECT tm.id, tm.team_id, tm.user_id, tm.role, tm.permissions, tm.accepted, tm.payouts_split FROM versions v
|
SELECT tm.id, tm.team_id, tm.user_id, tm.role, tm.permissions, tm.accepted, tm.payouts_split, tm.ordering FROM versions v
|
||||||
INNER JOIN mods m ON m.id = v.mod_id
|
INNER JOIN mods m ON m.id = v.mod_id
|
||||||
INNER JOIN team_members tm ON tm.team_id = m.team_id AND tm.user_id = $2 AND tm.accepted = TRUE
|
INNER JOIN team_members tm ON tm.team_id = m.team_id AND tm.user_id = $2 AND tm.accepted = TRUE
|
||||||
WHERE v.id = $1
|
WHERE v.id = $1
|
||||||
@@ -692,6 +727,7 @@ impl TeamMember {
|
|||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
accepted: m.accepted,
|
accepted: m.accepted,
|
||||||
payouts_split: m.payouts_split,
|
payouts_split: m.payouts_split,
|
||||||
|
ordering: m.ordering,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ impl From<QueryProject> for Project {
|
|||||||
title: x.title,
|
title: x.title,
|
||||||
description: x.description,
|
description: x.description,
|
||||||
created: x.created,
|
created: x.created,
|
||||||
|
ordering: x.ordering,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
flame_anvil_project: m.flame_anvil_project,
|
flame_anvil_project: m.flame_anvil_project,
|
||||||
@@ -191,6 +192,7 @@ pub struct GalleryItem {
|
|||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub created: DateTime<Utc>,
|
pub created: DateTime<Utc>,
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ pub struct TeamMember {
|
|||||||
/// Payouts split. This is a weighted average. For example. if a team has two members with this
|
/// Payouts split. This is a weighted average. For example. if a team has two members with this
|
||||||
/// value set to 25.0 for both members, they split revenue 50/50
|
/// value set to 25.0 for both members, they split revenue 50/50
|
||||||
pub payouts_split: Option<Decimal>,
|
pub payouts_split: Option<Decimal>,
|
||||||
|
/// Ordering of the member in the list
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TeamMember {
|
impl TeamMember {
|
||||||
@@ -91,6 +93,7 @@ impl TeamMember {
|
|||||||
} else {
|
} else {
|
||||||
Some(data.payouts_split)
|
Some(data.payouts_split)
|
||||||
},
|
},
|
||||||
|
ordering: data.ordering,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ pub struct NewGalleryItem {
|
|||||||
#[validate(length(min = 1, max = 2048))]
|
#[validate(length(min = 1, max = 2048))]
|
||||||
/// The description of the gallery item
|
/// The description of the gallery item
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UploadedFile {
|
pub struct UploadedFile {
|
||||||
@@ -553,6 +554,7 @@ pub async fn project_create_inner(
|
|||||||
title: item.title.clone(),
|
title: item.title.clone(),
|
||||||
description: item.description.clone(),
|
description: item.description.clone(),
|
||||||
created: Utc::now(),
|
created: Utc::now(),
|
||||||
|
ordering: item.ordering,
|
||||||
});
|
});
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@@ -650,6 +652,7 @@ pub async fn project_create_inner(
|
|||||||
permissions: crate::models::teams::Permissions::ALL,
|
permissions: crate::models::teams::Permissions::ALL,
|
||||||
accepted: true,
|
accepted: true,
|
||||||
payouts_split: Decimal::ONE_HUNDRED,
|
payouts_split: Decimal::ONE_HUNDRED,
|
||||||
|
ordering: 0,
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -763,6 +766,7 @@ pub async fn project_create_inner(
|
|||||||
title: x.title.clone(),
|
title: x.title.clone(),
|
||||||
description: x.description.clone(),
|
description: x.description.clone(),
|
||||||
created: x.created,
|
created: x.created,
|
||||||
|
ordering: x.ordering,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1399,6 +1399,7 @@ pub struct GalleryCreateQuery {
|
|||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
#[validate(length(min = 1, max = 2048))]
|
#[validate(length(min = 1, max = 2048))]
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
|
pub ordering: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("{id}/gallery")]
|
#[post("{id}/gallery")]
|
||||||
@@ -1498,6 +1499,7 @@ pub async fn add_gallery_item(
|
|||||||
title: item.title,
|
title: item.title,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
created: Utc::now(),
|
created: Utc::now(),
|
||||||
|
ordering: item.ordering.unwrap_or(0),
|
||||||
}
|
}
|
||||||
.insert(project_item.inner.id, &mut transaction)
|
.insert(project_item.inner.id, &mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -1532,6 +1534,7 @@ pub struct GalleryEditQuery {
|
|||||||
)]
|
)]
|
||||||
#[validate(length(min = 1, max = 2048))]
|
#[validate(length(min = 1, max = 2048))]
|
||||||
pub description: Option<Option<String>>,
|
pub description: Option<Option<String>>,
|
||||||
|
pub ordering: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[patch("{id}/gallery")]
|
#[patch("{id}/gallery")]
|
||||||
@@ -1653,6 +1656,19 @@ pub async fn edit_gallery_item(
|
|||||||
.execute(&mut *transaction)
|
.execute(&mut *transaction)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
if let Some(ordering) = item.ordering {
|
||||||
|
sqlx::query!(
|
||||||
|
"
|
||||||
|
UPDATE mods_gallery
|
||||||
|
SET ordering = $2
|
||||||
|
WHERE id = $1
|
||||||
|
",
|
||||||
|
id,
|
||||||
|
ordering
|
||||||
|
)
|
||||||
|
.execute(&mut *transaction)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
transaction.commit().await?;
|
transaction.commit().await?;
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -46,7 +46,7 @@ pub struct CategoryData {
|
|||||||
pub async fn category_list(
|
pub async fn category_list(
|
||||||
pool: web::Data<PgPool>,
|
pool: web::Data<PgPool>,
|
||||||
) -> Result<HttpResponse, ApiError> {
|
) -> Result<HttpResponse, ApiError> {
|
||||||
let mut results = Category::list(&**pool)
|
let results = Category::list(&**pool)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| CategoryData {
|
.map(|x| CategoryData {
|
||||||
@@ -57,8 +57,6 @@ pub async fn category_list(
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
results.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase()));
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(results))
|
Ok(HttpResponse::Ok().json(results))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ pub async fn join_team(
|
|||||||
None,
|
None,
|
||||||
Some(true),
|
Some(true),
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
&mut transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -209,6 +210,10 @@ fn default_role() -> String {
|
|||||||
"Member".to_string()
|
"Member".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_ordering() -> i64 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct NewTeamMember {
|
pub struct NewTeamMember {
|
||||||
pub user_id: UserId,
|
pub user_id: UserId,
|
||||||
@@ -218,6 +223,8 @@ pub struct NewTeamMember {
|
|||||||
pub permissions: Permissions,
|
pub permissions: Permissions,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub payouts_split: Decimal,
|
pub payouts_split: Decimal,
|
||||||
|
#[serde(default = "default_ordering")]
|
||||||
|
pub ordering: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("{id}/members")]
|
#[post("{id}/members")]
|
||||||
@@ -305,6 +312,7 @@ pub async fn add_team_member(
|
|||||||
permissions: new_member.permissions,
|
permissions: new_member.permissions,
|
||||||
accepted: false,
|
accepted: false,
|
||||||
payouts_split: new_member.payouts_split,
|
payouts_split: new_member.payouts_split,
|
||||||
|
ordering: new_member.ordering,
|
||||||
}
|
}
|
||||||
.insert(&mut transaction)
|
.insert(&mut transaction)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -364,6 +372,7 @@ pub struct EditTeamMember {
|
|||||||
pub permissions: Option<Permissions>,
|
pub permissions: Option<Permissions>,
|
||||||
pub role: Option<String>,
|
pub role: Option<String>,
|
||||||
pub payouts_split: Option<Decimal>,
|
pub payouts_split: Option<Decimal>,
|
||||||
|
pub ordering: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[patch("{id}/members/{user_id}")]
|
#[patch("{id}/members/{user_id}")]
|
||||||
@@ -446,6 +455,7 @@ pub async fn edit_team_member(
|
|||||||
edit_member.role.clone(),
|
edit_member.role.clone(),
|
||||||
None,
|
None,
|
||||||
edit_member.payouts_split,
|
edit_member.payouts_split,
|
||||||
|
edit_member.ordering,
|
||||||
&mut transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -520,6 +530,7 @@ pub async fn transfer_ownership(
|
|||||||
Some(crate::models::teams::DEFAULT_ROLE.to_string()),
|
Some(crate::models::teams::DEFAULT_ROLE.to_string()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
&mut transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -531,6 +542,7 @@ pub async fn transfer_ownership(
|
|||||||
Some(crate::models::teams::OWNER_ROLE.to_string()),
|
Some(crate::models::teams::OWNER_ROLE.to_string()),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
&mut transaction,
|
&mut transaction,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user