Skip to content
Repos

DevPlaceApp

C++ 820 B28 lines Opens in site

Directory Raw Download

#include "model/Notification.hpp"

#include "core/JsonDecode.hpp"

namespace dp {

Notification::Data Notification::Data::fromJson(const Json& j) {
  using D = JsonDecode;
  Data d;
  d.id = D::req<std::string>(j, "uid");
  d.type = NotificationType::fromRaw(D::req<std::string>(j, "type"));
  d.message = D::req<std::string>(j, "message");
  d.read = D::req<bool>(j, "read");
  d.relatedId = D::req<std::string>(j, "related_uid");
  d.targetUrl = D::req<std::string>(j, "target_url");
  d.createdAt = D::reqDate(j, "created_at");
  return d;
}

Notification Notification::fromJson(const Json& j) {
  using D = JsonDecode;
  Notification n;
  n.data = Data::fromJson(D::child(j, "notification"));
  if (const Json* actor = JsonRead::child(j, "actor")) n.actor = User::fromJson(*actor);
  return n;
}

}  // namespace dp
30.5ms