Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3447199
Create initial rails files
LetiTran May 7, 2018
8d3d5b9
Generate Controllers with methods and Models for Customer, Movie, and…
madaleines May 7, 2018
0009505
Add foreigns to rental model
madaleines May 7, 2018
4f5231e
Added missing columns for customers and movies
LetiTran May 7, 2018
2eee395
Created routes and model validations
LetiTran May 7, 2018
4c117ea
Added /zomg route
LetiTran May 7, 2018
4367598
Added controller methods
LetiTran May 7, 2018
0f21bb3
Added methods on movie model to return inventoy count and if self is …
LetiTran May 7, 2018
0303b72
Added method to return movies checked out by costumer
LetiTran May 7, 2018
d67afc6
Merge branch 'leti/movie_model'
LetiTran May 7, 2018
510e056
Add methods to Rental Model
madaleines May 7, 2018
8ab9b78
Merge branch 'master' of https://github.com/LetiTran/VideoStoreAPI in…
madaleines May 7, 2018
c6513e8
Added movies and customers fixtures
LetiTran May 8, 2018
45e6609
Fixed fixtures
LetiTran May 8, 2018
0330f7d
Fixed typo in Rental model
LetiTran May 8, 2018
4e06cf9
Fixed Rental model validations
LetiTran May 8, 2018
34fca3d
Validate Rental model test
madaleines May 8, 2018
6d049a1
Fixed boolean validation on Rental
LetiTran May 8, 2018
8d34e5e
Wrote tests for Customer model.
LetiTran May 8, 2018
53c3161
Remove date gem
madaleines May 8, 2018
eff980a
Create fixtures for Rental model tests
madaleines May 8, 2018
b76914f
Write tests for Rental model
madaleines May 8, 2018
799bf72
Edit assign_due_date method to take date from created_at
madaleines May 8, 2018
c436828
Created tests for Movie model.
LetiTran May 8, 2018
8fa9c18
Merging with rental model tests.
LetiTran May 8, 2018
93cc499
initiate RABL
madaleines May 8, 2018
6f461e3
Merge branch 'master' of https://github.com/LetiTran/VideoStoreAPI in…
madaleines May 8, 2018
aceb122
Created Customer #index and #create methods
LetiTran May 8, 2018
3ee9a9f
Movies and Customers controller methods created and working.
LetiTran May 8, 2018
14e2d49
Figuring out rabl
madaleines May 8, 2018
b985e10
resolve merge conflicts
madaleines May 8, 2018
385bbef
Manipulate RABL files
madaleines May 8, 2018
22fc41e
Changed Movie#available_inventory to work with movies that have no in…
LetiTran May 9, 2018
327a544
Added rabl functions to Customer and Movie views.
LetiTran May 9, 2018
5ff2ef0
remove validation for due date
madaleines May 9, 2018
a0c6adf
Write controller methods for Rental
madaleines May 9, 2018
cc73d78
resolve merge conflicts
madaleines May 9, 2018
82e19c4
Modify Rental model tests to validate if returned is true
madaleines May 9, 2018
5b82867
Updated Customer model tests
LetiTran May 9, 2018
2d0abfe
Updated movie model tests to work with the new Rentals fixtures
LetiTran May 9, 2018
63d6801
Merge branch 'master' of https://github.com/LetiTran/VideoStoreAPI in…
LetiTran May 9, 2018
5ff86eb
remove json root and child root in config
madaleines May 9, 2018
c7cda15
Merge branch 'master' of https://github.com/LetiTran/VideoStoreAPI in…
LetiTran May 9, 2018
14a8e82
removed config override for child node
madaleines May 9, 2018
10a8f1b
Write controller tests for Rentals
madaleines May 9, 2018
e473386
Wrote customers_controller tests and all passing
LetiTran May 9, 2018
cae5e84
Minor refactoring in costumers controller
LetiTran May 9, 2018
53b35bd
Wrote movie controller tests and all passing.
LetiTran May 9, 2018
df46b6e
Merge branch 'master' of https://github.com/LetiTran/VideoStoreAPI
LetiTran May 9, 2018
dc884c1
Edit routes for Rental and work on update method
madaleines May 9, 2018
f510137
Working on smoke tests for movie
LetiTran May 9, 2018
fdf2afd
modify movie controller
madaleines May 9, 2018
026175b
working on rental tests and methods. Fixed update problem that wasnt …
LetiTran May 9, 2018
1b2171c
Merging
LetiTran May 9, 2018
e6b68cd
Edit wording
madaleines May 9, 2018
5164c1e
changaed customer controller test to work without required params in …
LetiTran May 9, 2018
7facac9
FIXED SHIT AND OUR SMOKE TESTS PASS
madaleines May 10, 2018
093290b
Fix Controller and model tests accordingly
madaleines May 10, 2018
1a496ad
Remove unnecessary files
madaleines May 10, 2018
5e9da55
Fixed assign_due_date method and changed rabl to display the due_date…
LetiTran May 11, 2018
45c9350
Refactoring
LetiTran May 11, 2018
cb28255
Begin optionals for sorting
madaleines May 11, 2018
bb9717e
Merge branch 'master' of https://github.com/LetiTran/VideoStoreAPI in…
madaleines May 11, 2018
50f010c
Deleted check-in method in rental model
LetiTran May 11, 2018
4faa4b9
Merge branch 'master' of https://github.com/LetiTran/VideoStoreAPI
LetiTran May 11, 2018
24c2c7e
Pagination working. Added params for pagination
LetiTran May 11, 2018
ad0593a
Working on sorting customers by name
LetiTran May 11, 2018
0cc8610
Sorting by name working - NEED REFACTORING
LetiTran May 11, 2018
aa96b9a
Sort by name working and refactored.
LetiTran May 11, 2018
d7c047e
Movies can be sorted now too.
LetiTran May 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

