Skip to content

Instantly share code, notes, and snippets.

# frozen_string_literal: true
class Templates::Components::Contexts::Fetch < BaseService
include Queries::Engine
private
def klass = ::Templates::Component
end
# frozen_string_literal: true
class Templates::Components::Contexts::Creation < BaseService
performs_checks
def initialize(input:)
@input = input
end
def call
# frozen_string_literal: true
# The CreateInput class is responsible for validating the input required
# to create a new template component. It checks for the presence of necessary
# attributes and ensures that the template and user associations are valid.
class Templates::Components::CreateInput < BaseInput
# The required keys for the input attributes.
REQUIRED_KEYS = %i[key_tags key_type text_accessor template_id user_id]
attributes(:title, *REQUIRED_KEYS)
# frozen_string_literal: true
class Templates::Components::QueryInput < Queries::SimpleInput
input_for ::Templates::Component
end
class Templates::Component < ApplicationRecord
self.table_name = 'templates_components'
KEY_TYPE_APPLICATORS = {
invoices: %i[
issue_date
due_date
unit_price
total_hours
sub_total
<body>
<div id="page1" style="width:612.0pt;height:792.0pt">
<p style="top:86.3pt;left:28.3pt;line-height:14.2pt">
<span style="font-family:DejaVuSans,serif;font-size:14.2pt;color:#333333">Invoice HE1003</span>
</p>
<p style="top:115.9pt;left:28.3pt;line-height:7.2pt">
<span style="font-family:DejaVuSans,serif;font-size:7.2pt;color:#7a8798">FROM</span>
</p>
<p style="top:130.9pt;left:28.3pt;line-height:8.3pt">
# frozen_string_literal: true
class Templates::TemplatesController < ApplicationController
before_action :ensure_current_user!
def create
context = ::Templates::Templates::Contexts::Creation.call(input: template_create_input)
return error_response(context.messge) unless context.success?
render json: ::Templates::TemplateBlueprint.render(context.payload), status: :created
# frozen_string_literal: true
# The Creation service is responsible for creating a template from a given PDF file.
#
# It extracts instructions from the PDF, converts the PDF to HTML, and prepares parameters
# for template creation.
#
# @see Templates::Invoices::CreateInput for the expected input structure.
class Templates::Templates::Contexts::Creation < BaseService
performs_checks
# frozen_string_literal: true
class Templates::Templates::Contexts::Fetch < BaseService
include Queries::Engine
private
def klass = ::Templates::Template
end
# frozen_string_literal: true
class Templates::Templates::QueryInput < Queries::SimpleInput
input_for ::Templates::Template
end