You've already forked AstralRinth
forked from didirus/AstralRinth
Run fmt, fix dep route (#312)
This commit is contained in:
@@ -62,7 +62,10 @@ impl Category {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_id<'a, E>(name: &str, exec: E) -> Result<Option<CategoryId>, DatabaseError>
|
||||
pub async fn get_id<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<CategoryId>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -115,7 +118,10 @@ impl Category {
|
||||
Ok(result.map(|r| CategoryId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn get_name<'a, E>(id: CategoryId, exec: E) -> Result<String, DatabaseError>
|
||||
pub async fn get_name<'a, E>(
|
||||
id: CategoryId,
|
||||
exec: E,
|
||||
) -> Result<String, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -159,7 +165,10 @@ impl Category {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn remove<'a, E>(name: &str, exec: E) -> Result<Option<()>, DatabaseError>
|
||||
pub async fn remove<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -184,7 +193,10 @@ impl Category {
|
||||
|
||||
impl<'a> CategoryBuilder<'a> {
|
||||
/// The name of the category. Must be ASCII alphanumeric or `-`/`_`
|
||||
pub fn name(self, name: &'a str) -> Result<CategoryBuilder<'a>, DatabaseError> {
|
||||
pub fn name(
|
||||
self,
|
||||
name: &'a str,
|
||||
) -> Result<CategoryBuilder<'a>, DatabaseError> {
|
||||
if name
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
||||
@@ -208,20 +220,26 @@ impl<'a> CategoryBuilder<'a> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn icon(self, icon: &'a str) -> Result<CategoryBuilder<'a>, DatabaseError> {
|
||||
pub fn icon(
|
||||
self,
|
||||
icon: &'a str,
|
||||
) -> Result<CategoryBuilder<'a>, DatabaseError> {
|
||||
Ok(Self {
|
||||
icon: Some(icon),
|
||||
..self
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn insert<'b, E>(self, exec: E) -> Result<CategoryId, DatabaseError>
|
||||
pub async fn insert<'b, E>(
|
||||
self,
|
||||
exec: E,
|
||||
) -> Result<CategoryId, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'b, Database = sqlx::Postgres>,
|
||||
{
|
||||
let id = *self
|
||||
.project_type
|
||||
.ok_or_else(|| DatabaseError::Other("No project type specified.".to_string()))?;
|
||||
let id = *self.project_type.ok_or_else(|| {
|
||||
DatabaseError::Other("No project type specified.".to_string())
|
||||
})?;
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
INSERT INTO categories (category, project_type, icon)
|
||||
@@ -254,7 +272,10 @@ impl Loader {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_id<'a, E>(name: &str, exec: E) -> Result<Option<LoaderId>, DatabaseError>
|
||||
pub async fn get_id<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<LoaderId>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -278,7 +299,10 @@ impl Loader {
|
||||
Ok(result.map(|r| LoaderId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn get_name<'a, E>(id: LoaderId, exec: E) -> Result<String, DatabaseError>
|
||||
pub async fn get_name<'a, E>(
|
||||
id: LoaderId,
|
||||
exec: E,
|
||||
) -> Result<String, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -330,7 +354,10 @@ impl Loader {
|
||||
}
|
||||
|
||||
// TODO: remove loaders with projects using them
|
||||
pub async fn remove<'a, E>(name: &str, exec: E) -> Result<Option<()>, DatabaseError>
|
||||
pub async fn remove<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -355,7 +382,10 @@ impl Loader {
|
||||
|
||||
impl<'a> LoaderBuilder<'a> {
|
||||
/// The name of the loader. Must be ASCII alphanumeric or `-`/`_`
|
||||
pub fn name(self, name: &'a str) -> Result<LoaderBuilder<'a>, DatabaseError> {
|
||||
pub fn name(
|
||||
self,
|
||||
name: &'a str,
|
||||
) -> Result<LoaderBuilder<'a>, DatabaseError> {
|
||||
if name
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
||||
@@ -369,7 +399,10 @@ impl<'a> LoaderBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn icon(self, icon: &'a str) -> Result<LoaderBuilder<'a>, DatabaseError> {
|
||||
pub fn icon(
|
||||
self,
|
||||
icon: &'a str,
|
||||
) -> Result<LoaderBuilder<'a>, DatabaseError> {
|
||||
Ok(Self {
|
||||
icon: Some(icon),
|
||||
..self
|
||||
@@ -471,7 +504,10 @@ impl GameVersion {
|
||||
Ok(result.map(|r| GameVersionId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn get_name<'a, E>(id: GameVersionId, exec: E) -> Result<String, DatabaseError>
|
||||
pub async fn get_name<'a, E>(
|
||||
id: GameVersionId,
|
||||
exec: E,
|
||||
) -> Result<String, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -589,7 +625,10 @@ impl GameVersion {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn remove<'a, E>(name: &str, exec: E) -> Result<Option<()>, DatabaseError>
|
||||
pub async fn remove<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -614,7 +653,10 @@ impl GameVersion {
|
||||
|
||||
impl<'a> GameVersionBuilder<'a> {
|
||||
/// The game version. Spaces must be replaced with '_' for it to be valid
|
||||
pub fn version(self, version: &'a str) -> Result<GameVersionBuilder<'a>, DatabaseError> {
|
||||
pub fn version(
|
||||
self,
|
||||
version: &'a str,
|
||||
) -> Result<GameVersionBuilder<'a>, DatabaseError> {
|
||||
if version
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || "-_.".contains(c))
|
||||
@@ -645,14 +687,20 @@ impl<'a> GameVersionBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn created(self, created: &'a chrono::DateTime<chrono::Utc>) -> GameVersionBuilder<'a> {
|
||||
pub fn created(
|
||||
self,
|
||||
created: &'a chrono::DateTime<chrono::Utc>,
|
||||
) -> GameVersionBuilder<'a> {
|
||||
Self {
|
||||
date: Some(created),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn insert<'b, E>(self, exec: E) -> Result<GameVersionId, DatabaseError>
|
||||
pub async fn insert<'b, E>(
|
||||
self,
|
||||
exec: E,
|
||||
) -> Result<GameVersionId, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'b, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -690,7 +738,10 @@ impl License {
|
||||
LicenseBuilder::default()
|
||||
}
|
||||
|
||||
pub async fn get_id<'a, E>(id: &str, exec: E) -> Result<Option<LicenseId>, DatabaseError>
|
||||
pub async fn get_id<'a, E>(
|
||||
id: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<LicenseId>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -707,7 +758,10 @@ impl License {
|
||||
Ok(result.map(|r| LicenseId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn get<'a, E>(id: LicenseId, exec: E) -> Result<License, DatabaseError>
|
||||
pub async fn get<'a, E>(
|
||||
id: LicenseId,
|
||||
exec: E,
|
||||
) -> Result<License, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -751,7 +805,10 @@ impl License {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn remove<'a, E>(short: &str, exec: E) -> Result<Option<()>, DatabaseError>
|
||||
pub async fn remove<'a, E>(
|
||||
short: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -776,7 +833,10 @@ impl License {
|
||||
|
||||
impl<'a> LicenseBuilder<'a> {
|
||||
/// The license's short name/abbreviation. Spaces must be replaced with '_' for it to be valid
|
||||
pub fn short(self, short: &'a str) -> Result<LicenseBuilder<'a>, DatabaseError> {
|
||||
pub fn short(
|
||||
self,
|
||||
short: &'a str,
|
||||
) -> Result<LicenseBuilder<'a>, DatabaseError> {
|
||||
if short
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || "-_.".contains(c))
|
||||
@@ -791,14 +851,20 @@ impl<'a> LicenseBuilder<'a> {
|
||||
}
|
||||
|
||||
/// The license's long name
|
||||
pub fn name(self, name: &'a str) -> Result<LicenseBuilder<'a>, DatabaseError> {
|
||||
pub fn name(
|
||||
self,
|
||||
name: &'a str,
|
||||
) -> Result<LicenseBuilder<'a>, DatabaseError> {
|
||||
Ok(Self {
|
||||
name: Some(name),
|
||||
..self
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn insert<'b, E>(self, exec: E) -> Result<LicenseId, DatabaseError>
|
||||
pub async fn insert<'b, E>(
|
||||
self,
|
||||
exec: E,
|
||||
) -> Result<LicenseId, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'b, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -874,7 +940,9 @@ impl DonationPlatform {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(exec: E) -> Result<Vec<DonationPlatform>, DatabaseError>
|
||||
pub async fn list<'a, E>(
|
||||
exec: E,
|
||||
) -> Result<Vec<DonationPlatform>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -897,7 +965,10 @@ impl DonationPlatform {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn remove<'a, E>(short: &str, exec: E) -> Result<Option<()>, DatabaseError>
|
||||
pub async fn remove<'a, E>(
|
||||
short: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -922,7 +993,10 @@ impl DonationPlatform {
|
||||
|
||||
impl<'a> DonationPlatformBuilder<'a> {
|
||||
/// The donation platform short name. Spaces must be replaced with '_' for it to be valid
|
||||
pub fn short(self, short: &'a str) -> Result<DonationPlatformBuilder<'a>, DatabaseError> {
|
||||
pub fn short(
|
||||
self,
|
||||
short: &'a str,
|
||||
) -> Result<DonationPlatformBuilder<'a>, DatabaseError> {
|
||||
if short
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || "-_.".contains(c))
|
||||
@@ -937,14 +1011,20 @@ impl<'a> DonationPlatformBuilder<'a> {
|
||||
}
|
||||
|
||||
/// The donation platform long name
|
||||
pub fn name(self, name: &'a str) -> Result<DonationPlatformBuilder<'a>, DatabaseError> {
|
||||
pub fn name(
|
||||
self,
|
||||
name: &'a str,
|
||||
) -> Result<DonationPlatformBuilder<'a>, DatabaseError> {
|
||||
Ok(Self {
|
||||
name: Some(name),
|
||||
..self
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn insert<'b, E>(self, exec: E) -> Result<DonationPlatformId, DatabaseError>
|
||||
pub async fn insert<'b, E>(
|
||||
self,
|
||||
exec: E,
|
||||
) -> Result<DonationPlatformId, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'b, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -974,7 +1054,10 @@ impl ReportType {
|
||||
ReportTypeBuilder { name: None }
|
||||
}
|
||||
|
||||
pub async fn get_id<'a, E>(name: &str, exec: E) -> Result<Option<ReportTypeId>, DatabaseError>
|
||||
pub async fn get_id<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<ReportTypeId>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -998,7 +1081,10 @@ impl ReportType {
|
||||
Ok(result.map(|r| ReportTypeId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn get_name<'a, E>(id: ReportTypeId, exec: E) -> Result<String, DatabaseError>
|
||||
pub async fn get_name<'a, E>(
|
||||
id: ReportTypeId,
|
||||
exec: E,
|
||||
) -> Result<String, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -1032,7 +1118,10 @@ impl ReportType {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn remove<'a, E>(name: &str, exec: E) -> Result<Option<()>, DatabaseError>
|
||||
pub async fn remove<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -1057,7 +1146,10 @@ impl ReportType {
|
||||
|
||||
impl<'a> ReportTypeBuilder<'a> {
|
||||
/// The name of the report type. Must be ASCII alphanumeric or `-`/`_`
|
||||
pub fn name(self, name: &'a str) -> Result<ReportTypeBuilder<'a>, DatabaseError> {
|
||||
pub fn name(
|
||||
self,
|
||||
name: &'a str,
|
||||
) -> Result<ReportTypeBuilder<'a>, DatabaseError> {
|
||||
if name
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
||||
@@ -1068,7 +1160,10 @@ impl<'a> ReportTypeBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn insert<'b, E>(self, exec: E) -> Result<ReportTypeId, DatabaseError>
|
||||
pub async fn insert<'b, E>(
|
||||
self,
|
||||
exec: E,
|
||||
) -> Result<ReportTypeId, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'b, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -1097,7 +1192,10 @@ impl ProjectType {
|
||||
ProjectTypeBuilder { name: None }
|
||||
}
|
||||
|
||||
pub async fn get_id<'a, E>(name: &str, exec: E) -> Result<Option<ProjectTypeId>, DatabaseError>
|
||||
pub async fn get_id<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<ProjectTypeId>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -1148,7 +1246,10 @@ impl ProjectType {
|
||||
Ok(project_types)
|
||||
}
|
||||
|
||||
pub async fn get_name<'a, E>(id: ProjectTypeId, exec: E) -> Result<String, DatabaseError>
|
||||
pub async fn get_name<'a, E>(
|
||||
id: ProjectTypeId,
|
||||
exec: E,
|
||||
) -> Result<String, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -1183,7 +1284,10 @@ impl ProjectType {
|
||||
}
|
||||
|
||||
// TODO: remove loaders with mods using them
|
||||
pub async fn remove<'a, E>(name: &str, exec: E) -> Result<Option<()>, DatabaseError>
|
||||
pub async fn remove<'a, E>(
|
||||
name: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -1208,7 +1312,10 @@ impl ProjectType {
|
||||
|
||||
impl<'a> ProjectTypeBuilder<'a> {
|
||||
/// The name of the project type. Must be ASCII alphanumeric or `-`/`_`
|
||||
pub fn name(self, name: &'a str) -> Result<ProjectTypeBuilder<'a>, DatabaseError> {
|
||||
pub fn name(
|
||||
self,
|
||||
name: &'a str,
|
||||
) -> Result<ProjectTypeBuilder<'a>, DatabaseError> {
|
||||
if name
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
||||
@@ -1219,7 +1326,10 @@ impl<'a> ProjectTypeBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn insert<'b, E>(self, exec: E) -> Result<ProjectTypeId, DatabaseError>
|
||||
pub async fn insert<'b, E>(
|
||||
self,
|
||||
exec: E,
|
||||
) -> Result<ProjectTypeId, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'b, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -83,7 +83,10 @@ impl ids::SideTypeId {
|
||||
}
|
||||
|
||||
impl ids::DonationPlatformId {
|
||||
pub async fn get_id<'a, E>(id: &str, exec: E) -> Result<Option<Self>, DatabaseError>
|
||||
pub async fn get_id<'a, E>(
|
||||
id: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<Self>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -102,7 +105,10 @@ impl ids::DonationPlatformId {
|
||||
}
|
||||
|
||||
impl ids::ProjectTypeId {
|
||||
pub async fn get_id<'a, E>(project_type: String, exec: E) -> Result<Option<Self>, DatabaseError>
|
||||
pub async fn get_id<'a, E>(
|
||||
project_type: String,
|
||||
exec: E,
|
||||
) -> Result<Option<Self>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
|
||||
@@ -174,9 +174,11 @@ impl Notification {
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
futures::future::try_join_all(notification_ids.into_iter().map(|id| Self::get(id, exec)))
|
||||
.await
|
||||
.map(|x| x.into_iter().flatten().collect())
|
||||
futures::future::try_join_all(
|
||||
notification_ids.into_iter().map(|id| Self::get(id, exec)),
|
||||
)
|
||||
.await
|
||||
.map(|x| x.into_iter().flatten().collect())
|
||||
}
|
||||
|
||||
pub async fn get_many_user<'a, E>(
|
||||
@@ -234,7 +236,8 @@ impl Notification {
|
||||
notification_ids: Vec<NotificationId>,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<Option<()>, sqlx::error::Error> {
|
||||
let notification_ids_parsed: Vec<i64> = notification_ids.into_iter().map(|x| x.0).collect();
|
||||
let notification_ids_parsed: Vec<i64> =
|
||||
notification_ids.into_iter().map(|x| x.0).collect();
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
|
||||
@@ -300,7 +300,8 @@ impl Project {
|
||||
{
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let project_ids_parsed: Vec<i64> = project_ids.into_iter().map(|x| x.0).collect();
|
||||
let project_ids_parsed: Vec<i64> =
|
||||
project_ids.into_iter().map(|x| x.0).collect();
|
||||
let projects = sqlx::query!(
|
||||
"
|
||||
SELECT id, project_type, title, description, downloads, follows,
|
||||
@@ -542,19 +543,24 @@ impl Project {
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
let id_option =
|
||||
crate::models::ids::base62_impl::parse_base62(&*slug_or_project_id.clone()).ok();
|
||||
let id_option = crate::models::ids::base62_impl::parse_base62(
|
||||
&*slug_or_project_id.clone(),
|
||||
)
|
||||
.ok();
|
||||
|
||||
if let Some(id) = id_option {
|
||||
let mut project = Project::get(ProjectId(id as i64), executor).await?;
|
||||
let mut project =
|
||||
Project::get(ProjectId(id as i64), executor).await?;
|
||||
|
||||
if project.is_none() {
|
||||
project = Project::get_from_slug(&slug_or_project_id, executor).await?;
|
||||
project = Project::get_from_slug(&slug_or_project_id, executor)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(project)
|
||||
} else {
|
||||
let project = Project::get_from_slug(&slug_or_project_id, executor).await?;
|
||||
let project =
|
||||
Project::get_from_slug(&slug_or_project_id, executor).await?;
|
||||
|
||||
Ok(project)
|
||||
}
|
||||
@@ -567,18 +573,25 @@ impl Project {
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
let id_option = crate::models::ids::base62_impl::parse_base62(slug_or_project_id).ok();
|
||||
let id_option =
|
||||
crate::models::ids::base62_impl::parse_base62(slug_or_project_id)
|
||||
.ok();
|
||||
|
||||
if let Some(id) = id_option {
|
||||
let mut project = Project::get_full(ProjectId(id as i64), executor).await?;
|
||||
let mut project =
|
||||
Project::get_full(ProjectId(id as i64), executor).await?;
|
||||
|
||||
if project.is_none() {
|
||||
project = Project::get_full_from_slug(slug_or_project_id, executor).await?;
|
||||
project =
|
||||
Project::get_full_from_slug(slug_or_project_id, executor)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(project)
|
||||
} else {
|
||||
let project = Project::get_full_from_slug(slug_or_project_id, executor).await?;
|
||||
let project =
|
||||
Project::get_full_from_slug(slug_or_project_id, executor)
|
||||
.await?;
|
||||
Ok(project)
|
||||
}
|
||||
}
|
||||
@@ -676,8 +689,14 @@ impl Project {
|
||||
moderation_message_body: m.moderation_message_body,
|
||||
},
|
||||
project_type: m.project_type_name,
|
||||
categories: categories?.into_iter().map(|x| x.category).collect(),
|
||||
versions: versions?.into_iter().map(|x| VersionId(x.id)).collect(),
|
||||
categories: categories?
|
||||
.into_iter()
|
||||
.map(|x| x.category)
|
||||
.collect(),
|
||||
versions: versions?
|
||||
.into_iter()
|
||||
.map(|x| VersionId(x.id))
|
||||
.collect(),
|
||||
donation_urls: donations?
|
||||
.into_iter()
|
||||
.map(|x| DonationUrl {
|
||||
@@ -699,11 +718,17 @@ impl Project {
|
||||
created: x.created,
|
||||
})
|
||||
.collect(),
|
||||
status: crate::models::projects::ProjectStatus::from_str(&m.status_name),
|
||||
status: crate::models::projects::ProjectStatus::from_str(
|
||||
&m.status_name,
|
||||
),
|
||||
license_id: m.short,
|
||||
license_name: m.license_name,
|
||||
client_side: crate::models::projects::SideType::from_str(&m.client_side_type),
|
||||
server_side: crate::models::projects::SideType::from_str(&m.server_side_type),
|
||||
client_side: crate::models::projects::SideType::from_str(
|
||||
&m.client_side_type,
|
||||
),
|
||||
server_side: crate::models::projects::SideType::from_str(
|
||||
&m.server_side_type,
|
||||
),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -717,9 +742,11 @@ impl Project {
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
futures::future::try_join_all(project_ids.into_iter().map(|id| Self::get_full(id, exec)))
|
||||
.await
|
||||
.map(|x| x.into_iter().flatten().collect())
|
||||
futures::future::try_join_all(
|
||||
project_ids.into_iter().map(|id| Self::get_full(id, exec)),
|
||||
)
|
||||
.await
|
||||
.map(|x| x.into_iter().flatten().collect())
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -52,7 +52,10 @@ impl Report {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get<'a, E>(id: ReportId, exec: E) -> Result<Option<QueryReport>, sqlx::Error>
|
||||
pub async fn get<'a, E>(
|
||||
id: ReportId,
|
||||
exec: E,
|
||||
) -> Result<Option<QueryReport>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
@@ -93,7 +96,8 @@ impl Report {
|
||||
{
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let report_ids_parsed: Vec<i64> = report_ids.into_iter().map(|x| x.0).collect();
|
||||
let report_ids_parsed: Vec<i64> =
|
||||
report_ids.into_iter().map(|x| x.0).collect();
|
||||
let reports = sqlx::query!(
|
||||
"
|
||||
SELECT r.id, rt.name, r.mod_id, r.version_id, r.user_id, r.body, r.reporter, r.created
|
||||
@@ -123,7 +127,10 @@ impl Report {
|
||||
Ok(reports)
|
||||
}
|
||||
|
||||
pub async fn remove_full<'a, E>(id: ReportId, exec: E) -> Result<Option<()>, sqlx::Error>
|
||||
pub async fn remove_full<'a, E>(
|
||||
id: ReportId,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
|
||||
@@ -32,7 +32,8 @@ impl TeamBuilder {
|
||||
.await?;
|
||||
|
||||
for member in self.members {
|
||||
let team_member_id = generate_team_member_id(&mut *transaction).await?;
|
||||
let team_member_id =
|
||||
generate_team_member_id(&mut *transaction).await?;
|
||||
let team_member = TeamMember {
|
||||
id: team_member_id,
|
||||
team_id,
|
||||
|
||||
@@ -42,7 +42,10 @@ impl User {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub async fn get<'a, 'b, E>(id: UserId, executor: E) -> Result<Option<Self>, sqlx::error::Error>
|
||||
pub async fn get<'a, 'b, E>(
|
||||
id: UserId,
|
||||
executor: E,
|
||||
) -> Result<Option<Self>, sqlx::error::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
@@ -150,13 +153,17 @@ impl User {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_many<'a, E>(user_ids: Vec<UserId>, exec: E) -> Result<Vec<User>, sqlx::Error>
|
||||
pub async fn get_many<'a, E>(
|
||||
user_ids: Vec<UserId>,
|
||||
exec: E,
|
||||
) -> Result<Vec<User>, sqlx::Error>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let user_ids_parsed: Vec<i64> = user_ids.into_iter().map(|x| x.0).collect();
|
||||
let user_ids_parsed: Vec<i64> =
|
||||
user_ids.into_iter().map(|x| x.0).collect();
|
||||
let users = sqlx::query!(
|
||||
"
|
||||
SELECT u.id, u.github_id, u.name, u.email,
|
||||
@@ -365,8 +372,11 @@ impl User {
|
||||
.await?;
|
||||
|
||||
for project_id in projects {
|
||||
let _result =
|
||||
super::project_item::Project::remove_full(project_id, transaction).await?;
|
||||
let _result = super::project_item::Project::remove_full(
|
||||
project_id,
|
||||
transaction,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let notifications: Vec<i64> = sqlx::query!(
|
||||
@@ -445,7 +455,8 @@ impl User {
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
let id_option = crate::models::ids::base62_impl::parse_base62(username_or_id).ok();
|
||||
let id_option =
|
||||
crate::models::ids::base62_impl::parse_base62(username_or_id).ok();
|
||||
|
||||
if let Some(id) = id_option {
|
||||
let id = UserId(id as i64);
|
||||
|
||||
@@ -29,11 +29,13 @@ impl DependencyBuilder {
|
||||
version_id: VersionId,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), DatabaseError> {
|
||||
let (version_dependency_id, project_dependency_id): (Option<VersionId>, Option<ProjectId>) =
|
||||
if self.version_id.is_some() {
|
||||
(self.version_id, None)
|
||||
} else if let Some(project_id) = self.project_id {
|
||||
let version_id = sqlx::query!(
|
||||
let (version_dependency_id, project_dependency_id): (
|
||||
Option<VersionId>,
|
||||
Option<ProjectId>,
|
||||
) = if self.version_id.is_some() {
|
||||
(self.version_id, None)
|
||||
} else if let Some(project_id) = self.project_id {
|
||||
let version_id = sqlx::query!(
|
||||
"
|
||||
SELECT version.id id FROM (
|
||||
SELECT DISTINCT ON(v.id) v.id, v.date_published FROM versions v
|
||||
@@ -49,10 +51,10 @@ impl DependencyBuilder {
|
||||
)
|
||||
.fetch_optional(&mut *transaction).await?.map(|x| VersionId(x.id));
|
||||
|
||||
(version_id, Some(project_id))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
(version_id, Some(project_id))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
@@ -561,7 +563,8 @@ impl Version {
|
||||
{
|
||||
use futures::stream::TryStreamExt;
|
||||
|
||||
let version_ids_parsed: Vec<i64> = version_ids.into_iter().map(|x| x.0).collect();
|
||||
let version_ids_parsed: Vec<i64> =
|
||||
version_ids.into_iter().map(|x| x.0).collect();
|
||||
let versions = sqlx::query!(
|
||||
"
|
||||
SELECT v.id, v.mod_id, v.author_id, v.name, v.version_number,
|
||||
@@ -662,7 +665,8 @@ impl Version {
|
||||
);
|
||||
|
||||
if let Some(v) = version? {
|
||||
let mut hashes_map: HashMap<FileId, HashMap<String, Vec<u8>>> = HashMap::new();
|
||||
let mut hashes_map: HashMap<FileId, HashMap<String, Vec<u8>>> =
|
||||
HashMap::new();
|
||||
|
||||
for hash in hashes? {
|
||||
let entry = hashes_map
|
||||
@@ -690,11 +694,17 @@ impl Version {
|
||||
id: FileId(x.id),
|
||||
url: x.url,
|
||||
filename: x.filename,
|
||||
hashes: hashes_map.entry(FileId(x.id)).or_default().clone(),
|
||||
hashes: hashes_map
|
||||
.entry(FileId(x.id))
|
||||
.or_default()
|
||||
.clone(),
|
||||
primary: x.is_primary,
|
||||
})
|
||||
.collect(),
|
||||
game_versions: game_versions?.into_iter().map(|x| x.game_version).collect(),
|
||||
game_versions: game_versions?
|
||||
.into_iter()
|
||||
.map(|x| x.game_version)
|
||||
.collect(),
|
||||
loaders: loaders?.into_iter().map(|x| x.loader).collect(),
|
||||
featured: v.featured,
|
||||
dependencies: dependencies?
|
||||
@@ -719,9 +729,11 @@ impl Version {
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
|
||||
{
|
||||
futures::future::try_join_all(version_ids.into_iter().map(|id| Self::get_full(id, exec)))
|
||||
.await
|
||||
.map(|x| x.into_iter().flatten().collect())
|
||||
futures::future::try_join_all(
|
||||
version_ids.into_iter().map(|id| Self::get_full(id, exec)),
|
||||
)
|
||||
.await
|
||||
.map(|x| x.into_iter().flatten().collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user