From 7c92a1eb66064d5e5e3bb4a3cd9f4f899d7180f4 Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Thu, 18 Apr 2024 19:34:25 +0900 Subject: [PATCH] fix: fix 204 DELETE issue (#1081) --- lib/mihari/web/endpoints/alerts.rb | 6 ++---- lib/mihari/web/endpoints/artifacts.rb | 4 ++-- lib/mihari/web/endpoints/configs.rb | 7 +------ lib/mihari/web/endpoints/rules.rb | 4 ++-- lib/mihari/web/endpoints/tags.rb | 4 ++-- spec/web/endpoints/artifacts_spec.rb | 2 +- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/mihari/web/endpoints/alerts.rb b/lib/mihari/web/endpoints/alerts.rb index 01a6594f..1680726f 100644 --- a/lib/mihari/web/endpoints/alerts.rb +++ b/lib/mihari/web/endpoints/alerts.rb @@ -52,7 +52,7 @@ class Alerts < Grape::API end desc "Delete an alert", { - success: {code: 204, model: Entities::Message}, + success: {code: 204}, failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete an alert" } @@ -60,11 +60,9 @@ class Alerts < Grape::API requires :id, type: Integer end delete "/:id" do - status 204 - id = params["id"].to_i result = Services::AlertDestroyer.result(id) - return present({message: ""}, with: Entities::Message) if result.success? + return if result.success? case result.failure when ActiveRecord::RecordNotFound diff --git a/lib/mihari/web/endpoints/artifacts.rb b/lib/mihari/web/endpoints/artifacts.rb index acf37a4b..ba28d820 100644 --- a/lib/mihari/web/endpoints/artifacts.rb +++ b/lib/mihari/web/endpoints/artifacts.rb @@ -87,7 +87,7 @@ class Artifacts < Grape::API end desc "Delete an artifact", { - success: {code: 204, model: Entities::Message}, + success: {code: 204}, failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete an artifact" } @@ -99,7 +99,7 @@ class Artifacts < Grape::API id = params["id"].to_i result = Services::ArtifactDestroyer.result(id) - return present({message: ""}, with: Entities::Message) if result.success? + return if result.success? case result.failure when ActiveRecord::RecordNotFound diff --git a/lib/mihari/web/endpoints/configs.rb b/lib/mihari/web/endpoints/configs.rb index 4a243fd7..2ea93d7d 100644 --- a/lib/mihari/web/endpoints/configs.rb +++ b/lib/mihari/web/endpoints/configs.rb @@ -15,12 +15,7 @@ class Configs < Grape::API } get "/" do configs = Services::ConfigSearcher.call - present( - { - results: configs - }, - with: Entities::Configs - ) + present({results: configs}, with: Entities::Configs) end end end diff --git a/lib/mihari/web/endpoints/rules.rb b/lib/mihari/web/endpoints/rules.rb index 6624ad6d..ef6cc2b3 100644 --- a/lib/mihari/web/endpoints/rules.rb +++ b/lib/mihari/web/endpoints/rules.rb @@ -167,7 +167,7 @@ def call(yaml, overwrite: true) end desc "Delete a rule", { - success: {code: 204, model: Entities::Message}, + success: {code: 204}, failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete a rule" } @@ -179,7 +179,7 @@ def call(yaml, overwrite: true) id = params[:id].to_s result = Services::RuleDestroyer.result(id) - return present({message: "ID:#{id} is deleted"}, with: Entities::Message) if result.success? + return if result.success? case result.failure when ActiveRecord::RecordNotFound diff --git a/lib/mihari/web/endpoints/tags.rb b/lib/mihari/web/endpoints/tags.rb index 74dcc1fa..bf8e96bf 100644 --- a/lib/mihari/web/endpoints/tags.rb +++ b/lib/mihari/web/endpoints/tags.rb @@ -32,7 +32,7 @@ class Tags < Grape::API end desc "Delete a tag", { - success: {code: 204, model: Entities::Message}, + success: {code: 204}, failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete a tag" } @@ -44,7 +44,7 @@ class Tags < Grape::API id = params[:id].to_i result = Services::TagDestroyer.result(id) - return present({message: ""}, with: Entities::Message) if result.success? + return if result.success? case result.failure when ActiveRecord::RecordNotFound diff --git a/spec/web/endpoints/artifacts_spec.rb b/spec/web/endpoints/artifacts_spec.rb index 54b3da7b..c9600fa9 100644 --- a/spec/web/endpoints/artifacts_spec.rb +++ b/spec/web/endpoints/artifacts_spec.rb @@ -74,7 +74,7 @@ def app expect(last_response.status).to eq(404) end - it "returns 201" do + it "returns 204" do delete "/api/artifacts/#{artifact_to_delete.id}" expect(last_response.status).to eq(204) end