Skip to content
Repos

DevPlaceApp

C++ 1.1 KB34 lines Opens in site

Directory Raw Download

#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<std::string>(j, "uid");
  d.slug = D::req<std::string>(j, "slug");
  d.userId = D::req<std::string>(j, "user_uid");
  d.title = D::req<std::string>(j, "title");
  d.description = D::req<std::string>(j, "description");
  d.sourceCode = D::req<std::string>(j, "source_code");
  d.language = D::req<std::string>(j, "language");
  d.stars = D::req<std::int64_t>(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<std::int64_t>(j, "my_vote"));
  g.commentCount = D::req<std::int64_t>(j, "comment_count");
  g.recentComments = D::reqModels<Comment>(j, "recent_comments");
  return g;
}

}  // namespace dp
47.4ms