You've already forked AstralRinth
forked from didirus/AstralRinth
Move to SPDX licenses (#449)
* Move to SPDX licenses Found a way to do this without breaking API compat, so here it is, instead of waiting for v3 Resolves MOD-129 Resolves #396 * License URL updates * what was I thinking * Do a thing * Add open source filter * Remove dead imports * Borrow * Update 20220910132835_spdx-licenses.sql * Add license text route * Update migration * Address comments
This commit is contained in:
@@ -38,12 +38,6 @@ pub struct ReportType {
|
||||
pub report_type: String,
|
||||
}
|
||||
|
||||
pub struct License {
|
||||
pub id: LicenseId,
|
||||
pub short: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub struct DonationPlatform {
|
||||
pub id: DonationPlatformId,
|
||||
pub short: String,
|
||||
@@ -685,157 +679,6 @@ impl<'a> GameVersionBuilder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LicenseBuilder<'a> {
|
||||
pub short: Option<&'a str>,
|
||||
pub name: Option<&'a str>,
|
||||
}
|
||||
|
||||
impl License {
|
||||
pub fn builder() -> LicenseBuilder<'static> {
|
||||
LicenseBuilder::default()
|
||||
}
|
||||
|
||||
pub async fn get_id<'a, E>(
|
||||
id: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<LicenseId>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT id FROM licenses
|
||||
WHERE short = $1
|
||||
",
|
||||
id
|
||||
)
|
||||
.fetch_optional(exec)
|
||||
.await?;
|
||||
|
||||
Ok(result.map(|r| LicenseId(r.id)))
|
||||
}
|
||||
|
||||
pub async fn get<'a, E>(
|
||||
id: LicenseId,
|
||||
exec: E,
|
||||
) -> Result<License, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT short, name FROM licenses
|
||||
WHERE id = $1
|
||||
",
|
||||
id as LicenseId
|
||||
)
|
||||
.fetch_one(exec)
|
||||
.await?;
|
||||
|
||||
Ok(License {
|
||||
id,
|
||||
short: result.short,
|
||||
name: result.name,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn list<'a, E>(exec: E) -> Result<Vec<License>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT id, short, name FROM licenses
|
||||
"
|
||||
)
|
||||
.fetch_many(exec)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|c| License {
|
||||
id: LicenseId(c.id),
|
||||
short: c.short,
|
||||
name: c.name,
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<License>>()
|
||||
.await?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn remove<'a, E>(
|
||||
short: &str,
|
||||
exec: E,
|
||||
) -> Result<Option<()>, DatabaseError>
|
||||
where
|
||||
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
DELETE FROM licenses
|
||||
WHERE short = $1
|
||||
",
|
||||
short
|
||||
)
|
||||
.execute(exec)
|
||||
.await?;
|
||||
|
||||
if result.rows_affected() == 0 {
|
||||
// Nothing was deleted
|
||||
Ok(None)
|
||||
} else {
|
||||
Ok(Some(()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
Ok(Self {
|
||||
short: Some(short),
|
||||
..self
|
||||
})
|
||||
}
|
||||
|
||||
/// The license's long name
|
||||
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>
|
||||
where
|
||||
E: sqlx::Executor<'b, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
INSERT INTO licenses (short, name)
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (short) DO NOTHING
|
||||
RETURNING id
|
||||
",
|
||||
self.short,
|
||||
self.name,
|
||||
)
|
||||
.fetch_one(exec)
|
||||
.await?;
|
||||
|
||||
Ok(LicenseId(result.id))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DonationPlatformBuilder<'a> {
|
||||
pub short: Option<&'a str>,
|
||||
|
||||
Reference in New Issue
Block a user