From 5e48fa1ab93760ddc7cb5b2b2926e0b355c26388 Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 17 Sep 2020 19:40:54 -0700 Subject: [PATCH] update method now written should build fine --- server-api/db/src/channels.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server-api/db/src/channels.rs b/server-api/db/src/channels.rs index 260d9ad..f0a8673 100644 --- a/server-api/db/src/channels.rs +++ b/server-api/db/src/channels.rs @@ -6,7 +6,7 @@ use async_trait::async_trait; use crate::{VarChar, UBigInt, Integer}; use crate::common::FromDB; -use crate::{no_conn, Response}; +use crate::{sql_err, no_conn, Response}; #[allow(dead_code)] pub struct Channel { @@ -23,7 +23,7 @@ impl FromDB for Channel { async fn get(p: &Pool, id: UBigInt) -> Response { if let Ok(conn) = p.get_conn().await { - let q = "SELECT id, name, description, kind WHERE id = :id"; + let q = "SELECT id, name, description, kind FROM channels WHERE id = :id"; let result: Result<(Conn, Self::Row), SqlError> = conn.first_exec(q, params!{"id" => id}).await; if let Ok((_, row)) = result { @@ -44,7 +44,23 @@ impl FromDB for Channel { } async fn update(p: &Pool, row: Self) -> Response { - unimplemented!() + if let Ok(conn) = p.get_conn().await { + let q = "UPDATE channels + SET name = :name, description = :desc, kind = :kind + WHERE id = :id"; + let result: Result = + conn.drop_exec(q, params!{ + "id" => row.id, + "name" => row.name, + "desc" => row.description, + "kind" => row.kind + }).await; + return match result { + Ok(_) => Response::Success, + Err(_) => Response::Other(sql_err!("Invite::FromDB::update Update failed")) + } + } + return Response::Other(no_conn!("Invite::FromDB::get connection failed")); } async fn delete(p: &Pool, id: UBigInt) -> Response {