feat: add soft-delete functionality for categories, areas, and teams in Admin service

This commit is contained in:
gabdevele
2026-06-15 15:10:52 +02:00 Unverified
parent aab7420706
commit bf85168914
8 changed files with 262 additions and 0 deletions
+54
View File
@@ -374,6 +374,26 @@ Json::Value AdminService::updateModeration(const auth::UserContext &user,
return success();
}
Json::Value AdminService::deleteCategory(const auth::UserContext &user,
long long categoryId)
{
if (!auth::isAdmin(user))
{
return failure("forbidden");
}
auto db = drogon::app().getDbClient();
const auto rows = db->execSqlSync(
"SELECT id FROM report_categories WHERE id = ?",
categoryId);
if (rows.empty())
{
return failure("category_not_found");
}
db->execSqlSync("UPDATE report_categories SET active = FALSE WHERE id = ?",
categoryId);
return success();
}
Json::Value AdminService::updateCategory(const auth::UserContext &user,
long long categoryId,
const Json::Value &body)
@@ -411,6 +431,23 @@ Json::Value AdminService::updateCategory(const auth::UserContext &user,
return success();
}
Json::Value AdminService::deleteArea(const auth::UserContext &user,
long long areaId)
{
if (!auth::isAdmin(user))
{
return failure("forbidden");
}
auto db = drogon::app().getDbClient();
const auto rows = db->execSqlSync("SELECT id FROM areas WHERE id = ?", areaId);
if (rows.empty())
{
return failure("area_not_found");
}
db->execSqlSync("UPDATE areas SET active = FALSE WHERE id = ?", areaId);
return success();
}
Json::Value AdminService::updateArea(const auth::UserContext &user,
long long areaId,
const Json::Value &body)
@@ -458,6 +495,23 @@ Json::Value AdminService::updateArea(const auth::UserContext &user,
return success();
}
Json::Value AdminService::deleteTeam(const auth::UserContext &user,
long long teamId)
{
if (!auth::isAdmin(user))
{
return failure("forbidden");
}
auto db = drogon::app().getDbClient();
const auto rows = db->execSqlSync("SELECT id FROM teams WHERE id = ?", teamId);
if (rows.empty())
{
return failure("team_not_found");
}
db->execSqlSync("UPDATE teams SET active = FALSE WHERE id = ?", teamId);
return success();
}
Json::Value AdminService::updateTeam(const auth::UserContext &user,
long long teamId,
const Json::Value &body)
+3
View File
@@ -24,6 +24,9 @@ class AdminService
Json::Value updateModeration(const auth::UserContext &user,
long long flagId,
const Json::Value &body);
Json::Value deleteCategory(const auth::UserContext &user, long long categoryId);
Json::Value deleteArea(const auth::UserContext &user, long long areaId);
Json::Value deleteTeam(const auth::UserContext &user, long long teamId);
Json::Value updateCategory(const auth::UserContext &user,
long long categoryId,
const Json::Value &body);