Sha256: 136ceb844fc09beafa70e6738c46fc01fc3f83c4eef35606d510ba14ee6bd807

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Ecom
  module Core
    class UsersController < ApplicationController
      before_action :set_user, only: [:update]

      def index
        render json: User.all
      end

      def lookup
        data = ActiveModelSerializers::SerializableResource.new(User.all, each_serializer: UserLookupSerializer)
        render json: { success: true, data: data }
      end

      def active
        render json: User.active
      end

      def create
        user = User.new(user_params)
        if user.save
          render json: user, status: :created
        else
          render json: { success: false, errors: user.errors }, status: :unprocessable_entity
        end
      end

      def update
        if @user.update(user_params)
          render json: @user
        else
          render json: { success: false, errors: @user.errors }, status: :unprocessable_entity
        end
      end

      private

      def set_user
        @user = User.find(params[:id])
      end

      def user_params
        params.require(:user).permit(:first_name, :last_name, :email, :password, :active)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ecom_core-1.3.14 app/controllers/ecom/core/users_controller.rb
ecom_core-1.3.13 app/controllers/ecom/core/users_controller.rb
ecom_core-1.3.12 app/controllers/ecom/core/users_controller.rb
ecom_core-1.3.11 app/controllers/ecom/core/users_controller.rb