Skip to content

User Registration feature

Vladislav Trotsenko edited this page Apr 10, 2020 · 6 revisions

This is basic user registration feature. It consists of 1 endpoint.

POST /api/v1/users/registration

The point of this endpoint is create user account.

RegistrationsController#create

module Api::V1::Users
  class RegistrationsController < ApiController
    def create
      endpoint Api::V1::Users::Registrations::Operation::Create
    end
  end
end

Operation

module Api::V1::Users::Registrations::Operation
  class Create < ApplicationOperation
    step Macro::Inject(
      jwt: 'services.email_token',
      worker: Api::V1::Users::Registrations::Worker::EmailConfirmation
    )
    step Model(Account, :new)
    step Contract::Build(constant: Api::V1::Users::Registrations::Contract::Create)
    step Contract::Validate()
    step Contract::Persist()
    step Macro::Semantic(success: :created) # semantic marker for http status
    step :set_email_token # jwt token for verification by email
    step :send_confirmation_link # send confirmation uri with email token
    step Macro::Renderer(serializer: Api::V1::Lib::Serializer::Account) # sets renderer options
  end
end

Used nested & macroses

Clone this wiki locally