#include "model/Gist.hpp" #include "core/JsonDecode.hpp" namespace dp { Gist::Data Gist::Data::fromJson(const Json& j) { using D = JsonDecode; Data d; d.id = D::req(j, "uid"); d.slug = D::req(j, "slug"); d.userId = D::req(j, "user_uid"); d.title = D::req(j, "title"); d.description = D::req(j, "description"); d.sourceCode = D::req(j, "source_code"); d.language = D::req(j, "language"); d.stars = D::req(j, "stars"); d.createdAt = D::reqDate(j, "created_at"); d.updatedAt = D::optDate(j, "updated_at"); return d; } Gist Gist::fromJson(const Json& j) { using D = JsonDecode; Gist g; g.data = Data::fromJson(D::child(j, "gist")); if (const Json* author = JsonRead::child(j, "author")) g.author = User::fromJson(*author); g.myVote = Vote::fromInt(D::req(j, "my_vote")); g.commentCount = D::req(j, "comment_count"); g.recentComments = D::reqModels(j, "recent_comments"); return g; } } // namespace dp