Skip to content

Instantly share code, notes, and snippets.

@Hasstrup
Created November 5, 2024 23:08
Show Gist options
  • Save Hasstrup/066a761b09f378ac57bb12927eda5055 to your computer and use it in GitHub Desktop.
Save Hasstrup/066a761b09f378ac57bb12927eda5055 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
class Templates::TemplatesController < ApplicationController
before_action :ensure_current_user!
def dispatch_mail
context = ::Templates::Templates::Contexts::EmailDispatch.call(input: email_dispatch_input)
return error_response(context.message) unless context.success?
render json: ::Templates::TemplateBlueprint.render(context.payload), status: :created
end
private
def email_dispatch_input
@email_dispatch_input ||=
::Templates::Templates::EmailDispatchInput.new(**including_current_user(template_mail_dispatch_params))
end
def template_mail_dispatch_params
@template_mail_dispatch_params ||= params.permit(*%i[template_id strategy])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment