Implement more database methods and basic API routes (#50)

* feat: Implement more database methods & add mod and version routes

* feat: Implement deleting mods/versions & implement categories

* feat: Implement routes for categories, game versions & loaders

* feat: Reorganize API routes in a (hopefully) usable way
This commit is contained in:
Aeledfyr
2020-08-12 14:54:03 -05:00
committed by GitHub
parent e2bf474332
commit 781f0c843e
20 changed files with 2146 additions and 125 deletions

View File

@@ -142,7 +142,7 @@ pub async fn index_curseforge(
}
}
if mod_categories.contains(&"fabric".to_owned()) {
if mod_categories.iter().any(|e| e == "fabric") {
using_fabric = true;
}
@@ -154,7 +154,8 @@ pub async fn index_curseforge(
mod_categories.push(String::from("forge"));
}
if using_fabric {
mod_categories.push(String::from("fabric"));
// The only way this could happen is if "fabric" is already a category
// mod_categories.push(String::from("fabric"));
}
let mut mod_attachments = curseforge_mod.attachments;

View File

@@ -34,7 +34,22 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchMod>, IndexingE
.try_collect::<Vec<String>>()
.await?;
let categories = sqlx::query!(
// TODO: only loaders for recent versions? For mods that have moved from forge to fabric
let loaders: Vec<String> = sqlx::query!(
"
SELECT loaders.loader FROM versions
INNER JOIN loaders_versions lv ON lv.version_id = versions.id
INNER JOIN loaders ON loaders.id = lv.loader_id
WHERE versions.mod_id = $1
",
result.id
)
.fetch_many(&pool)
.try_filter_map(|e| async { Ok(e.right().map(|c| c.loader)) })
.try_collect::<Vec<String>>()
.await?;
let mut categories = sqlx::query!(
"
SELECT c.category
FROM mods_categories mc
@@ -48,6 +63,8 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchMod>, IndexingE
.try_collect::<Vec<String>>()
.await?;
categories.extend(loaders);
let mut icon_url = "".to_string();
if let Some(url) = result.icon_url {