feat: add soft-delete functionality for categories, areas, and teams in Admin service
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user