feat: add feedback existence check and update API spec for feedback submission
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "services/UserService.h"
|
||||
|
||||
#include <drogon/drogon.h>
|
||||
#include <drogon/orm/Exception.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
@@ -1057,13 +1058,28 @@ Json::Value ReportService::addFeedback(const auth::UserContext &user,
|
||||
return failure("report_not_resolved");
|
||||
}
|
||||
|
||||
db->execSqlSync(
|
||||
"INSERT INTO feedback (report_id, user_id, rating, comment) "
|
||||
"VALUES (?, ?, ?, ?)",
|
||||
reportId,
|
||||
user.id,
|
||||
rating,
|
||||
body.get("comment", "").asString());
|
||||
const auto existingFeedback = db->execSqlSync(
|
||||
"SELECT id FROM feedback WHERE report_id = ?",
|
||||
reportId);
|
||||
if (!existingFeedback.empty())
|
||||
{
|
||||
return failure("feedback_already_exists");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
db->execSqlSync(
|
||||
"INSERT INTO feedback (report_id, user_id, rating, comment) "
|
||||
"VALUES (?, ?, ?, ?)",
|
||||
reportId,
|
||||
user.id,
|
||||
rating,
|
||||
body.get("comment", "").asString());
|
||||
}
|
||||
catch (const drogon::orm::DrogonDbException &)
|
||||
{
|
||||
return failure("feedback_already_exists");
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user