1 #include "lib/spotify/entity.hpp"
2
to_json(nlohmann::json & j,const entity & e)3 void lib::spt::to_json(nlohmann::json &j, const entity &e)
4 {
5 j = nlohmann::json{
6 {"id", e.id},
7 {"name", e.name},
8 };
9 }
10
from_json(const nlohmann::json & j,entity & e)11 void lib::spt::from_json(const nlohmann::json &j, entity &e)
12 {
13 if (!j.is_object())
14 {
15 return;
16 }
17
18 if (j.contains("id"))
19 {
20 const auto &id = j.at("id");
21 if (id.is_string())
22 {
23 id.get_to(e.id);
24 }
25 }
26
27 if (j.contains("name"))
28 {
29 const auto &name = j.at("name");
30 if (name.is_string())
31 {
32 name.get_to(e.name);
33 }
34 }
35 }
36
combine_names(const std::vector<entity> & entities,const char * separator)37 auto lib::spt::entity::combine_names(const std::vector<entity> &entities,
38 const char *separator) -> std::string
39 {
40 std::vector<std::string> names;
41 names.reserve(entities.size());
42 for (const auto &entity : entities)
43 {
44 names.push_back(entity.name);
45 }
46 return lib::strings::join(names, separator);
47 }
48
combine_names(const std::vector<entity> & entities)49 auto lib::spt::entity::combine_names(const std::vector<entity> &entities) -> std::string
50 {
51 return combine_names(entities, ", ");
52 }
53