mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 22:54:47 +02:00
Fix class/routes namespace for ContactRequest endpoint
This commit is contained in:
parent
d07b6a9c7b
commit
1bbacbf56c
4 changed files with 96 additions and 0 deletions
23
app/controllers/api/v1/contact_requests_controller.rb
Normal file
23
app/controllers/api/v1/contact_requests_controller.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Api
|
||||
module V1
|
||||
class ContactRequestsController < BaseController
|
||||
before_action :authenticate_shared_key
|
||||
|
||||
# POST api/v1/contact_requests/
|
||||
def create
|
||||
return head(:bad_request) if contact_request_params[:email].blank?
|
||||
|
||||
ContactRequest.save_record(contact_request_params)
|
||||
head(:created)
|
||||
rescue ActionController::ParameterMissing
|
||||
head(:bad_request)
|
||||
end
|
||||
|
||||
def update; end
|
||||
|
||||
def contact_request_params
|
||||
params.require(:contact_request).permit(:email, :whois_record_id, :name, :status, :id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
33
app/models/contact_request.rb
Normal file
33
app/models/contact_request.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
class ContactRequest < ApplicationRecord
|
||||
establish_connection :"whois_#{Rails.env}"
|
||||
self.table_name = 'contact_requests'
|
||||
|
||||
STATUS_NEW = 'new'.freeze
|
||||
STATUS_CONFIRMED = 'confirmed'.freeze
|
||||
STATUS_SENT = 'sent'.freeze
|
||||
STATUSES = [STATUS_NEW, STATUS_CONFIRMED, STATUS_SENT].freeze
|
||||
|
||||
validates :whois_record_id, presence: true
|
||||
validates :email, presence: true
|
||||
validates :name, presence: true
|
||||
validates :status, inclusion: { in: STATUSES }
|
||||
|
||||
attr_readonly :secret,
|
||||
:valid_to
|
||||
|
||||
def self.save_record(params)
|
||||
contact_request = new(params)
|
||||
contact_request.secret = create_random_secret
|
||||
contact_request.valid_to = set_valid_to_24_hours_from_now
|
||||
contact_request.status = STATUS_NEW
|
||||
contact_request.save!
|
||||
end
|
||||
|
||||
def self.create_random_secret
|
||||
SecureRandom.hex(64)
|
||||
end
|
||||
|
||||
def self.set_valid_to_24_hours_from_now
|
||||
(Time.zone.now + 24.hours)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue