summaryrefslogtreecommitdiff
path: root/app/controllers/api/user_accounts_controller.rb
blob: b95105fc4c733be240ca8dec335f7d9a77daff0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module Api
  # The UserAccounts controller.
  class UserAccountsController < AuthenticatedController
    skip_before_action :validate_jwt, only: [:create]

    def show
      render json: serialized_user_account.serializable_hash
    end

    def create
      @user_account = UserAccount.new(permitted_params)

      unless @user_account.save
        render json: { errors: @user_account.errors.full_messages }, status: :unprocessable_entity
        return
      end

      render json: Serializers::UserAccountSerializer.new(@user_account).serializable_hash
    end

    private

    def permitted_params
      params.require(:user_account).permit(:email, :first_name, :last_name, :password)
    end

    def serialized_user_account
      @serialized_user_account ||= Serializers::UserAccountSerializer.new(current_user_account)
    end
  end
end