Commit 59bd2daa authored by Rafael Ravedutti's avatar Rafael Ravedutti

Adjust get citizen uploads format

Signed-off-by: Rafael Ravedutti's avatarRafael Ravedutti <rrlmachado@inf.ufpr.br>
parent 0fbd13c5
Pipeline #16034 passed with stages
in 3 minutes and 28 seconds
......@@ -199,12 +199,21 @@ module Api::V1
# Current citizen id
citizen_id = current_user[0][:id]
# Permission
permission = Professional.get_permission(current_user[1])
# Find uploads for current citizen
@uploads = CitizenUpload.where(citizen_id: citizen_id)
.order("created_at DESC")
.filter(params[:q], params[:page], permission)
# Create response object
response = Hash.new
response[:num_entries] = @uploads.total_count
response[:entries] = @uploads.as_json
# Render uploads in JSON format
render json: @uploads
render json: response.to_json
end
# POST /citizens/upload
......
class CitizenUpload < ApplicationRecord
include Searchable
belongs_to :citizen
# Specify location where the log should be stored (default is public)
......@@ -9,4 +11,23 @@ class CitizenUpload < ApplicationRecord
validates_attachment_content_type :log,
:content_type => ["text/plain", "text/csv"]
# @params params [ActionController::Parameters] Parameters for searching
# @params npage [String] number of page to be returned
# @params permission [String] Permission of current user
# @return [ActiveRecords] filtered citizens
def self.filter(params, npage, permission)
return search(search_params(params, permission), npage)
end
# Translates incoming search parameters to ransack patterns
# @params params [ActionController::Parameters] Parameters for searching
# @params permission [String] Permission of current user
# @return [Hash] filtered and translated parameters
def self.search_params(params, permission)
sortable = ["created_at"]
filter = {"citizen_id" => "citizen_id_eq", "created_at" => "created_at_gteq"}
return filter_search_params(params, filter, sortable)
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment