mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 14:36:22 +02:00
added endpoints to demo registry for accr results
This commit is contained in:
parent
487cbb1774
commit
c07abaea59
20 changed files with 401 additions and 78 deletions
|
@ -3,24 +3,26 @@ require 'auth_token/auth_token_decryptor'
|
|||
module Api
|
||||
module V1
|
||||
module AccreditationCenter
|
||||
class BaseController < ActionController::API
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :show_not_found_error
|
||||
rescue_from ActiveRecord::RecordInvalid, with: :show_invalid_record_error
|
||||
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
|
||||
error = {}
|
||||
error[parameter_missing_exception.param] = ['parameter is required']
|
||||
response = { errors: [error] }
|
||||
render json: response, status: :unprocessable_entity
|
||||
end
|
||||
if Rails.env.development? || Rails.env.staging? || Rails.env.test?
|
||||
class BaseController < ActionController::API
|
||||
rescue_from ActiveRecord::RecordNotFound, with: :show_not_found_error
|
||||
rescue_from ActiveRecord::RecordInvalid, with: :show_invalid_record_error
|
||||
rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
|
||||
error = {}
|
||||
error[parameter_missing_exception.param] = ['parameter is required']
|
||||
response = { errors: [error] }
|
||||
render json: response, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def show_not_found_error
|
||||
render json: { errors: [{ base: ['Not found'] }] }, status: :not_found
|
||||
end
|
||||
def show_not_found_error
|
||||
render json: { errors: [{ base: ['Not found'] }] }, status: :not_found
|
||||
end
|
||||
|
||||
def show_invalid_record_error(exception)
|
||||
render json: { errors: exception.record.errors }, status: :bad_request
|
||||
def show_invalid_record_error(exception)
|
||||
render json: { errors: exception.record.errors }, status: :bad_request
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
require 'serializers/repp/contact'
|
||||
|
||||
module Api
|
||||
module V1
|
||||
module AccreditationCenter
|
||||
class ResultsController < ::Api::V1::AccreditationCenter::BaseController
|
||||
def show
|
||||
accr_users = []
|
||||
registrar = Registrar.find_by(name: params[:registrar_name])
|
||||
|
||||
return render json: { errors: 'Registrar not found' }, status: :not_found if registrar.nil?
|
||||
|
||||
registrar.api_users.where.not(accreditation_date: nil).each do |u|
|
||||
accr_users << u
|
||||
end
|
||||
|
||||
render json: { code: 1000, registrar_users: accr_users }
|
||||
end
|
||||
|
||||
def show_api_user
|
||||
user_api = User.find_by(username: params[:username], identity_code: params[:identity_code])
|
||||
|
||||
return render json: { errors: 'User not found' }, status: :not_found if user_api.nil?
|
||||
|
||||
return render json: { errors: 'No accreditated yet' }, status: :not_found if user_api.accreditation_date.nil?
|
||||
|
||||
render json: { code: 1000, user_api: user_api }
|
||||
end
|
||||
|
||||
def list_accreditated_api_users
|
||||
users = User.where.not(accreditation_date: nil)
|
||||
|
||||
return render json: { errors: 'Accreditated users not found' }, status: :not_found if users.empty?
|
||||
|
||||
render json: { code: 1000, users: users }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue