1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-09-25 22:29:45 +00:00

Start to return user information

This commit is contained in:
2020-05-25 13:25:51 +02:00
parent 97d9adcc03
commit be4d1befcc
7 changed files with 80 additions and 7 deletions

View File

@@ -0,0 +1,25 @@
//! # User controller
//!
//! This controller handles all the routes related about getting user information
//!
//! @author Pierre Hubert
use crate::controllers::routes::RequestResult;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::user_helper;
use crate::api_data::user_info::APIUserInfo;
/// Get information about a single user
pub fn get_single(request: &mut HttpRequestHandler) -> RequestResult {
let user_id = request.post_i64("userID")?;
let user = match user_helper::find_user_by_id(user_id) {
Ok(user) => user,
Err(e) => {
println!("Error while getting user info: {}", e);
request.not_found("Could not get user information!".to_string())?;
unreachable!();
}
};
request.set_response(APIUserInfo::new(user))
}