added delete method for members
This commit is contained in:
parent
49344b5aae
commit
fb0df20715
@ -22,4 +22,6 @@ pub trait FromDB<T> {
|
|||||||
async fn get(p: &Pool, id: UBigInt) -> Response<T>;
|
async fn get(p: &Pool, id: UBigInt) -> Response<T>;
|
||||||
|
|
||||||
async fn update(p: &Pool, row: T) -> Response<T>;
|
async fn update(p: &Pool, row: T) -> Response<T>;
|
||||||
|
|
||||||
|
async fn delete(p: &Pool, id: UBigInt) -> Response<T>;
|
||||||
}
|
}
|
||||||
|
@ -83,4 +83,27 @@ impl FromDB<Member> for Member {
|
|||||||
}
|
}
|
||||||
return Response::Other(NO_CONN_MSG);
|
return Response::Other(NO_CONN_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn delete(p: &Pool, id: UBigInt) -> Response<Self> {
|
||||||
|
if let Ok(conn) = p.get_conn().await {
|
||||||
|
let q = "DELETE from members WHERE id = :id";
|
||||||
|
let db_result: Result<Conn, SqlError>
|
||||||
|
= conn.drop_exec(q, params!{"id" => id}).await;
|
||||||
|
match Member::get(p, id).await {
|
||||||
|
Response::Row(_) => {
|
||||||
|
if let Ok(conn) = db_result {
|
||||||
|
return match conn.prep_exec("", params!{"id" => id}).await {
|
||||||
|
Ok(_) => Response::Success,
|
||||||
|
Err(_) => Response::Other("Could not delete entry")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Response::Success
|
||||||
|
},
|
||||||
|
Response::Empty => return Response::Empty,
|
||||||
|
_ => return Response::Other("Query failed in Member::delete")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response::Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user