@@ -370,11 +370,7 @@ namespace api::v1 {
370370
371371 co_await global::storage->invalidateProject (project);
372372
373- Json::Value root;
374- root[" message" ] = " Project deleted successfully" ;
375- const auto resp = HttpResponse::newHttpJsonResponse (root);
376- resp->setStatusCode (k200OK);
377- callback (resp);
373+ callback (simpleResponse (" Project deleted successfully" ));
378374 }
379375
380376 Task<> ProjectsController::redeployProject (const HttpRequestPtr req, const std::function<void (const HttpResponsePtr &)> callback,
@@ -470,8 +466,29 @@ namespace api::v1 {
470466 Task<> ProjectsController::getDeployments (const HttpRequestPtr req, const std::function<void (const HttpResponsePtr &)> callback,
471467 const std::string id) const {
472468 const auto project = co_await BaseProjectController::getUserProject (req, id);
473- const auto deployments = co_await global::database->getDeployments (project.getValueOfId (), getTableQueryParams (req).page );
469+ auto deployments = co_await global::database->getDeployments (project.getValueOfId (), getTableQueryParams (req).page );
474470
475471 callback (jsonResponse (deployments));
476472 }
473+
474+ Task<> ProjectsController::deleteDeployment (const HttpRequestPtr req, const std::function<void (const HttpResponsePtr &)> callback,
475+ const std::string id) const {
476+ const auto deployment (co_await global::database->getDeployment (id));
477+ if (!deployment) {
478+ throw ApiException (Error::ErrBadRequest, " not_found" );
479+ }
480+ const auto project (co_await BaseProjectController::getUserProject (req, deployment->getValueOfProjectId ()));
481+
482+ if (const auto error = co_await global::database->deleteDeployment (id); error != Error::Ok) {
483+ logger.error (" Failed to delete deployment {} in database" , id);
484+ throw ApiException (Error::ErrInternal, " internal" );
485+ }
486+
487+ if (deployment->getValueOfActive ()) {
488+ logger.debug (" Invalidating project after active deployment was removed" );
489+ co_await global::storage->invalidateProject (project);
490+ }
491+
492+ callback (simpleResponse (" Deployment deleted successfully" ));
493+ }
477494}
0 commit comments