feat: add feedback existence check and update API spec for feedback submission
This commit is contained in:
@@ -57,7 +57,8 @@ void sendService(Json::Value body,
|
||||
else if (error == "invalid_status_transition" ||
|
||||
error == "media_limit_reached" ||
|
||||
error == "report_not_open" ||
|
||||
error == "report_owned_by_other_operator")
|
||||
error == "report_owned_by_other_operator" ||
|
||||
error == "feedback_already_exists")
|
||||
{
|
||||
status = drogon::k409Conflict;
|
||||
}
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ Authorization: Bearer <token>
|
||||
- `POST /reports/{id}/media`
|
||||
max 5 total media, image/video only
|
||||
- `POST /reports/{id}/feedback`
|
||||
only owner, only when status is `RESOLVED`
|
||||
only owner, only when status is `RESOLVED`, one feedback per report
|
||||
|
||||
## Operator Workflow
|
||||
- `GET /operator/teams`
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "services/UserService.h"
|
||||
|
||||
#include <drogon/drogon.h>
|
||||
#include <drogon/orm/Exception.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
@@ -1057,6 +1058,16 @@ Json::Value ReportService::addFeedback(const auth::UserContext &user,
|
||||
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(
|
||||
"INSERT INTO feedback (report_id, user_id, rating, comment) "
|
||||
"VALUES (?, ?, ?, ?)",
|
||||
@@ -1064,6 +1075,11 @@ Json::Value ReportService::addFeedback(const auth::UserContext &user,
|
||||
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