Lots of little fixes (#73)

* Lots of little fixes

* Change + Add TODOs back that were incomplete

* Fix migrations

* Run prepare

* Minor fixes

* Fix formatting

* SQLX Prepare
This commit is contained in:
Geometrically
2020-10-14 13:19:38 -07:00
committed by GitHub
parent 1072d1306b
commit ad29f2477e
13 changed files with 513 additions and 174 deletions

View File

@@ -36,15 +36,29 @@ pub async fn mods_get(
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?;
let mods: Vec<models::mods::Mod> = mods_data
.into_iter()
.map(|m| models::mods::Mod {
let mut mods: Vec<models::mods::Mod> = Vec::new();
for m in mods_data {
let status = sqlx::query!(
"
SELECT status FROM statuses
WHERE id = $1
",
m.status.0,
)
.fetch_one(&**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?
.status;
mods.push(models::mods::Mod {
id: m.id.into(),
team: m.team_id.into(),
title: m.title,
description: m.description,
body_url: m.body_url,
published: m.published,
updated: m.updated,
status: models::mods::ModStatus::from_str(&*status),
downloads: m.downloads as u32,
categories: vec![],
@@ -54,7 +68,7 @@ pub async fn mods_get(
source_url: m.source_url,
wiki_url: m.wiki_url,
})
.collect();
}
Ok(HttpResponse::Ok().json(mods))
}
@@ -71,6 +85,19 @@ pub async fn mod_get(
if let Some(data) = mod_data {
let m = data.inner;
let status = sqlx::query!(
"
SELECT status FROM statuses
WHERE id = $1
",
m.status.0,
)
.fetch_one(&**pool)
.await
.map_err(|e| ApiError::DatabaseError(e.into()))?
.status;
let response = models::mods::Mod {
id: m.id.into(),
team: m.team_id.into(),
@@ -78,6 +105,8 @@ pub async fn mod_get(
description: m.description,
body_url: m.body_url,
published: m.published,
updated: m.updated,
status: models::mods::ModStatus::from_str(&*status),
downloads: m.downloads as u32,
categories: data.categories,