From dcb55a1af9e929c5ef3cf67de26986c66ce329d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Thu, 21 Jan 2021 13:08:54 +0200 Subject: [PATCH] Create domain renew action --- .../repp/v1/domains/renews_controller.rb | 5 +-- app/models/actions/domain_renew.rb | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/models/actions/domain_renew.rb diff --git a/app/controllers/repp/v1/domains/renews_controller.rb b/app/controllers/repp/v1/domains/renews_controller.rb index 67c537bf6..1ba8db506 100644 --- a/app/controllers/repp/v1/domains/renews_controller.rb +++ b/app/controllers/repp/v1/domains/renews_controller.rb @@ -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) diff --git a/app/models/actions/domain_renew.rb b/app/models/actions/domain_renew.rb new file mode 100644 index 000000000..ec8178e6f --- /dev/null +++ b/app/models/actions/domain_renew.rb @@ -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