mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-01-07 03:12:36 +00:00
27 lines
1.0 KiB
Rust
27 lines
1.0 KiB
Rust
|
//! # Surveys controller
|
||
|
//!
|
||
|
//! @author Pierre Hubert
|
||
|
|
||
|
use crate::api_data::survey_api::SurveyAPI;
|
||
|
use crate::controllers::routes::RequestResult;
|
||
|
use crate::data::error::ResultBoxError;
|
||
|
use crate::data::http_request_handler::HttpRequestHandler;
|
||
|
use crate::data::post::PostAccessLevel;
|
||
|
use crate::helpers::survey_helper;
|
||
|
|
||
|
/// Get information about a single survey
|
||
|
pub fn get_info_single(r: &mut HttpRequestHandler) -> RequestResult {
|
||
|
let post = r.post_post_with_access("postID", PostAccessLevel::BASIC_ACCESS)?;
|
||
|
let survey = r.ok_or_not_found(
|
||
|
survey_helper::get_info(post.id),
|
||
|
"This post does not seems to have any survey...",
|
||
|
)?;
|
||
|
|
||
|
r.set_response(SurveyAPI::new(&survey, r.user_id_opt())?)
|
||
|
}
|
||
|
|
||
|
/// Get the ID of a survey associated to a post whose ID was specified in the request
|
||
|
fn post_survey_id_from_post_id(r: &mut HttpRequestHandler, name: &str, min_level: PostAccessLevel) -> ResultBoxError<u64> {
|
||
|
let post = r.post_post_with_access(name, min_level)?;
|
||
|
survey_helper::get_id(post.id)
|
||
|
}
|