From 151b69451fa28ae411e4668b74923f47ee4e74a9 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 10 Jul 2020 10:53:37 +0200 Subject: [PATCH] Can get information about a single survey --- src/controllers/mod.rs | 3 ++- src/controllers/routes.rs | 5 ++++- src/controllers/surveys_controller.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/controllers/surveys_controller.rs diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs index 30ff232..37bc7d1 100644 --- a/src/controllers/mod.rs +++ b/src/controllers/mod.rs @@ -11,5 +11,6 @@ pub mod groups_controller; pub mod posts_controller; pub mod comments_controller; pub mod likes_controller; +pub mod surveys_controller; pub mod movies_controller; -pub mod virtual_directory_controller; \ No newline at end of file +pub mod virtual_directory_controller; diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index f2ee9ee..2aa377d 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -1,6 +1,6 @@ use std::error::Error; -use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, posts_controller, search_controller, server_controller, user_controller, virtual_directory_controller}; +use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, posts_controller, search_controller, server_controller, surveys_controller, user_controller, virtual_directory_controller}; use crate::controllers::routes::Method::{GET, POST}; use crate::data::http_request_handler::HttpRequestHandler; @@ -231,6 +231,9 @@ pub fn get_routes() -> Vec { // Likes controller Route::post("/likes/update", Box::new(likes_controller::update)), + // Surveys controller + Route::post("/surveys/get_info", Box::new(surveys_controller::get_info_single)), + // Movies controller Route::post("/movies/get_list", Box::new(movies_controller::get_list)), diff --git a/src/controllers/surveys_controller.rs b/src/controllers/surveys_controller.rs new file mode 100644 index 0000000..8cd54cc --- /dev/null +++ b/src/controllers/surveys_controller.rs @@ -0,0 +1,27 @@ +//! # 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 { + let post = r.post_post_with_access(name, min_level)?; + survey_helper::get_id(post.id) +} \ No newline at end of file