Sha256: 77cd7103c1b03f1ae6130167e50d088619106721b5015ed22ca7d4626ea60ca1

Contents?: true

Size: 966 Bytes

Versions: 6

Compression:

Stored size: 966 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Endpoints
    class Tags < Grape::API
      namespace :tags do
        desc "Get tags", {
          is_array: true,
          success: Entities::Tags
        }
        get "/" do
          tags = Mihari::Tag.distinct.pluck(:name)
          present({ tags: tags }, with: Entities::Tags)
        end

        desc "Delete a tag", {
          success: Entities::Message,
          failure: [{ code: 404, message: "Not found", model: Entities::Message }]
        }
        params do
          requires :name, type: String
        end
        delete "/:name" do
          name = params[:name].to_s

          begin
            Mihari::Tag.where(name: name).destroy_all
          rescue ActiveRecord::RecordNotFound
            error!({ message: "Name:#{name} is not found" }, 404)
          end

          status 204
          present({ message: "" }, with: Entities::Message)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mihari-3.12.0 lib/mihari/web/endpoints/tags.rb
mihari-3.11.0 lib/mihari/web/endpoints/tags.rb
mihari-3.10.1 lib/mihari/web/endpoints/tags.rb
mihari-3.10.0 lib/mihari/web/endpoints/tags.rb
mihari-3.9.2 lib/mihari/web/endpoints/tags.rb
mihari-3.9.1 lib/mihari/web/endpoints/tags.rb