Add report media uploads

This commit is contained in:
gabdevele
2026-06-02 20:38:44 +02:00 Unverified
parent b59536757b
commit 1ef41bb2a3
12 changed files with 77 additions and 46 deletions
+19 -13
View File
@@ -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();
}
+3 -2
View File
@@ -31,12 +31,13 @@ class ReportService
Json::Value addFeedback(const auth::UserContext &user,
long long reportId,
const Json::Value &body);
Json::Value canAddPhoto(const auth::UserContext &user, long long reportId);
Json::Value addPhoto(const auth::UserContext &user,
Json::Value canAddMedia(const auth::UserContext &user, long long reportId);
Json::Value 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);
};
} // namespace visione::services