From b904941229de53660a3e37c3d0931cc3f74212bf Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Tue, 21 Feb 2023 19:59:06 -0600 Subject: AƱade serializador de usuarios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/user_accounts_controller.rb | 23 +++++++++++++++++++++++ app/serializers/base_serializer.rb | 8 ++++++++ 2 files changed, 31 insertions(+) create mode 100644 app/controllers/api/user_accounts_controller.rb create mode 100644 app/serializers/base_serializer.rb diff --git a/app/controllers/api/user_accounts_controller.rb b/app/controllers/api/user_accounts_controller.rb new file mode 100644 index 0000000..36359e5 --- /dev/null +++ b/app/controllers/api/user_accounts_controller.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Api + # The UserAccounts controller. + class UserAccountsController < ApplicationController + 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 + end +end diff --git a/app/serializers/base_serializer.rb b/app/serializers/base_serializer.rb new file mode 100644 index 0000000..bead772 --- /dev/null +++ b/app/serializers/base_serializer.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +module Serializers + # The father class of all serializers. + class BaseSerializer + include JSONAPI::Serializer + end +end -- cgit v1.2.3