diff --git a/src/api_data/movie_api.rs b/src/api_data/movie_api.rs index 4a9c544..bdaf495 100644 --- a/src/api_data/movie_api.rs +++ b/src/api_data/movie_api.rs @@ -31,4 +31,8 @@ impl MovieAPI { size: m.size, } } + + pub fn for_list(l: &Vec) -> Vec { + l.iter().map(Self::new).collect() + } } \ No newline at end of file diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs index 973489f..acf4cce 100644 --- a/src/controllers/mod.rs +++ b/src/controllers/mod.rs @@ -9,4 +9,5 @@ pub mod conversations_controller; pub mod search_controller; pub mod groups_controller; pub mod posts_controller; +pub mod movies_controller; pub mod virtual_directory_controller; \ No newline at end of file diff --git a/src/controllers/movies_controller.rs b/src/controllers/movies_controller.rs new file mode 100644 index 0000000..e5fa441 --- /dev/null +++ b/src/controllers/movies_controller.rs @@ -0,0 +1,15 @@ +//! # Movies controller +//! +//! @author Pierre Hubert + +use crate::api_data::movie_api::MovieAPI; +use crate::controllers::routes::RequestResult; +use crate::data::http_request_handler::HttpRequestHandler; +use crate::helpers::movies_helper; + +/// Get the list of movies of the current user +pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult { + let list = movies_helper::get_list_user(r.user_id_ref()?)?; + + r.set_response(MovieAPI::for_list(&list)) +} \ No newline at end of file diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index 353ed68..1c95d49 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -1,6 +1,6 @@ use std::error::Error; -use crate::controllers::{account_controller, conversations_controller, friends_controller, groups_controller, search_controller, server_controller, user_controller, virtual_directory_controller, posts_controller}; +use crate::controllers::{account_controller, conversations_controller, friends_controller, groups_controller, search_controller, server_controller, user_controller, virtual_directory_controller, posts_controller, movies_controller}; use crate::controllers::routes::Method::{GET, POST}; use crate::data::http_request_handler::HttpRequestHandler; @@ -209,6 +209,10 @@ pub fn get_routes() -> Vec { Route::post("/posts/create", Box::new(posts_controller::create_post)), + // Movies controller + Route::post("/movies/get_list", Box::new(movies_controller::get_list)), + + // Virtual directory controller Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)), diff --git a/src/helpers/movies_helper.rs b/src/helpers/movies_helper.rs index 61fd020..05f5a3e 100644 --- a/src/helpers/movies_helper.rs +++ b/src/helpers/movies_helper.rs @@ -5,8 +5,17 @@ use crate::constants::database_tables_names::MOVIES_TABLE; use crate::data::error::ResultBoxError; use crate::data::movie::Movie; +use crate::data::user::UserID; use crate::helpers::database; +/// Get the list of movies of the current +pub fn get_list_user(user_id: &UserID) -> ResultBoxError> { + database::QueryInfo::new(MOVIES_TABLE) + .cond_user_id("ID_user", user_id) + .set_order("ID DESC") + .exec(db_to_movie) +} + /// Get information about a single movie pub fn get_info(movie_id: u64) -> ResultBoxError { database::QueryInfo::new(MOVIES_TABLE)