From 8a932b604c3392ea85e6c22bc13407b5e8297515 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Fri, 1 Nov 2024 14:22:06 +0200 Subject: [PATCH] feat: add support for multiple reserved domains - Add new ReservedDomainsInvoiceStatusesController to handle multiple domains - Removed ReservedDomainInvoiceStatusesController (single domain) - Update invoice description to support multiple reserved domain names - Update Docker configuration: - Switch to official Ruby image - Update PostgreSQL client version - Remove unused Qt and Chrome dependencies This change enables handling multiple domain reservations in a single invoice --- Dockerfile | 22 ++++-------- ...rved_domain_invoice_statuses_controller.rb | 26 -------------- ...ved_domains_invoice_statuses_controller.rb | 35 +++++++++++++++++++ app/services/invoice_instance_generator.rb | 4 +-- config/routes.rb | 3 +- 5 files changed, 46 insertions(+), 44 deletions(-) delete mode 100644 app/controllers/api/v1/invoice/reserved_domain_invoice_statuses_controller.rb create mode 100644 app/controllers/api/v1/invoice/reserved_domains_invoice_statuses_controller.rb diff --git a/Dockerfile b/Dockerfile index 073547b..90cf20b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM internetee/ruby:3.2.2-bullseye +FROM ruby:3.2.2-bullseye SHELL ["/bin/bash", "-o", "pipefail", "-c"] @@ -24,9 +24,9 @@ RUN sed -i -e 's/# et_EE.UTF-8 UTF-8/et_EE.UTF-8 UTF-8/' /etc/locale.gen && \ ENV LANG et_EE.UTF-8 RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc -s | apt-key add - -RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list' +RUN sh -c 'echo "deb https://apt-archive.postgresql.org/pub/repos/apt bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list' RUN apt-get update > /dev/null && apt-get install -y --no-install-recommends > /dev/null \ - postgresql-client-13=* \ + postgresql-client-11=* \ libpq-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -36,12 +36,12 @@ RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - RUN apt-get install -y --no-install-recommends > /dev/null \ nodejs=* \ - qt5-default=* \ - libqt5webkit5-dev=* \ +# qt5-default=* \ +# libqt5webkit5-dev=* \ gstreamer1.0-plugins-base=* \ - libappindicator3-1=* \ +# libappindicator3-1=* \ gstreamer1.0-tools=* \ - qtdeclarative5-dev=* \ +# qtdeclarative5-dev=* \ fonts-liberation=* \ gstreamer1.0-x=* \ libasound2=* \ @@ -62,14 +62,6 @@ RUN apt-get install -y --no-install-recommends > /dev/null \ RUN npm install -g yarn@latest -RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb -RUN dpkg -i /chrome.deb || apt-get update > /dev/null \ - && apt-get install -yf --no-install-recommends > /dev/null && apt-get clean \ - && rm -rf /var/lib/apt/lists/* -RUN dpkg -i /chrome.deb -RUN rm /chrome.deb -RUN sed -i 's/SECLEVEL=2/SECLEVEL=1/' /etc/ssl/openssl.cnf - RUN mkdir -p /opt/webapps/app/tmp/pids WORKDIR /opt/webapps/app diff --git a/app/controllers/api/v1/invoice/reserved_domain_invoice_statuses_controller.rb b/app/controllers/api/v1/invoice/reserved_domain_invoice_statuses_controller.rb deleted file mode 100644 index 38a5136..0000000 --- a/app/controllers/api/v1/invoice/reserved_domain_invoice_statuses_controller.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Api - module V1 - module Invoice - class ReservedDomainInvoiceStatusesController < ApplicationController - def show - domain_name = params[:domain_name] - token = params[:token] - @invoices = ::Invoice.where('description LIKE ?', "%Reserved domain name: #{domain_name}, Token: #{token}%") - - paid_invoices = @invoices.select(&:paid?) - - if paid_invoices.present? - render json: { - message: 'Domain is reserved', - invoice_status: 'paid', - invoice_number: paid_invoices.first.invoice_number - }, - status: :ok - else - render json: { message: 'Domain is not reserved', invoice_status: 'unpaid' }, status: :ok - end - end - end - end - end -end diff --git a/app/controllers/api/v1/invoice/reserved_domains_invoice_statuses_controller.rb b/app/controllers/api/v1/invoice/reserved_domains_invoice_statuses_controller.rb new file mode 100644 index 0000000..0a5767f --- /dev/null +++ b/app/controllers/api/v1/invoice/reserved_domains_invoice_statuses_controller.rb @@ -0,0 +1,35 @@ +module Api + module V1 + module Invoice + class ReservedDomainsInvoiceStatusesController < ApplicationController + before_action :set_invoice, only: :show + + def show + if @invoice.paid? + render json: { + message: 'Domain is reserved', + invoice_status: 'paid', + invoice_number: params[:invoice_number] + }, + status: :ok + else + render json: { + message: 'Domains are not reserved', + invoice_status: 'unpaid', + invoice_number: params[:invoice_number] + }, + status: :ok + end + end + + private + + def set_invoice + @invoice = ::Invoice.find_by(invoice_number: params[:invoice_number]) + + raise ActiveRecord::RecordNotFound, 'Invoice not found' if @invoice.nil? + end + end + end + end +end diff --git a/app/services/invoice_instance_generator.rb b/app/services/invoice_instance_generator.rb index 02dbe7a..116c779 100644 --- a/app/services/invoice_instance_generator.rb +++ b/app/services/invoice_instance_generator.rb @@ -3,8 +3,8 @@ class InvoiceInstanceGenerator REGULAR = 'regular'.freeze def self.create(params:) - description = if params[:reserved_domain_name].present? && params[:token].present? - "Reserved domain name: #{params[:reserved_domain_name]}, Token: #{params[:token]}" + description = if params[:reserved_domain_names].present? + "Reserved domain names: #{params[:reserved_domain_names].join(', ')}" else params.fetch(:custom_field1, 'reload balance').to_s end diff --git a/config/routes.rb b/config/routes.rb index bbd7794..64dc0f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,7 +64,8 @@ namespace :invoice do resource :invoice_synchronize, only: :update resource :update_invoice_data, only: :update - resource :reserved_domain_invoice_statuses, only: :show + resource :reserved_domain_invoice_statuses, only: :show # deprecated + resource :reserved_domains_invoice_statuses, only: :show resource :reserved_domain_cancellation_statuses, only: :update end