16#include <nlohmann/json.hpp>
32 std::string plotShort;
34 std::vector<std::string> actors;
35 std::vector<std::string> genres;
36 int runtimeMinutes = 0;
37 std::vector<std::string> countries;
38 std::string posterUrl;
40 double imdbRating = 0.0;
42 int rottenTomatoes = 0;
47 double userScore = 1500.0;
57inline void to_json(nlohmann::json& j,
const Movie& m) {
58 j = nlohmann::json{{
"title", m.title}, {
"year", m.year}, {
"director", m.director}};
59 if (!m.plotShort.empty()) j[
"plotShort"] = m.plotShort;
60 if (!m.plotFull.empty()) j[
"plotFull"] = m.plotFull;
61 if (!m.actors.empty()) j[
"actors"] = m.actors;
62 if (!m.genres.empty()) j[
"genres"] = m.genres;
63 if (m.runtimeMinutes > 0) j[
"runtimeMinutes"] = m.runtimeMinutes;
64 if (!m.countries.empty()) j[
"countries"] = m.countries;
65 if (!m.posterUrl.empty()) j[
"posterUrl"] = m.posterUrl;
66 if (m.imdbRating > 0.0) j[
"imdbRating"] = m.imdbRating;
67 if (m.metascore > 0) j[
"metascore"] = m.metascore;
68 if (m.rottenTomatoes > 0) j[
"rottenTomatoes"] = m.rottenTomatoes;
69 if (!m.source.empty()) j[
"source"] = m.source;
70 if (!m.imdbID.empty()) j[
"imdbID"] = m.imdbID;
72 j[
"userScore"] = m.userScore;
73 j[
"userRank"] = m.userRank;
82inline void from_json(
const nlohmann::json& j,
Movie& m) {
84 if (j.contains(
"title")) j.at(
"title").get_to(m.title);
else m.title =
"";
85 if (j.contains(
"year")) j.at(
"year").get_to(m.year);
else m.year = 0;
86 if (j.contains(
"director")) j.at(
"director").get_to(m.director);
else m.director =
"";
89 m.plotShort = j.value(
"plotShort", std::string());
90 m.plotFull = j.value(
"plotFull", std::string());
91 if (j.contains(
"actors")) j.at(
"actors").get_to(m.actors);
else m.actors.clear();
92 if (j.contains(
"genres")) j.at(
"genres").get_to(m.genres);
else m.genres.clear();
93 m.runtimeMinutes = j.value(
"runtimeMinutes", 0);
94 if (j.contains(
"countries")) j.at(
"countries").get_to(m.countries);
else m.countries.clear();
95 m.posterUrl = j.value(
"posterUrl",
"");
96 m.imdbRating = j.value(
"imdbRating", 0.0);
97 m.metascore = j.value(
"metascore", 0);
98 m.rottenTomatoes = j.value(
"rottenTomatoes", 0);
99 m.source = j.value(
"source",
"");
100 m.imdbID = j.value(
"imdbID",
"");
102 m.userScore = j.value(
"userScore", 1500.0);
103 m.userRank = j.value(
"userRank", -1);
Movie domain model and metadata.
Definition Movie.h:27