mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 15:14:47 +02:00
Create domain renew action
This commit is contained in:
parent
454433cf10
commit
dcb55a1af9
2 changed files with 36 additions and 2 deletions
|
@ -9,11 +9,12 @@ module Repp
|
|||
api :POST, 'repp/v1/domains/:domain_name/renew'
|
||||
desc 'Renew domain'
|
||||
param :renew, Hash, required: true, desc: 'Renew parameters' do
|
||||
param :renew_period, Integer, required: true, desc: 'Renew period. Month (m) or year (y)'
|
||||
param :period, Integer, required: true, desc: 'Renew period. Month (m) or year (y)'
|
||||
param :period_unit, String, required: true, desc: 'For how many months or years to renew'
|
||||
end
|
||||
def create
|
||||
action = Actions::DomainUpdate.new(@domain, renew_params[:renew], current_user)
|
||||
authorize!(:renew, @domain)
|
||||
action = Actions::DomainRenew.new(@domain, renew_params[:renew], current_user.registrar)
|
||||
|
||||
unless action.call
|
||||
handle_errors(@domain)
|
||||
|
|
33
app/models/actions/domain_renew.rb
Normal file
33
app/models/actions/domain_renew.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Actions
|
||||
class DomainRenew
|
||||
attr_reader :domain
|
||||
attr_reader :params
|
||||
attr_reader :user
|
||||
|
||||
def initialize(domain, params, user)
|
||||
@domain = domain
|
||||
@params = params
|
||||
@user = user
|
||||
end
|
||||
|
||||
def call
|
||||
renew
|
||||
end
|
||||
|
||||
def renew
|
||||
period = params[:period]
|
||||
unit = params[:period_unit]
|
||||
|
||||
task = Domains::BulkRenew::SingleDomainRenew.run(domain: domain,
|
||||
period: params[:period],
|
||||
unit: params[:period_unit],
|
||||
registrar: user)
|
||||
|
||||
return true if task
|
||||
|
||||
puts task.errors
|
||||
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue