keep working on the like button

This commit is contained in:
2026-07-20 19:02:04 +10:00
parent 7d0727a7aa
commit 6241824960
9 changed files with 67 additions and 4 deletions

View File

@@ -154,6 +154,22 @@ void Database::addPost(const Post& post) {
sqlite3_finalize(stmt);
}
void Database::addLike(uint64_t postId, uint64_t userId) {
std::stringstream sql;
sql << R"(
UPDATE posts
SET likes = likes + 1
WHERE id =
)";
sql << postId << ";";
std::string sqlstr = sql.str();
char* errmsg = nullptr;
if (sqlite3_exec(db, sqlstr.c_str(), nullptr, nullptr, &errmsg) != SQLITE_OK) {
throw std::runtime_error("sqlite3 error: " + std::string(errmsg));
}
}