Add report media uploads
This commit is contained in:
+19
-13
@@ -181,16 +181,19 @@ Json::Value ReportService::createReport(const auth::UserContext &user,
|
||||
reportId,
|
||||
user.id);
|
||||
|
||||
if (body["photos"].isArray())
|
||||
const auto &mediaItems =
|
||||
body["media"].isArray() ? body["media"] : body["photos"];
|
||||
if (mediaItems.isArray())
|
||||
{
|
||||
for (const auto &photo : body["photos"])
|
||||
for (const auto &item : mediaItems)
|
||||
{
|
||||
if (photo.isString() && !photo.asString().empty())
|
||||
if (item.isString() && !item.asString().empty())
|
||||
{
|
||||
db->execSqlSync(
|
||||
"INSERT INTO report_photos (report_id, url) VALUES (?, ?)",
|
||||
"INSERT INTO report_photos (report_id, url, media_kind) "
|
||||
"VALUES (?, ?, 'IMAGE')",
|
||||
reportId,
|
||||
photo.asString());
|
||||
item.asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,9 +284,10 @@ Json::Value ReportService::reportDetail(const auth::UserContext &user,
|
||||
response["history"] = repositories::resultToJson(db->execSqlSync(
|
||||
"SELECT * FROM report_status_history WHERE report_id = ? ORDER BY id",
|
||||
reportId));
|
||||
response["photos"] = repositories::resultToJson(db->execSqlSync(
|
||||
response["media"] = repositories::resultToJson(db->execSqlSync(
|
||||
"SELECT * FROM report_photos WHERE report_id = ? ORDER BY id",
|
||||
reportId));
|
||||
response["photos"] = response["media"];
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -482,7 +486,7 @@ Json::Value ReportService::addFeedback(const auth::UserContext &user,
|
||||
return success();
|
||||
}
|
||||
|
||||
Json::Value ReportService::canAddPhoto(const auth::UserContext &user,
|
||||
Json::Value ReportService::canAddMedia(const auth::UserContext &user,
|
||||
long long reportId)
|
||||
{
|
||||
if (!canAccessReport(user, reportId))
|
||||
@@ -495,22 +499,23 @@ Json::Value ReportService::canAddPhoto(const auth::UserContext &user,
|
||||
reportId);
|
||||
if (!count.empty() && count[0]["total"].as<int>() >= 5)
|
||||
{
|
||||
return failure("photo_limit_reached");
|
||||
return failure("media_limit_reached");
|
||||
}
|
||||
auto response = success();
|
||||
response["remaining_photo_slots"] =
|
||||
response["remaining_media_slots"] =
|
||||
5 - (count.empty() ? 0 : count[0]["total"].as<int>());
|
||||
return response;
|
||||
}
|
||||
|
||||
Json::Value ReportService::addPhoto(const auth::UserContext &user,
|
||||
Json::Value ReportService::addMedia(const auth::UserContext &user,
|
||||
long long reportId,
|
||||
const std::string &url,
|
||||
const std::string &originalFilename,
|
||||
const std::string &contentType,
|
||||
const std::string &mediaKind,
|
||||
size_t sizeBytes)
|
||||
{
|
||||
auto allowed = canAddPhoto(user, reportId);
|
||||
auto allowed = canAddMedia(user, reportId);
|
||||
if (!allowed.get("ok", false).asBool() || url.empty())
|
||||
{
|
||||
return allowed;
|
||||
@@ -518,12 +523,13 @@ Json::Value ReportService::addPhoto(const auth::UserContext &user,
|
||||
|
||||
drogon::app().getDbClient()->execSqlSync(
|
||||
"INSERT INTO report_photos "
|
||||
"(report_id, url, original_filename, content_type, size_bytes) "
|
||||
"VALUES (?, ?, ?, ?, ?)",
|
||||
"(report_id, url, original_filename, content_type, media_kind, size_bytes) "
|
||||
"VALUES (?, ?, ?, ?, ?, ?)",
|
||||
reportId,
|
||||
url,
|
||||
originalFilename,
|
||||
contentType,
|
||||
mediaKind,
|
||||
static_cast<unsigned long long>(sizeBytes));
|
||||
return success();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user