1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#[cfg(feature = "commands")]
pub mod details;
#[cfg(feature = "commands")]
pub mod search;
#[cfg(feature = "commands")]
pub mod similar;
use crate::common::country::Country;
use crate::common::language::Language;
use crate::common::status::Status;
use crate::company::CompanyShort;
use crate::genre::Genre;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct MovieBase {
pub id: u64,
pub title: String,
pub original_title: String,
pub original_language: String,
pub overview: String,
#[serde(default, with = "crate::util::optional_date")]
pub release_date: Option<chrono::NaiveDate>,
pub poster_path: Option<String>,
pub backdrop_path: Option<String>,
pub adult: bool,
pub popularity: f64,
pub vote_count: u64,
pub vote_average: f64,
pub video: bool,
}
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct MovieShort {
#[serde(flatten)]
pub inner: MovieBase,
pub genre_ids: Vec<u64>,
}
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Movie {
#[serde(flatten)]
pub inner: MovieBase,
pub budget: u64,
pub genres: Vec<Genre>,
#[serde(deserialize_with = "crate::util::empty_string::deserialize")]
pub homepage: Option<String>,
pub imdb_id: Option<String>,
pub production_companies: Vec<CompanyShort>,
pub production_countries: Vec<Country>,
pub revenue: u64,
pub runtime: Option<u64>,
pub spoken_languages: Vec<Language>,
pub status: Status,
pub tagline: Option<String>,
}
#[cfg(test)]
mod tests {
#[test]
fn serialize() {
let origin = include_str!("../../assets/movie-details-success.json");
let movie: super::Movie = serde_json::from_str(origin).unwrap();
let serial = serde_json::to_string_pretty(&movie).unwrap();
println!("serial: {}", serial);
let expected: super::Movie = serde_json::from_str(&serial).unwrap();
assert_eq!(movie, expected);
}
}