feat: add feedback existence check and update API spec for feedback submission

This commit is contained in:
gabdevele
2026-06-18 19:29:35 +02:00 Unverified
parent 21f8ccbecc
commit 59cd6f34cb
3 changed files with 26 additions and 9 deletions
+2 -1
View File
@@ -57,7 +57,8 @@ void sendService(Json::Value body,
else if (error == "invalid_status_transition" || else if (error == "invalid_status_transition" ||
error == "media_limit_reached" || error == "media_limit_reached" ||
error == "report_not_open" || error == "report_not_open" ||
error == "report_owned_by_other_operator") error == "report_owned_by_other_operator" ||
error == "feedback_already_exists")
{ {
status = drogon::k409Conflict; status = drogon::k409Conflict;
} }
+1 -1
View File
@@ -74,7 +74,7 @@ Authorization: Bearer <token>
- `POST /reports/{id}/media` - `POST /reports/{id}/media`
max 5 total media, image/video only max 5 total media, image/video only
- `POST /reports/{id}/feedback` - `POST /reports/{id}/feedback`
only owner, only when status is `RESOLVED` only owner, only when status is `RESOLVED`, one feedback per report
## Operator Workflow ## Operator Workflow
- `GET /operator/teams` - `GET /operator/teams`
+16
View File
@@ -7,6 +7,7 @@
#include "services/UserService.h" #include "services/UserService.h"
#include <drogon/drogon.h> #include <drogon/drogon.h>
#include <drogon/orm/Exception.h>
#include <map> #include <map>
#include <set> #include <set>
@@ -1057,6 +1058,16 @@ Json::Value ReportService::addFeedback(const auth::UserContext &user,
return failure("report_not_resolved"); return failure("report_not_resolved");
} }
const auto existingFeedback = db->execSqlSync(
"SELECT id FROM feedback WHERE report_id = ?",
reportId);
if (!existingFeedback.empty())
{
return failure("feedback_already_exists");
}
try
{
db->execSqlSync( db->execSqlSync(
"INSERT INTO feedback (report_id, user_id, rating, comment) " "INSERT INTO feedback (report_id, user_id, rating, comment) "
"VALUES (?, ?, ?, ?)", "VALUES (?, ?, ?, ?)",
@@ -1064,6 +1075,11 @@ Json::Value ReportService::addFeedback(const auth::UserContext &user,
user.id, user.id,
rating, rating,
body.get("comment", "").asString()); body.get("comment", "").asString());
}
catch (const drogon::orm::DrogonDbException &)
{
return failure("feedback_already_exists");
}
return success(); return success();
} }