From 0b34c254776553400ff15105f311e104d9533510 Mon Sep 17 00:00:00 2001 From: shockrah Date: Wed, 26 May 2021 12:14:43 -0700 Subject: [PATCH] * Fixing broken /channels/create due to updated channel structure The badges_id field has proved to bubble up some issues with updating deep structures Basically this just means that feature branches for deep features like this are a good idea ! Issue: RTC feature flag was working fine but without the feature flag `Row`'s had no pickup This meant correct responses were slipping into previously unreachable sections of code --- json-api/db/src/channels.rs | 3 ++- json-api/db/src/member.rs | 2 +- json-api/run-client.sh | 3 --- json-api/src/channels.rs | 9 ++++++++- 4 files changed, 11 insertions(+), 6 deletions(-) delete mode 100644 json-api/run-client.sh diff --git a/json-api/db/src/channels.rs b/json-api/db/src/channels.rs index 86fc362..973d3d8 100644 --- a/json-api/db/src/channels.rs +++ b/json-api/db/src/channels.rs @@ -47,7 +47,6 @@ impl Channel { let params = params!{"kind" => kind}; type Row = (u64, String, Option, i32, String); let channels = conn.exec_map(q, params, |(id, name, description, kind, badge_ids): Row| { - println!("{}", badge_ids); let badge_ids: Vec = serde_json::from_str(&badge_ids).unwrap_or(Vec::new()); Channel { id, name, description, kind, badge_ids @@ -68,6 +67,8 @@ impl Channel { // bounds are literally [1, 2] if kind == TEXT_CHANNEL || kind == VOICE_CHANNEL { let mut conn = p.get_conn().await?; + // Badge id's are not required here as they have a default server-side + // value of '[]' let q = "INSERT INTO channels (id, name, description, kind) VALUES (:i, :n, :d, :k)"; let id = rand::rngs::OsRng.next_u64(); // generate id's randomly for channels conn.exec_drop(q, params!{ diff --git a/json-api/db/src/member.rs b/json-api/db/src/member.rs index a98d36b..b769b60 100644 --- a/json-api/db/src/member.rs +++ b/json-api/db/src/member.rs @@ -108,7 +108,7 @@ impl PublicMember { return Ok(Response::RestrictedInput(format!("Invalid status value"))); } else { let mut conn = p.get_conn().await?; - let q = "SELECT id, name, permissions badge_ids FROM members + let q = "SELECT id, name, permissions, badge_ids FROM members WHERE status = :status LIMIT 1000"; let params = params!{"status" => status}; diff --git a/json-api/run-client.sh b/json-api/run-client.sh deleted file mode 100644 index 0c1d626..0000000 --- a/json-api/run-client.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -source ./client-tests/bin/activate -python3 client-tests/main.py diff --git a/json-api/src/channels.rs b/json-api/src/channels.rs index c85d71a..3f30c40 100644 --- a/json-api/src/channels.rs +++ b/json-api/src/channels.rs @@ -62,8 +62,15 @@ pub async fn create_channel(pool: &Pool, response: &mut Response, params: rtc::create_channel(channel).await; StatusCode::OK }, + #[cfg(not(feature = "rtc"))] + Row(_) => { StatusCode::OK }, + RestrictedInput(_) => StatusCode::UNPROCESSABLE_ENTITY, - _ => StatusCode::INTERNAL_SERVER_ERROR + // Unreachable + _ => { + eprintln!("[HTTP] /channels/create Couldn't fetch response variant"); + StatusCode::INTERNAL_SERVER_ERROR + } } }, Err(e) => {