-* Removing ugle tuple indexing with some cleaner binds

- Removing warning of unused var
+ Adding 404 response to /badge/update/name when the badge_id isn't real
This commit is contained in:
shockrah 2021-06-07 23:55:12 -07:00
parent b289f5c811
commit 0e607eac1d
2 changed files with 8 additions and 7 deletions

View File

@ -37,12 +37,12 @@ async fn get(pool: &Pool, id: u64) -> SqlResult<Option<Badge>> {
let q = "SELECT name, color, permissions FROM badges WHERE id = :id";
let row: Option<(String, u32, u64)> = conn.exec_first(q, params!{ "id" => id}).await?;
match row {
Some(row) => {
Some((name, color, perms)) => {
let b = Badge {
id,
name: row.0,
color: row.1,
perms: row.2,
name,
color,
perms
};
Ok(Some(b))
},

View File

@ -100,7 +100,9 @@ pub async fn update_name(p: &Pool, response: &mut Response<Body>, params: HashMa
set_json_body(response, json!({"badge-update": payload}));
}
},
Ok(false) => {},
Ok(false) => {
*response.status_mut() = StatusCode::NOT_FOUND;
},
Err(e) => {
eprintln!("[HTTP][ERROR] /badges/update/name {}", e);
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
@ -115,9 +117,8 @@ pub async fn update_name(p: &Pool, response: &mut Response<Body>, params: HashMa
pub async fn delete(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
if let Some(id) = qs_param!(params, "badge_id", u64) {
match db::badges::delete(p, id).await {
Ok(id) => {
Ok(_id) => {
// TODO: add rtc notification here
println!("TODO remove me at some point {}", id);
},
Err(e) => {
eprintln!("[HTTP][ERROR] /badge/delete {}", e);