mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-02-08 02:07:04 +00:00
27 lines
798 B
Rust
27 lines
798 B
Rust
|
//! # 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::helpers::database;
|
||
|
|
||
|
/// 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")?,
|
||
|
})
|
||
|
}
|