-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from RailsGirlsCPH/user_resource
Pull Request for User Resource only
- Loading branch information
Showing
27 changed files
with
706 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class Api::V1::ApiUsersController < ApplicationController | ||
before_action :set_api_user, only: [:show, :update, :destroy] | ||
|
||
#GET /api_users | ||
def index | ||
@api_users = ApiUser.all | ||
json_response(@api_users) | ||
end | ||
|
||
# Post /api_users | ||
def create | ||
@api_user = ApiUser.create!(api_user_params) | ||
json_response(@api_user, :created) | ||
end | ||
|
||
# GET /api_users/:id | ||
def show | ||
json_response(@api_user) | ||
end | ||
|
||
# PUT /api_users/:id | ||
def update | ||
@api_user.update(api_user_params) | ||
head :no_content | ||
end | ||
|
||
# DELETE /api_users/:id | ||
def destroy | ||
@api_user.destroy | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def api_user_params | ||
#whitelist params | ||
#params.permit(:email, :password_digest) | ||
params.require(:api_user).permit(:first_name, :last_name, :city, :email, :password_digest, :mentor, :mentee) | ||
end | ||
|
||
def set_api_user | ||
@api_user = ApiUser.find(params[:id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
class ApplicationController < ActionController::Base | ||
protect_from_forgery with: :exception | ||
class ApplicationController < ActionController::API | ||
#protect_from_forgery with: :exception | ||
include Response | ||
include ExceptionHandler | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module ExceptionHandler | ||
extend ActiveSupport::Concern | ||
|
||
# Define custom error subclasses - rescue catches `StandardErrors` | ||
class AuthenticationError < StandardError; end | ||
class MissingToken < StandardError; end | ||
class InvalidToken < StandardError; end | ||
|
||
included do | ||
rescue_from ActiveRecord::RecordInvalid, with: :four_two_two | ||
rescue_from ActiveRecord::RecordNotFound, with: :four_o_four | ||
rescue_from ActionController::ParameterMissing, with: :four_two_two | ||
#Following handlers not required until authentication set up | ||
#rescue_from ExceptionHandler::AuthenticationError, with: :unauthorized_request | ||
#rescue_from ExceptionHandler::MissingToken, with: :four_twenty_two | ||
#rescue_from ExceptionHandler::InvalidToken, with: :four_twenty_two | ||
end | ||
|
||
private | ||
|
||
def four_o_four(e) | ||
json_response({message: e.message}, :not_found) | ||
end | ||
|
||
def four_two_two(e) | ||
json_response({message: e.message}, :unprocessable_entity) | ||
end | ||
|
||
# JSON response with message; Status code 401 - Unauthorized | ||
def unauthorized_request(e) | ||
json_response({ message: e.message }, :unauthorized) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Response | ||
def json_response(object, status = :ok) | ||
render json: object, status: status | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ApiUsersHelper | ||
end |
Oops, something went wrong.