feat: enhance validation and serialization with fiscal code checks and JSON schema support

This commit is contained in:
gabdevele
2026-06-14 21:09:05 +02:00 Unverified
parent feef498d9a
commit 002f89bd73
10 changed files with 282 additions and 32 deletions
+28 -2
View File
@@ -12,6 +12,9 @@ namespace visione::services
{
namespace
{
using repositories::JsonFieldType;
using repositories::JsonRowSchema;
Json::Value failure(const std::string &code)
{
Json::Value body;
@@ -58,6 +61,27 @@ int boundedPerPage(const std::optional<std::string> &value)
return 50;
}
}
const JsonRowSchema &moderationFlagSchema()
{
static const JsonRowSchema schema{
{"id", JsonFieldType::UInt64},
{"report_id", JsonFieldType::UInt64},
{"message_id", JsonFieldType::UInt64},
{"created_by_user_id", JsonFieldType::UInt64},
{"resolved_by_user_id", JsonFieldType::UInt64}};
return schema;
}
const JsonRowSchema &adminUserSchema()
{
static const JsonRowSchema schema{
{"id", JsonFieldType::UInt64},
{"points", JsonFieldType::Int64},
{"banned", JsonFieldType::Bool},
{"must_change_password", JsonFieldType::Bool}};
return schema;
}
} // namespace
Json::Value AdminService::listCategories()
@@ -229,7 +253,8 @@ Json::Value AdminService::listModeration(
statusValue,
statusValue,
perPageValue,
offset));
offset),
moderationFlagSchema());
return response;
}
@@ -317,7 +342,8 @@ Json::Value AdminService::listUsers(const auth::UserContext &user)
"LEFT JOIN roles r ON r.id = ur.role_id "
"GROUP BY u.id, u.first_name, u.last_name, u.email, u.fiscal_code, "
"u.phone, u.points, u.banned, u.must_change_password "
"ORDER BY u.created_at DESC LIMIT 200"));
"ORDER BY u.created_at DESC LIMIT 200"),
adminUserSchema());
return response;
}