2020-07-02 16:19:04 +00:00
|
|
|
//! # Posts controller
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
|
|
|
use crate::api_data::post_api::PostAPI;
|
|
|
|
use crate::controllers::routes::RequestResult;
|
2020-07-06 07:20:31 +00:00
|
|
|
use crate::data::group::GroupAccessLevel;
|
2020-07-02 16:19:04 +00:00
|
|
|
use crate::data::http_request_handler::HttpRequestHandler;
|
|
|
|
use crate::helpers::{posts_helper, user_helper};
|
|
|
|
|
|
|
|
/// Get the list of posts of a user
|
|
|
|
pub fn get_list_user(r: &mut HttpRequestHandler) -> RequestResult {
|
|
|
|
let user_id = r.post_user_id("userID")?;
|
|
|
|
let start_from = r.post_u64_opt("startFrom", 0)?;
|
|
|
|
|
|
|
|
if !user_helper::can_see_user_page(r.user_id_ref()?, &user_id)? {
|
|
|
|
r.forbidden("You are not allowed to access this user posts !".to_string())?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let posts = posts_helper::PostsQuery::new(r.user_id_opt())
|
|
|
|
.set_start_from(start_from)
|
|
|
|
.get_user(&user_id)?;
|
|
|
|
|
2020-07-06 07:20:31 +00:00
|
|
|
r.set_response(PostAPI::for_list(&posts, r.user_id_opt())?)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the list of posts of a group
|
|
|
|
pub fn get_list_group(r: &mut HttpRequestHandler) -> RequestResult {
|
|
|
|
let group_id = r.post_group_id_with_access("groupID", GroupAccessLevel::VIEW_ACCESS)?;
|
|
|
|
let start_from = r.post_u64_opt("startFrom", 0)?;
|
|
|
|
|
|
|
|
let posts = posts_helper::PostsQuery::new(r.user_id_opt())
|
|
|
|
.set_start_from(start_from)
|
|
|
|
.get_group(&group_id)?;
|
|
|
|
|
2020-07-04 14:44:42 +00:00
|
|
|
r.set_response(PostAPI::for_list(&posts, r.user_id_opt())?)
|
2020-07-02 16:19:04 +00:00
|
|
|
}
|