1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Can get a user id included in a POST request

This commit is contained in:
2020-05-29 18:15:24 +02:00
parent 8e2a4a8b71
commit cf2d9606d9
4 changed files with 31 additions and 1 deletions

View File

@ -12,7 +12,7 @@ use crate::data::api_client::APIClient;
use crate::data::config::conf;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper};
use crate::helpers::{account_helper, api_helper, user_helper};
/// Http request handler
///
@ -303,4 +303,19 @@ impl HttpRequestHandler {
Ok(list)
}
/// Get the ID of a user included in a POST request
pub fn post_user_id(&mut self, name: &str) -> ResultBoxError<UserID> {
let user_id = self.post_i64(name)?;
if user_id < 1 {
self.bad_request(format!("Invalid user specified in '{}'!", name))?;
}
if !user_helper::exists(user_id)? {
self.not_found(format!("User with ID {} not found!", user_id))?;
}
Ok(user_id)
}
}