This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class Templates::Templates::CreateInput < BaseInput | |
REQUIRED_KEYS = %i[title file_name file_base64 user_id] | |
attributes(*REQUIRED_KEYS) | |
def validate! | |
validate_required_keys! | |
validate_user! | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Templates::Template < ApplicationRecord | |
self.table_name = 'templates_templates' | |
belongs_to :user | |
has_many :components, class_name: 'Templates::Component' | |
end | |
# == Schema Information | |
# | |
# Table name: templates_templates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Templates::Component < ApplicationRecord | |
self.table_name = 'templates_components' | |
KEY_TYPE_APPLICATORS = { | |
invoices: %i[ | |
issue_date | |
due_date | |
unit_price | |
total_hours | |
sub_total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class UsersController < ApplicationController | |
def register | |
context = ::Users::Contexts::Registration.call(input: users_registration_input) | |
return error_response(context.message) unless context.success? | |
render json: ::Tokens::TokenBlueprint.render(context.payload), status: :ok | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
def show | |
context = ::Users::Contexts::Fetch.call(params: query_users_params, type: :single) | |
return error_response(context.message) unless context.success? | |
render json: UserBlueprint.render(context.payload), status: :ok | |
end | |
private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# The Fetch class is responsible for retrieving user records from the database. | |
# It extends the BaseService and includes the Queries::Engine module to leverage | |
# query execution functionality. | |
class Users::Contexts::Fetch < BaseService | |
include Queries::Engine | |
private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Queries | |
# The Engine module provides a structure for executing queries against | |
# a given model with a defined set of parameters and conditions. | |
module Engine | |
def self.call(**kwargs) | |
new(**kwargs).call | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# The ErrorHandling module provides mechanisms for managing errors | |
# within service classes. It includes methods for safely executing | |
# blocks of code and handling known error classes. | |
module ErrorHandling | |
module Core | |
# A list of error classes that can be rescued during safe execution. | |
ERROR_CLASSES = [ | |
ActiveRecord::RecordNotFound, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Users::RegistrationInput < BaseInput | |
REQUIRED_KEYS = %i[email password].freeze | |
attributes(*REQUIRED_KEYS, :first_name, :last_name) | |
def validate! | |
validate_required_keys! | |
end | |
end | |
############ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class UsersController < ApplicationController | |
def register | |
context = ::Users::Contexts::Registration.call(input: users_registration_input) | |
return error_response(context.message) unless context.success? | |
render json: ::Tokens::TokenBlueprint.render(context.payload), status: :ok | |
end |