Older/WebApplication/model/Post.cpp
amass b6e0681489
All checks were successful
Deploy / PullDocker (push) Successful in 4s
Deploy / Build (push) Successful in 2m8s
Deploy Docker Images / Docusaurus build and Server deploy (push) Successful in 13s
add code.
2024-11-02 00:30:14 +08:00

37 lines
907 B
C++

#include "Post.h"
#include "User.h"
#include <Wt/Dbo/Impl.h>
DBO_INSTANTIATE_TEMPLATES(Post)
std::string Post::permaLink() const {
return date.toString("yyyy/MM/dd/'" + titleToUrl() + '\'').toUTF8();
}
std::string Post::commentCount() const {
int count = (int)comments.size() - 1;
if (count == 1)
return "1 comment";
else
return std::to_string(count) + " comments";
}
std::string Post::titleToUrl() const {
std::string result = title.narrow();
for (unsigned i = 0; i < result.length(); ++i) {
if (!isalnum(result[i]))
result[i] = '_';
else
result[i] = tolower(result[i]);
}
return result;
}
Wt::Dbo::ptr<Comment> Post::rootComment() const {
if (session())
return session()->find<Comment>().where("post_id = ?").bind(id()).where("parent_id is null");
else
return Wt::Dbo::ptr<Comment>();
}