Refactor mod creation route, add more checks (#80)

This also removes the `team_members` field of `InitialModData`, as
team members are no longer specified at mod creation.
This commit is contained in:
Aeledfyr
2020-10-17 21:34:23 -05:00
committed by GitHub
parent 520b12e56b
commit d0fb5c3bd5
6 changed files with 730 additions and 362 deletions

View File

@@ -88,7 +88,7 @@ generate_ids!(
UserId
);
#[derive(Copy, Clone, Debug, Type)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Type)]
#[sqlx(transparent)]
pub struct UserId(pub i64);

View File

@@ -31,3 +31,47 @@ pub enum DatabaseError {
)]
InvalidIdentifier(String),
}
impl ids::ChannelId {
pub async fn get_id<'a, E>(
channel: &str,
exec: E,
) -> Result<Option<ids::ChannelId>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let result = sqlx::query!(
"
SELECT id FROM release_channels
WHERE channel = $1
",
channel
)
.fetch_optional(exec)
.await?;
Ok(result.map(|r| ids::ChannelId(r.id)))
}
}
impl ids::StatusId {
pub async fn get_id<'a, E>(
status: &crate::models::mods::ModStatus,
exec: E,
) -> Result<Option<Self>, DatabaseError>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres>,
{
let result = sqlx::query!(
"
SELECT id FROM statuses
WHERE status = $1
",
status.as_str()
)
.fetch_optional(exec)
.await?;
Ok(result.map(|r| ids::StatusId(r.id)))
}
}