1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 07:19:22 +00:00

Can get the list of movies of current user

This commit is contained in:
Pierre HUBERT 2020-07-08 13:45:01 +02:00
parent df1e2ffd7b
commit 32628af376
5 changed files with 34 additions and 1 deletions

View File

@ -31,4 +31,8 @@ impl MovieAPI {
size: m.size,
}
}
pub fn for_list(l: &Vec<Movie>) -> Vec<MovieAPI> {
l.iter().map(Self::new).collect()
}
}

View File

@ -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;

View File

@ -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))
}

View File

@ -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> {
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)),

View File

@ -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<Vec<Movie>> {
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<Movie> {
database::QueryInfo::new(MOVIES_TABLE)