From f72ec0ec3ad6d4e96d6adc76cbabbe8cd964a40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 6 Oct 2020 14:28:57 +0300 Subject: [PATCH] Add contact create to REPP --- app/api/repp/contact_v1.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/api/repp/contact_v1.rb b/app/api/repp/contact_v1.rb index 810829ef7..1eb5a88ce 100644 --- a/app/api/repp/contact_v1.rb +++ b/app/api/repp/contact_v1.rb @@ -30,6 +30,37 @@ module Repp total_number_of_records: current_user.registrar.contacts.count } end + + desc 'Create new contact object' + params do + requires :contact, type: Hash, allow_blank: false do + requires :name, type: String, desc: 'Full name of contact' + requires :ident, type: String, desc: 'Government identifier of contact' + requires :ident_type, type: String, desc: 'Type of contact ident' + requires :ident_country_code, type: String, desc: 'Ident country code' + requires :country_code, type: String, desc: 'Address country' + requires :phone, type: String, desc: 'Phone number of contact. In format of +country_prefix.number' + requires :email, type: String, desc: 'Email address of contact' + requires :fax, type: String, desc: 'Fax number of contact' + requires :street, type: String, desc: 'Address street' + requires :city, type: String, desc: 'Address city' + requires :zip, type: String, desc: 'Address ZIP' + end + end + + post '/' do + @legal_doc = params[:legal_documents] + @contact = Contact.new(params[:contact]) + @contact.registrar = current_user.registrar + action = Actions::ContactCreate.new(@contact, @legal_doc) + + if action.call + @response = { data: { contact: { id: @contact.id } } } + else + status :bad_request + @response = { errors: @contact.errors } + end + end end end end