2020-07-03 14:41:14 +00:00
|
|
|
//! # Movie API information
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use crate::data::movie::Movie;
|
|
|
|
use crate::utils::user_data_utils::user_data_url;
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
pub struct MovieAPI {
|
|
|
|
id: u64,
|
|
|
|
uri: String,
|
|
|
|
url: String,
|
|
|
|
userID: u64,
|
|
|
|
name: String,
|
|
|
|
file_type: String,
|
|
|
|
size: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MovieAPI {
|
|
|
|
/// Construct a new instance of movie
|
|
|
|
pub fn new(m: &Movie) -> MovieAPI {
|
|
|
|
MovieAPI {
|
|
|
|
id: m.id,
|
|
|
|
uri: m.uri.clone(),
|
|
|
|
url: user_data_url(m.uri.as_str()),
|
|
|
|
userID: m.user_id.id(),
|
|
|
|
name: m.name.clone(),
|
|
|
|
file_type: m.file_type.clone(),
|
|
|
|
size: m.size,
|
|
|
|
}
|
|
|
|
}
|
2020-07-08 11:45:01 +00:00
|
|
|
|
|
|
|
pub fn for_list(l: &Vec<Movie>) -> Vec<MovieAPI> {
|
|
|
|
l.iter().map(Self::new).collect()
|
|
|
|
}
|
2020-07-03 14:41:14 +00:00
|
|
|
}
|