.byebug_history
62 changes: 62 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
source 'https://rubygems.org'

git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.7'

# RABL for json view
gem 'rabl'
gem 'oj'
# To fix API issue with rabl and rail 5
gem 'jbuilder'

gem 'has_scope', '~> 0.7.1'

gem 'will_paginate', '~> 3.1.0'


# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :development, :test do
gem 'pry-rails'
end

group :test do
gem 'minitest-rails'
gem 'minitest-reporters'
end
170 changes: 170 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.6)
actionpack (= 5.1.6)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.6)
actionview (= 5.1.6)
activesupport (= 5.1.6)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.6)
activesupport (= 5.1.6)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.6)
activesupport (= 5.1.6)
globalid (>= 0.3.6)
activemodel (5.1.6)
activesupport (= 5.1.6)
activerecord (5.1.6)
activemodel (= 5.1.6)
activesupport (= 5.1.6)
arel (~> 8.0)
activesupport (5.1.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ansi (1.5.0)
arel (8.0.0)
builder (3.2.3)
byebug (10.0.2)
coderay (1.1.2)
concurrent-ruby (1.0.5)
crass (1.0.4)
erubi (1.7.1)
ffi (1.9.23)
globalid (0.4.1)
activesupport (>= 4.2.0)
has_scope (0.7.2)
actionpack (>= 4.1)
activesupport (>= 4.1)
i18n (1.0.1)
concurrent-ruby (~> 1.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
method_source (0.9.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
minitest-rails (3.0.0)
minitest (~> 5.8)
railties (~> 5.0)
minitest-reporters (1.2.0)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.13.1)
nio4r (2.3.1)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
oj (3.6.0)
pg (1.0.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.6)
pry (>= 0.10.4)
puma (3.11.4)
rabl (0.13.1)
activesupport (>= 2.3.14)
rack (2.0.5)
rack-test (1.0.0)
rack (>= 1.0, < 3)
rails (5.1.6)
actioncable (= 5.1.6)
actionmailer (= 5.1.6)
actionpack (= 5.1.6)
actionview (= 5.1.6)
activejob (= 5.1.6)
activemodel (= 5.1.6)
activerecord (= 5.1.6)
activesupport (= 5.1.6)
bundler (>= 1.3.0)
railties (= 5.1.6)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.1.6)
actionpack (= 5.1.6)
activesupport (= 5.1.6)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
spring (2.0.2)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
will_paginate (3.1.6)

PLATFORMS
ruby

DEPENDENCIES
byebug
has_scope (~> 0.7.1)
jbuilder
listen (>= 3.0.5, < 3.2)
minitest-rails
minitest-reporters
oj
pg (>= 0.18, < 2.0)
pry-rails
puma (~> 3.7)
rabl
rails (~> 5.1.6)
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data
will_paginate (~> 3.1.0)

BUNDLED WITH
1.16.1
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
4 changes: 4 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
4 changes: 4 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
Empty file added app/controllers/concerns/.keep
Empty file.
34 changes: 34 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class CustomersController < ApplicationController
def zomg
message = "it works"
render json: message.as_json
end

def index
params[:sort] ? (sort = params[:sort].to_sym) : sort = :id

@customers = Customer.order(sort).paginate(page: params[:p], per_page: params[:n])
end

def create
customer = Customer.create(customers_params)

if customer.valid?
customer.assign_registered_date
render json: {id: customer.id}, status: :ok
else
render json: {ok: false, errors: customer.errors}, status: :bad_request
end
end

# (Show not required)
def show
@customer = Customer.find_by(id: params[:id])
render json: {ok: false, error: :not_found}, status: :not_found if @customer.nil?
end

private
def customers_params
params.permit(:name, :phone, :address, :city, :state, :postal_code, :p, :n, :sort)
end
end
31 changes: 31 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class MoviesController < ApplicationController
def index

params[:sort] ? (sort = params[:sort].to_sym) : sort = :id
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is great! I'm a fan!

Ternaries also work so you can assign things like this (this does the same thing you did):

sort = params[:sort] ? params[:sort].to_sym : :id


@movies = Movie.order(sort).paginate(page: params[:p], per_page: params[:n])

end

def show

@movie = Movie.find_by(id: params[:id])

render json: {ok: false, error: :not_found}, status: :not_found if @movie.nil?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these post-fix conditionals look really fancy and nice!

end

def create
movie = Movie.create(movies_params)

if movie.valid?
render json: {id: movie.id}, status: :ok
else
render json: {ok: false, errors: movie.errors}, status: :bad_request
end
end

private
def movies_params
params.permit(:title, :release_date, :overview, :inventory, :p, :n, :sort)
end
end
48 changes: 48 additions & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class RentalsController < ApplicationController
def index
@rentals = Rental.all
end

def show
@rental = Rental.find_by(id: params[:id])

if @rental.nil?
render json: { ok: false, error: :not_found }, status: :not_found
end
end

def create
movie = Movie.find_by(id: params[:movie_id])

if movie.available?
rental = Rental.create(rental_params)

if rental.valid?
rental.assign_due_date
render json: { id: rental.id }, status: :ok
else
render json: {ok: false, errors: rental.errors}, status: :bad_request
end

else
render json: {ok: false, errors: "This will not work"}, status: :bad_request
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phrase "This will not work" is a little awkward sounding?

end
end

def update
rental = Rental.where(customer_id: params[:customer_id]).where(movie_id: params[:movie_id]).find_by(returned: false)

if rental
rental.update_attributes(returned: true)
render json: { id: rental.id }, status: :ok
else
render json: { ok: false, errors: "This will not work" }, status: :bad_request
end
end

private

def rental_params
return params.permit(:customer_id, :movie_id)
end
end
Binary file added app/images/mads.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/madsgardens.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/madsinhawaii.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Empty file added app/models/concerns/.keep
Empty file.
Loading