Skip to content

Commit

Permalink
fix: fix 204 DELETE issue (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki authored Apr 18, 2024
1 parent 42e22e1 commit 7c92a1e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
6 changes: 2 additions & 4 deletions lib/mihari/web/endpoints/alerts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ 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"
}
params do
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
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/web/endpoints/artifacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions lib/mihari/web/endpoints/configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/web/endpoints/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/web/endpoints/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/web/endpoints/artifacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c92a1e

Please sign in to comment.