This commit is contained in:
Benjamin Sherriff
2023-10-05 09:07:53 -04:00
parent ac17be838a
commit 1b41849115
54 changed files with 6473 additions and 129 deletions

View File

@@ -73,7 +73,7 @@ async fn get_all(req: HttpRequest) -> HttpResponse {
None => None
};
// Limit must be between 1 and 100
let limit = std::cmp::min(std::cmp::max(params.limit.unwrap_or(20), 1), 100);
let limit = std::cmp::min(std::cmp::max(params.limit.unwrap_or(100), 1), 100);
let total_count = QuerySpell::get_count(&filters).unwrap();
let max_page = std::cmp::max((total_count as f64 / limit as f64).ceil() as i32, 1);
// Page must be between 1 and max_page
@@ -82,8 +82,11 @@ async fn get_all(req: HttpRequest) -> HttpResponse {
match web::block(move || QuerySpell::get_all(&filters, limit, page)).await.unwrap() {
Ok(spells) => {
let mut response: Vec<Spell> = Vec::new();
for spell in spells {
response.push(Spell::from(spell));
for query_spell in spells {
let id = query_spell.id;
let mut spell = Spell::from(query_spell);
spell.id = Some(id);
response.push(spell);
}
HttpResponse::Ok().json(GetResponse {
data: response,
@@ -112,10 +115,15 @@ async fn get_by_id(id: web::Path<String>) -> HttpResponse {
})
};
match web::block(move || QuerySpell::get_by_id(id)).await.unwrap() {
Ok(spell) => HttpResponse::Ok().json(GetResponse {
data: Spell::from(spell),
metadata: None
}),
Ok(query_spell) => {
let id = query_spell.id;
let mut spell = Spell::from(query_spell);
spell.id = Some(id);
HttpResponse::Ok().json(GetResponse {
data: spell,
metadata: None
})
},
Err(err) => {
error!("{:?}", err.message);
ResponseError::error_response(&err)