Skip to content
Repos

DevPlaceApp

C++ 1.3 KB42 lines Opens in site

Directory Raw Download

#pragma once
// Spec: models.md PostDetail (+ Model Updates `with`). Wire is flat: post, author, is_owner, star_count, my_vote, ...
#include <cstdint>
#include <optional>
#include <string>
#include <vector>

#include "core/Json.hpp"
#include "model/Attachment.hpp"
#include "model/Comment.hpp"
#include "model/Poll.hpp"
#include "model/Post.hpp"
#include "model/Reactions.hpp"
#include "model/User.hpp"
#include "model/Vote.hpp"

namespace dp {

struct PostDetail {
  Post::Data post;
  User author;
  bool isOwner = false;
  std::int64_t starCount = 0;
  Vote myVote;
  std::vector<Comment> comments;
  std::vector<Attachment> attachments;
  bool bookmarked = false;
  std::optional<Poll> poll;
  std::int64_t commentCount = 0;
  std::vector<Post> relatedPosts;
  std::vector<std::string> topics;
  Reactions reactions;

  static PostDetail fromJson(const Json& j);
  std::string id() const { return "post:" + post.id; }
  // Copy with some fields replaced; nullopt keeps the current value.
  PostDetail with(std::optional<Vote> myVote = std::nullopt, std::optional<std::int64_t> starCount = std::nullopt,
                  std::optional<std::vector<Comment>> comments = std::nullopt,
                  std::optional<Reactions> reactions = std::nullopt) const;
};

}  // namespace dp
37.1ms