This repository has been archived on 2024-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
2021-11-25 07:07:38 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::Trends::TagsController < Api::BaseController
|
|
|
|
before_action :set_tags
|
|
|
|
|
2022-03-25 19:26:50 -04:00
|
|
|
after_action :insert_pagination_headers
|
|
|
|
|
|
|
|
DEFAULT_TAGS_LIMIT = 10
|
|
|
|
|
2021-11-25 07:07:38 -05:00
|
|
|
def index
|
|
|
|
render json: @tags, each_serializer: REST::TagSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_tags
|
|
|
|
@tags = begin
|
|
|
|
if Setting.trends
|
2022-04-06 14:56:57 -04:00
|
|
|
Trends.tags.query.allowed.offset(offset_param).limit(limit_param(DEFAULT_TAGS_LIMIT))
|
2021-11-25 07:07:38 -05:00
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-03-25 19:26:50 -04:00
|
|
|
|
|
|
|
def insert_pagination_headers
|
|
|
|
set_pagination_headers(next_path, prev_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def pagination_params(core_params)
|
|
|
|
params.slice(:limit).permit(:limit).merge(core_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_path
|
|
|
|
api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT))
|
|
|
|
end
|
|
|
|
|
|
|
|
def prev_path
|
|
|
|
api_v1_trends_tags_url pagination_params(offset: offset_param - limit_param(DEFAULT_TAGS_LIMIT)) if offset_param > limit_param(DEFAULT_TAGS_LIMIT)
|
|
|
|
end
|
|
|
|
|
|
|
|
def offset_param
|
|
|
|
params[:offset].to_i
|
|
|
|
end
|
2021-11-25 07:07:38 -05:00
|
|
|
end
|