➕ New /members/single route
➕ Simple test for /members/single handler ❗ Should probably add some more tests to verify failure cases
This commit is contained in:
parent
8e6c90b3c4
commit
898a7a8ca2
@ -73,6 +73,7 @@ async fn route_dispatcher(
|
|||||||
/* MEMBERS */
|
/* MEMBERS */
|
||||||
(GET, routes::GET_ONLINE_MEMBERS) => members::get_online_members(pool, resp).await,
|
(GET, routes::GET_ONLINE_MEMBERS) => members::get_online_members(pool, resp).await,
|
||||||
(GET, routes::GET_MYSELF) => members::get_self(pool, resp, params).await,
|
(GET, routes::GET_MYSELF) => members::get_self(pool, resp, params).await,
|
||||||
|
(GET, routes::GET_MEMBER) => members::get_member(pool, resp, params).await,
|
||||||
(POST, routes::SELF_UPDATE_NICKNAME) => members::post_self_nickname(pool, resp, params).await,
|
(POST, routes::SELF_UPDATE_NICKNAME) => members::post_self_nickname(pool, resp, params).await,
|
||||||
/* OWNER */
|
/* OWNER */
|
||||||
(POST, routes::SET_NEW_ADMIN) => admin::new_admin(pool, resp, params).await,
|
(POST, routes::SET_NEW_ADMIN) => admin::new_admin(pool, resp, params).await,
|
||||||
|
@ -72,3 +72,51 @@ pub async fn post_self_nickname(p: &Pool, response: &mut Response<Body>, params:
|
|||||||
StatusCode::BAD_REQUEST
|
StatusCode::BAD_REQUEST
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_member(p: &Pool, response: &mut Response<Body>, params: HashMap<String, String>) {
|
||||||
|
let target = qs_param!(params, "member_id", u64);
|
||||||
|
|
||||||
|
*response.status_mut() = if let Some(target) = target{
|
||||||
|
match Member::get(p, target).await {
|
||||||
|
Row(member) => {
|
||||||
|
set_json_body(response, json!({"member": {
|
||||||
|
"id": member.id,
|
||||||
|
"name": member.name,
|
||||||
|
"joindate": member.joindate,
|
||||||
|
"status": member.status,
|
||||||
|
"permissions": member.permissions
|
||||||
|
}}));
|
||||||
|
StatusCode::OK
|
||||||
|
},
|
||||||
|
Empty => StatusCode::NOT_FOUND,
|
||||||
|
Other(_msg) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
_ => StatusCode::INTERNAL_SERVER_ERROR
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
StatusCode::BAD_REQUEST
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::testing::get_pool;
|
||||||
|
use crate::testing::hyper_resp;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use tokio;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn get_member_test() {
|
||||||
|
// mostly looking for correct response code here
|
||||||
|
// NOTE: we are assuming that the database we're trying against has
|
||||||
|
// some dummy data in it for us to actually look at
|
||||||
|
|
||||||
|
let p = get_pool();
|
||||||
|
let mut resp = hyper_resp();
|
||||||
|
let mut params: HashMap<String, String> = HashMap::new();
|
||||||
|
params.insert("member_id".into(), "1".into());
|
||||||
|
|
||||||
|
super::get_member(&p, &mut resp, params).await;
|
||||||
|
|
||||||
|
println!("Response: {:?}", resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ pub const MESSAGE_TIME_RANGE: Rstr = "/message/get_range"; // requires @ch
|
|||||||
pub const MESSAGE_FROM_ID: Rstr = "/message/from_id"; // requires @channel(id) requires @start(id) @<optional>limit(1..1000)
|
pub const MESSAGE_FROM_ID: Rstr = "/message/from_id"; // requires @channel(id) requires @start(id) @<optional>limit(1..1000)
|
||||||
|
|
||||||
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online"; // requires none
|
pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online"; // requires none
|
||||||
|
pub const GET_MEMBER: Rstr = "/members/single"; // requires @member_id
|
||||||
pub const GET_MYSELF: Rstr = "/members/me"; // @requires none
|
pub const GET_MYSELF: Rstr = "/members/me"; // @requires none
|
||||||
pub const SELF_UPDATE_NICKNAME: Rstr= "/members/me/nickname";
|
pub const SELF_UPDATE_NICKNAME: Rstr= "/members/me/nickname";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user