1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-02-08 02:07:04 +00:00
comunicapiv3/src/helpers/movies_helper.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

2020-07-03 16:41:14 +02:00
//! # Movies helper
//!
//! @author Pierre Hubert
use crate::constants::database_tables_names::MOVIES_TABLE;
use crate::data::error::ResultBoxError;
use crate::data::movie::Movie;
use crate::data::user::UserID;
2020-07-03 16:41:14 +02:00
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)
}
2020-07-03 16:41:14 +02:00
/// Get information about a single movie
pub fn get_info(movie_id: u64) -> ResultBoxError<Movie> {
database::QueryInfo::new(MOVIES_TABLE)
.cond_u64("ID", movie_id)
.query_row(db_to_movie)
}
/// Turn a database entry into a movie object
fn db_to_movie(row: &database::RowResult) -> ResultBoxError<Movie> {
Ok(Movie {
id: row.get_u64("ID")?,
user_id: row.get_user_id("ID_user")?,
name: row.get_str("nom_video")?,
uri: row.get_str("URL")?,
file_type: row.get_str("file_type")?,
size: row.get_usize("size")?,
})
}