Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request for User Resource only #75

Merged
merged 9 commits into from
Oct 1, 2019
1 change: 1 addition & 0 deletions server/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
11 changes: 9 additions & 2 deletions server/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ gem 'jbuilder', '~> 2.9'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

gem 'bcrypt', '~> 3.1.7'
gem 'jwt'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

Expand All @@ -44,6 +44,7 @@ group :development, :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 3.29'
gem 'selenium-webdriver'
gem 'rspec-rails', '~> 3.8'
end

group :development do
Expand All @@ -55,5 +56,11 @@ group :development do
gem 'spring-watcher-listen', '~> 2.0.0'
end

group :test do
gem 'factory_bot_rails', '~> 4.0'
gem 'shoulda-matchers', '~> 3.1'
gem 'faker'
gem 'database_cleaner'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
99 changes: 80 additions & 19 deletions server/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GEM
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (9.0.0)
bcrypt (3.1.13)
bindex (0.5.0)
bootsnap (1.4.5)
msgpack (~> 1.0)
Expand All @@ -69,15 +70,31 @@ GEM
coffee-script-source (1.12.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
database_cleaner (1.7.0)
diff-lcs (1.3)
equatable (0.6.0)
erubi (1.8.0)
execjs (2.7.0)
ffi (1.11.1)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
factory_bot_rails (4.11.1)
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
faker (1.9.4)
i18n (>= 0.7)
pastel (~> 0.7.2)
thor (~> 0.20.0)
tty-pager (~> 0.12.0)
tty-screen (~> 0.6.5)
tty-tree (~> 0.3.0)
ffi (1.10.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
jwt (2.2.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -98,6 +115,9 @@ GEM
nio4r (2.3.1)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
pastel (0.7.3)
equatable (~> 0.6)
tty-color (~> 0.5)
pg (1.1.4)
public_suffix (4.0.1)
puma (4.2.0)
Expand Down Expand Up @@ -133,23 +153,42 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
regexp_parser (1.6.0)
regexp_parser (1.5.1)
rspec-core (3.8.1)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
ruby_dep (1.5.0)
rubyzip (2.0.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.0.1)
ffi (~> 1.9)
rake
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (3.142.5)
childprocess (>= 0.5, < 3.0)
rubyzip (>= 1.2.2)
rubyzip (1.2.2)
sass (3.7.3)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (3.142.3)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
shoulda-matchers (3.1.3)
activesupport (>= 4.0.0)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand All @@ -162,16 +201,31 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.1)
strings (0.1.5)
strings-ansi (~> 0.1)
unicode-display_width (~> 1.5)
unicode_utils (~> 1.4)
strings-ansi (0.1.0)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.9)
turbolinks (5.2.1)
tty-color (0.5.0)
tty-pager (0.12.1)
strings (~> 0.1.4)
tty-screen (~> 0.6)
tty-which (~> 0.4)
tty-screen (0.6.5)
tty-tree (0.3.0)
tty-which (0.4.1)
turbolinks (5.2.0)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.6.0)
unicode_utils (1.4.0)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -187,17 +241,24 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt (~> 3.1.7)
bootsnap (>= 1.1.0)
byebug
capybara (~> 3.29)
coffee-rails (~> 5.0)
database_cleaner
factory_bot_rails (~> 4.0)
faker
jbuilder (~> 2.9)
jwt
listen (>= 3.0.5, < 3.2)
pg
puma (~> 4.2)
rails (~> 5.2)
sass-rails (~> 6.0)
rspec-rails (~> 3.8)
sass-rails (~> 5.0)
selenium-webdriver
shoulda-matchers (~> 3.1)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3 (~> 1.4.1)
Expand Down
3 changes: 0 additions & 3 deletions server/app/assets/javascripts/welcome.coffee

This file was deleted.

84 changes: 0 additions & 84 deletions server/app/assets/stylesheets/welcome.scss

This file was deleted.

44 changes: 44 additions & 0 deletions server/app/controllers/api/v1/api_users_controller.rb
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
7 changes: 5 additions & 2 deletions server/app/controllers/application_controller.rb
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

34 changes: 34 additions & 0 deletions server/app/controllers/concerns/exception_handler.rb
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
5 changes: 5 additions & 0 deletions server/app/controllers/concerns/response.rb
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
4 changes: 0 additions & 4 deletions server/app/controllers/welcome_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions server/app/helpers/api_users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApiUsersHelper
LoneKP marked this conversation as resolved.
Show resolved Hide resolved
end
Loading