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" ||
|
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
@@ -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`
|
||||||
|
|||||||
@@ -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,13 +1058,28 @@ Json::Value ReportService::addFeedback(const auth::UserContext &user,
|
|||||||
return failure("report_not_resolved");
|
return failure("report_not_resolved");
|
||||||
}
|
}
|
||||||
|
|
||||||
db->execSqlSync(
|
const auto existingFeedback = db->execSqlSync(
|
||||||
"INSERT INTO feedback (report_id, user_id, rating, comment) "
|
"SELECT id FROM feedback WHERE report_id = ?",
|
||||||
"VALUES (?, ?, ?, ?)",
|
reportId);
|
||||||
reportId,
|
if (!existingFeedback.empty())
|
||||||
user.id,
|
{
|
||||||
rating,
|
return failure("feedback_already_exists");
|
||||||
body.get("comment", "").asString());
|
}
|
||||||
|
|
||||||
|
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();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user