mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Created market share chart data endpoint
This commit is contained in:
parent
0745efc766
commit
0c960fea67
2 changed files with 43 additions and 0 deletions
38
app/controllers/repp/v1/stats_controller.rb
Normal file
38
app/controllers/repp/v1/stats_controller.rb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
module Repp
|
||||||
|
module V1
|
||||||
|
class StatsController < BaseController
|
||||||
|
api :get, '/repp/v1/stats/market_share'
|
||||||
|
desc 'Get market share and distribution of registrars'
|
||||||
|
def market_share
|
||||||
|
registrars = ::Registrar.where(test_registrar: false).joins(:domains)
|
||||||
|
registrars = registrars.where(from_condition).where(to_condition)
|
||||||
|
grouped = registrars.group(:name).count
|
||||||
|
|
||||||
|
result = grouped.map do |key, value|
|
||||||
|
hash = { name: key.strip, y: value }
|
||||||
|
hash.merge!({ sliced: true, selected: true }) if current_user.registrar.name == key
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
render_success(data: result)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_params
|
||||||
|
params.permit(:q, q: %i[start_date end_date]).fetch(:q, {}) || {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_condition
|
||||||
|
return unless search_params[:start_date]
|
||||||
|
|
||||||
|
"domains.created_at >= '#{Date.strptime(search_params[:start_date], '%m.%y')}'"
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_condition
|
||||||
|
return unless search_params[:end_date]
|
||||||
|
|
||||||
|
"domains.created_at <= '#{Date.strptime(search_params[:end_date], '%m.%y').end_of_month}'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -99,6 +99,11 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :auctions, only: %i[index]
|
resources :auctions, only: %i[index]
|
||||||
resources :retained_domains, only: %i[index]
|
resources :retained_domains, only: %i[index]
|
||||||
|
resources :stats do
|
||||||
|
collection do
|
||||||
|
get '/market_share', to: 'stats#market_share'
|
||||||
|
end
|
||||||
|
end
|
||||||
namespace :registrar do
|
namespace :registrar do
|
||||||
resources :notifications, only: [:index, :show, :update] do
|
resources :notifications, only: [:index, :show, :update] do
|
||||||
collection do
|
collection do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue