-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
211 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod auth_tokens; | ||
pub mod developers; | ||
pub mod mod_downloads; | ||
pub mod mod_gd_versions; | ||
pub mod mod_tags; | ||
pub mod mod_versions; | ||
pub mod mods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::types::api::ApiError; | ||
use crate::types::models::mod_gd_version::{GDVersionEnum, ModGDVersionCreate, VerPlatform}; | ||
use sqlx::{PgConnection, Postgres, QueryBuilder}; | ||
|
||
pub async fn create_from_json( | ||
json: &[ModGDVersionCreate], | ||
mod_version_id: i32, | ||
conn: &mut PgConnection, | ||
) -> Result<(), ApiError> { | ||
if json.is_empty() { | ||
return Err(ApiError::BadRequest( | ||
"mod.json has no gd versions added".into(), | ||
)); | ||
} | ||
|
||
let mut builder: QueryBuilder<Postgres> = | ||
QueryBuilder::new("INSERT INTO mod_gd_versions (gd, platform, mod_id) VALUES "); | ||
|
||
for (i, current) in json.iter().enumerate() { | ||
builder.push("("); | ||
let mut separated = builder.separated(", "); | ||
separated.push_bind(current.gd as GDVersionEnum); | ||
separated.push_bind(current.platform as VerPlatform); | ||
separated.push_bind(mod_version_id); | ||
separated.push_unseparated(")"); | ||
if i != json.len() - 1 { | ||
separated.push_unseparated(", "); | ||
} | ||
} | ||
|
||
builder.build().execute(conn).await.map_err(|e| { | ||
log::error!("Failed to insert mod_gd_versions: {}", e); | ||
ApiError::DbError | ||
})?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters