Sha256: baa47e74512fa4a9f01fbd161b9beb31be81defc5538a936d058772173dcbd9f

Contents?: true

Size: 1.01 KB

Versions: 43

Compression:

Stored size: 1.01 KB

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,
          summary: "Get 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 }],
          summary: "Delete a tag"
        }
        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

43 entries across 43 versions & 1 rubygems

Version Path
mihari-5.4.3 lib/mihari/web/endpoints/tags.rb
mihari-5.4.2 lib/mihari/web/endpoints/tags.rb
mihari-5.4.1 lib/mihari/web/endpoints/tags.rb
mihari-5.4.0 lib/mihari/web/endpoints/tags.rb
mihari-5.3.2 lib/mihari/web/endpoints/tags.rb
mihari-5.3.1 lib/mihari/web/endpoints/tags.rb
mihari-5.3.0 lib/mihari/web/endpoints/tags.rb
mihari-5.2.4 lib/mihari/web/endpoints/tags.rb
mihari-5.2.3 lib/mihari/web/endpoints/tags.rb
mihari-5.2.2 lib/mihari/web/endpoints/tags.rb
mihari-5.2.1 lib/mihari/web/endpoints/tags.rb
mihari-5.2.0 lib/mihari/web/endpoints/tags.rb
mihari-5.1.4 lib/mihari/web/endpoints/tags.rb
mihari-5.1.3 lib/mihari/web/endpoints/tags.rb
mihari-5.1.2 lib/mihari/web/endpoints/tags.rb
mihari-5.1.1 lib/mihari/web/endpoints/tags.rb
mihari-5.1.0 lib/mihari/web/endpoints/tags.rb
mihari-5.0.1 lib/mihari/web/endpoints/tags.rb
mihari-5.0.0 lib/mihari/web/endpoints/tags.rb
mihari-4.12.0 lib/mihari/web/endpoints/tags.rb