Older/WebApplication/model/Post.h
luocai 8c0128c4e7
Some checks failed
Deploy / PullDocker (push) Failing after 2s
Deploy / Build (push) Successful in 1m59s
Deploy Docker Images / Docusaurus build and Server deploy (push) Successful in 2h4m57s
update docker images.
2024-11-07 18:21:04 +08:00

58 lines
1.4 KiB
C++

#ifndef __POST_H__
#define __POST_H__
#include "Comment.h"
#include "Tag.h"
#include <Wt/Dbo/WtSqlTraits.h>
#include <Wt/WDateTime.h>
#include <Wt/WString.h>
class User;
typedef Wt::Dbo::collection<Wt::Dbo::ptr<Comment>> Comments;
typedef Wt::Dbo::collection<Wt::Dbo::ptr<Tag>> Tags;
class Post : public Wt::Dbo::Dbo<Post> {
public:
enum State {
Unpublished = 0,
Published = 1,
};
std::string permaLink() const;
std::string commentCount() const;
std::string titleToUrl() const;
Wt::Dbo::ptr<Comment> rootComment() const;
template <class Action>
void persist(Action &a) {
Wt::Dbo::field(a, state, "state");
Wt::Dbo::field(a, date, "date");
Wt::Dbo::field(a, title, "title");
Wt::Dbo::field(a, briefSrc, "brief_src");
Wt::Dbo::field(a, briefHtml, "brief_html");
Wt::Dbo::field(a, bodySrc, "body_src");
Wt::Dbo::field(a, bodyHtml, "body_html");
Wt::Dbo::belongsTo(a, author, "author");
Wt::Dbo::hasMany(a, comments, Wt::Dbo::ManyToOne, "post");
Wt::Dbo::hasMany(a, tags, Wt::Dbo::ManyToMany, "post_tag");
}
Wt::Dbo::ptr<User> author;
State state;
Wt::WDateTime date;
Wt::WString title;
Wt::WString briefSrc;
Wt::WString briefHtml;
Wt::WString bodySrc;
Wt::WString bodyHtml;
Comments comments;
Tags tags;
};
DBO_EXTERN_TEMPLATES(Post)
#endif // __POST_H__