You've already forked AstralRinth
forked from didirus/AstralRinth
* WIP Switch to Postgres * feat(postgres): more work on porting to postgres, now compiles * feat(docker-compose): Changed the docker-compose.yml file to use postgres. * Update docker, documentation, gh actions... * Remove bson dependency * Remove bson import * feat: move mock filehost to trait rather than cargo feature * feat(postgres): transactions for mod creation, multipart refactor * fix: Add Cargo.lock so that sqlx functions * Update sqlx offline build data * fix: Use SQLX_OFFLINE to force sqlx into offline mode for CI * Default release channels * feat(postgres): refactor database models to fit postgres models * fix: Fix sqlx prepare, fix double allocation in indexing * Add dockerfile (#40) Co-authored-by: Charalampos Fanoulis <charalampos.fanoulis@gmail.com> Co-authored-by: Aeledfyr <aeledfyr@gmail.com> Co-authored-by: redblueflame <contact@redblueflame.com> Co-authored-by: Jai A <jai.a@tuta.io> Co-authored-by: Valentin Ricard <redblueflame1@gmail.Com> Co-authored-by: Charalampos Fanoulis <charalampos.fanoulis@gmail.com>
109 lines
2.9 KiB
Rust
109 lines
2.9 KiB
Rust
use super::ids::*;
|
|
|
|
pub struct ModBuilder {
|
|
pub mod_id: ModId,
|
|
pub team_id: TeamId,
|
|
pub title: String,
|
|
pub description: String,
|
|
pub body_url: String,
|
|
pub icon_url: Option<String>,
|
|
pub issues_url: Option<String>,
|
|
pub source_url: Option<String>,
|
|
pub wiki_url: Option<String>,
|
|
pub categories: Vec<CategoryId>,
|
|
pub initial_versions: Vec<super::version_item::VersionBuilder>,
|
|
}
|
|
|
|
impl ModBuilder {
|
|
pub async fn insert(
|
|
self,
|
|
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
|
) -> Result<ModId, super::DatabaseError> {
|
|
let mod_struct = Mod {
|
|
id: self.mod_id,
|
|
team_id: self.team_id,
|
|
title: self.title,
|
|
description: self.description,
|
|
body_url: self.body_url,
|
|
published: chrono::Utc::now(),
|
|
downloads: 0,
|
|
icon_url: self.icon_url,
|
|
issues_url: self.issues_url,
|
|
source_url: self.source_url,
|
|
wiki_url: self.wiki_url,
|
|
};
|
|
mod_struct.insert(&mut *transaction).await?;
|
|
|
|
for mut version in self.initial_versions {
|
|
version.mod_id = self.mod_id;
|
|
version.insert(&mut *transaction).await?;
|
|
}
|
|
|
|
for category in self.categories {
|
|
sqlx::query(
|
|
"
|
|
INSERT INTO mod_categories (joining_mod_id, joining_category_id)
|
|
VALUES ($1, $2)
|
|
",
|
|
)
|
|
.bind(self.mod_id)
|
|
.bind(category)
|
|
.execute(&mut *transaction)
|
|
.await?;
|
|
}
|
|
|
|
Ok(self.mod_id)
|
|
}
|
|
}
|
|
|
|
pub struct Mod {
|
|
pub id: ModId,
|
|
pub team_id: TeamId,
|
|
pub title: String,
|
|
pub description: String,
|
|
pub body_url: String,
|
|
pub published: chrono::DateTime<chrono::Utc>,
|
|
pub downloads: i32,
|
|
pub icon_url: Option<String>,
|
|
pub issues_url: Option<String>,
|
|
pub source_url: Option<String>,
|
|
pub wiki_url: Option<String>,
|
|
}
|
|
|
|
impl Mod {
|
|
pub async fn insert(
|
|
&self,
|
|
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
|
) -> Result<(), sqlx::error::Error> {
|
|
sqlx::query(
|
|
"
|
|
INSERT INTO mods (
|
|
id, team_id, title, description, body_url,
|
|
published, downloads, icon_url, issues_url,
|
|
source_url, wiki_url
|
|
)
|
|
VALUES (
|
|
$1, $2, $3, $4, $5,
|
|
$6, $7, $8, $9,
|
|
$10, $11
|
|
)
|
|
",
|
|
)
|
|
.bind(self.id)
|
|
.bind(self.team_id)
|
|
.bind(&self.title)
|
|
.bind(&self.description)
|
|
.bind(&self.body_url)
|
|
.bind(self.published)
|
|
.bind(self.downloads)
|
|
.bind(self.icon_url.as_ref())
|
|
.bind(self.issues_url.as_ref())
|
|
.bind(self.source_url.as_ref())
|
|
.bind(self.wiki_url.as_ref())
|
|
.execute(&mut *transaction)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
}
|