You've already forked AstralRinth
forked from didirus/AstralRinth
Add ordering to categories, gallery images, and team members (#501)
This commit is contained in:
@@ -240,6 +240,7 @@ pub struct NewGalleryItem {
|
||||
#[validate(length(min = 1, max = 2048))]
|
||||
/// The description of the gallery item
|
||||
pub description: Option<String>,
|
||||
pub ordering: i64,
|
||||
}
|
||||
|
||||
pub struct UploadedFile {
|
||||
@@ -553,6 +554,7 @@ pub async fn project_create_inner(
|
||||
title: item.title.clone(),
|
||||
description: item.description.clone(),
|
||||
created: Utc::now(),
|
||||
ordering: item.ordering,
|
||||
});
|
||||
|
||||
continue;
|
||||
@@ -650,6 +652,7 @@ pub async fn project_create_inner(
|
||||
permissions: crate::models::teams::Permissions::ALL,
|
||||
accepted: true,
|
||||
payouts_split: Decimal::ONE_HUNDRED,
|
||||
ordering: 0,
|
||||
}],
|
||||
};
|
||||
|
||||
@@ -763,6 +766,7 @@ pub async fn project_create_inner(
|
||||
title: x.title.clone(),
|
||||
description: x.description.clone(),
|
||||
created: x.created,
|
||||
ordering: x.ordering,
|
||||
})
|
||||
.collect(),
|
||||
};
|
||||
|
||||
@@ -1399,6 +1399,7 @@ pub struct GalleryCreateQuery {
|
||||
pub title: Option<String>,
|
||||
#[validate(length(min = 1, max = 2048))]
|
||||
pub description: Option<String>,
|
||||
pub ordering: Option<i64>,
|
||||
}
|
||||
|
||||
#[post("{id}/gallery")]
|
||||
@@ -1498,6 +1499,7 @@ pub async fn add_gallery_item(
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
created: Utc::now(),
|
||||
ordering: item.ordering.unwrap_or(0),
|
||||
}
|
||||
.insert(project_item.inner.id, &mut transaction)
|
||||
.await?;
|
||||
@@ -1532,6 +1534,7 @@ pub struct GalleryEditQuery {
|
||||
)]
|
||||
#[validate(length(min = 1, max = 2048))]
|
||||
pub description: Option<Option<String>>,
|
||||
pub ordering: Option<i64>,
|
||||
}
|
||||
|
||||
#[patch("{id}/gallery")]
|
||||
@@ -1653,6 +1656,19 @@ pub async fn edit_gallery_item(
|
||||
.execute(&mut *transaction)
|
||||
.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?;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ pub struct CategoryData {
|
||||
pub async fn category_list(
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let mut results = Category::list(&**pool)
|
||||
let results = Category::list(&**pool)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|x| CategoryData {
|
||||
@@ -57,8 +57,6 @@ pub async fn category_list(
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
results.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase()));
|
||||
|
||||
Ok(HttpResponse::Ok().json(results))
|
||||
}
|
||||
|
||||
|
||||
@@ -191,6 +191,7 @@ pub async fn join_team(
|
||||
None,
|
||||
Some(true),
|
||||
None,
|
||||
None,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@@ -209,6 +210,10 @@ fn default_role() -> String {
|
||||
"Member".to_string()
|
||||
}
|
||||
|
||||
fn default_ordering() -> i64 {
|
||||
0
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct NewTeamMember {
|
||||
pub user_id: UserId,
|
||||
@@ -218,6 +223,8 @@ pub struct NewTeamMember {
|
||||
pub permissions: Permissions,
|
||||
#[serde(default)]
|
||||
pub payouts_split: Decimal,
|
||||
#[serde(default = "default_ordering")]
|
||||
pub ordering: i64,
|
||||
}
|
||||
|
||||
#[post("{id}/members")]
|
||||
@@ -305,6 +312,7 @@ pub async fn add_team_member(
|
||||
permissions: new_member.permissions,
|
||||
accepted: false,
|
||||
payouts_split: new_member.payouts_split,
|
||||
ordering: new_member.ordering,
|
||||
}
|
||||
.insert(&mut transaction)
|
||||
.await?;
|
||||
@@ -364,6 +372,7 @@ pub struct EditTeamMember {
|
||||
pub permissions: Option<Permissions>,
|
||||
pub role: Option<String>,
|
||||
pub payouts_split: Option<Decimal>,
|
||||
pub ordering: Option<i64>,
|
||||
}
|
||||
|
||||
#[patch("{id}/members/{user_id}")]
|
||||
@@ -446,6 +455,7 @@ pub async fn edit_team_member(
|
||||
edit_member.role.clone(),
|
||||
None,
|
||||
edit_member.payouts_split,
|
||||
edit_member.ordering,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@@ -520,6 +530,7 @@ pub async fn transfer_ownership(
|
||||
Some(crate::models::teams::DEFAULT_ROLE.to_string()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@@ -531,6 +542,7 @@ pub async fn transfer_ownership(
|
||||
Some(crate::models::teams::OWNER_ROLE.to_string()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user