Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b3b0783
installed rails api and gitignore
GeMath18 Dec 2, 2020
d6c22a6
created models for customer,video,rental and migrations to relaterent…
GeMath18 Dec 2, 2020
9c51609
created controllers for customers and videos
GeMath18 Dec 2, 2020
7e331e6
created routes
GeMath18 Dec 2, 2020
145e2c2
added a column to customers table to be able to seed. seeding done.
GeMath18 Dec 2, 2020
b69b66c
solved the conflicts after merge
ichbinorange Dec 2, 2020
57dfcdc
added methods for customers index and videos show
ichbinorange Dec 3, 2020
ec5c0ce
added index and create to video controller, tests are passing, added …
GeMath18 Dec 3, 2020
6d59fd6
Merge pull request #1 from GeMath18/customers_index_n_videos_show
ichbinorange Dec 3, 2020
0f3e6e0
merge conflict
GeMath18 Dec 3, 2020
348c533
added brasket for error msg
ichbinorange Dec 3, 2020
48a451a
generated rentals controller
ichbinorange Dec 3, 2020
38863e4
added routes for rentals check_in and check_out
ichbinorange Dec 3, 2020
c47c7cf
added validations to rental model, deleted a column for rental table …
GeMath18 Dec 3, 2020
0063d64
drafted check-out for rentals
ichbinorange Dec 3, 2020
8979c61
fixed merge conflicts
ichbinorange Dec 3, 2020
8569a6f
revised the validates
ichbinorange Dec 3, 2020
63a82eb
added model helper methods for check_out action in rental
ichbinorange Dec 3, 2020
9bd433a
added tests for check_out action for rental
ichbinorange Dec 3, 2020
8b68dcb
added method for check_out action for rental
ichbinorange Dec 3, 2020
f6058d3
Merge pull request #2 from GeMath18/rentals_checkout
ichbinorange Dec 3, 2020
f0ff1c0
fixed the response of release_date format on video show
ichbinorange Dec 3, 2020
e2ae522
Merge pull request #3 from GeMath18/rentals_checkout
ichbinorange Dec 3, 2020
ade2861
created the check-in method and testing for it, all passed
GeMath18 Dec 3, 2020
4427fb8
Merge branch 'gm/rentalscheck-inmethod'
GeMath18 Dec 3, 2020
ef23785
added simplecov
ichbinorange Dec 3, 2020
338bf4c
Merge pull request #4 from GeMath18/rentals_checkout
ichbinorange Dec 3, 2020
54220a1
added tests for rental validations and custom methods, removed the re…
ichbinorange Dec 3, 2020
3e586d1
Merge pull request #5 from GeMath18/rental_validates
ichbinorange Dec 3, 2020
090bcfe
added validations tests for video, all passed
GeMath18 Dec 3, 2020
e95f20a
Merge branch 'gm/videomodeltests'
GeMath18 Dec 3, 2020
9983216
deleted a column available_inventory from rentals
GeMath18 Dec 3, 2020
cf09761
dried our routes
GeMath18 Dec 3, 2020
32d0592
added a test for invalid available_inventory for rental
ichbinorange Dec 4, 2020
0752779
Merge pull request #6 from GeMath18/rental_available_inventory
ichbinorange Dec 4, 2020
fa319d3
added sort params to customers
ichbinorange Dec 4, 2020
ed60ae8
added will_paginate to gemfile
ichbinorange Dec 4, 2020
42a5d77
added paginate params to customers
ichbinorange Dec 4, 2020
1bed27a
fixed non-existing attributes for sorting in customers
ichbinorange Dec 4, 2020
8f53be8
removed default scope for sorting bcz Sorting by ID is the rails default
ichbinorange Dec 4, 2020
f9cbdec
fixed non-existing attributes for pagination in customers
ichbinorange Dec 4, 2020
6a3e352
added tests for sorting/pagination queryparameter in customers
ichbinorange Dec 4, 2020
22bf2df
Merge pull request #7 from GeMath18/query_parameters
ichbinorange Dec 4, 2020
615b632
added only to the before action
ichbinorange Dec 4, 2020
ce41577
Merge pull request #8 from GeMath18/query_parameters
ichbinorange Dec 4, 2020
7e920c5
no changes
GeMath18 Dec 4, 2020
eeb1023
fixing one test on customer controller
GeMath18 Dec 4, 2020
57d8d11
fixed one test on rental controller, all tests passing
GeMath18 Dec 4, 2020
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
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep
.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key
.idea

# Ignore simplecov
coverage/*
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.6.5
63 changes: 63 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.5'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.4'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

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

gem 'will_paginate', '~> 3.1.0'

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.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 :development do
gem 'guard'
gem 'guard-minitest'
gem 'debase', '>= 0.2.4.1'
gem 'ruby-debug-ide', '>= 0.7.0'
end

group :test do
gem 'minitest-rails'
gem 'minitest-reporters'
end

group :test do
gem 'simplecov', require: false
end
220 changes: 220 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (6.0.3.4)
actionpack (= 6.0.3.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.0.3.4)
actionpack (= 6.0.3.4)
activejob (= 6.0.3.4)
activerecord (= 6.0.3.4)
activestorage (= 6.0.3.4)
activesupport (= 6.0.3.4)
mail (>= 2.7.1)
actionmailer (6.0.3.4)
actionpack (= 6.0.3.4)
actionview (= 6.0.3.4)
activejob (= 6.0.3.4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.0.3.4)
actionview (= 6.0.3.4)
activesupport (= 6.0.3.4)
rack (~> 2.0, >= 2.0.8)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.0.3.4)
actionpack (= 6.0.3.4)
activerecord (= 6.0.3.4)
activestorage (= 6.0.3.4)
activesupport (= 6.0.3.4)
nokogiri (>= 1.8.5)
actionview (6.0.3.4)
activesupport (= 6.0.3.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.0.3.4)
activesupport (= 6.0.3.4)
globalid (>= 0.3.6)
activemodel (6.0.3.4)
activesupport (= 6.0.3.4)
activerecord (6.0.3.4)
activemodel (= 6.0.3.4)
activesupport (= 6.0.3.4)
activestorage (6.0.3.4)
actionpack (= 6.0.3.4)
activejob (= 6.0.3.4)
activerecord (= 6.0.3.4)
marcel (~> 0.3.1)
activesupport (6.0.3.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
ansi (1.5.0)
bootsnap (1.5.1)
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.1.7)
crass (1.0.6)
debase (0.2.4.1)
debase-ruby_core_source (>= 0.10.2)
debase-ruby_core_source (0.10.11)
docile (1.3.2)
erubi (1.10.0)
ffi (1.13.1)
formatador (0.2.5)
globalid (0.4.2)
activesupport (>= 4.2.0)
guard (2.16.2)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-minitest (2.4.6)
guard-compat (~> 1.2)
minitest (>= 3.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
listen (3.3.3)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.8.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.2.8)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (1.0.0)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.2)
minitest-rails (6.0.1)
minitest (~> 5.10)
railties (~> 6.0.0)
minitest-reporters (1.4.2)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
msgpack (1.3.3)
nenv (0.3.0)
nio4r (2.5.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
pg (1.2.3)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
puma (4.3.7)
nio4r (~> 2.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.0.3.4)
actioncable (= 6.0.3.4)
actionmailbox (= 6.0.3.4)
actionmailer (= 6.0.3.4)
actionpack (= 6.0.3.4)
actiontext (= 6.0.3.4)
actionview (= 6.0.3.4)
activejob (= 6.0.3.4)
activemodel (= 6.0.3.4)
activerecord (= 6.0.3.4)
activestorage (= 6.0.3.4)
activesupport (= 6.0.3.4)
bundler (>= 1.3.0)
railties (= 6.0.3.4)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.0.3.4)
actionpack (= 6.0.3.4)
activesupport (= 6.0.3.4)
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rake (13.0.1)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
ruby-debug-ide (0.7.2)
rake (>= 0.8.1)
ruby-progressbar (1.10.1)
shellany (0.0.1)
simplecov (0.19.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
spring (2.1.1)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.2)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (1.0.1)
thread_safe (0.3.6)
tzinfo (1.2.8)
thread_safe (~> 0.1)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
will_paginate (3.1.8)
zeitwerk (2.4.2)

PLATFORMS
ruby

DEPENDENCIES
bootsnap (>= 1.4.2)
byebug
debase (>= 0.2.4.1)
guard
guard-minitest
listen (~> 3.2)
minitest-rails
minitest-reporters
pg (>= 0.18, < 2.0)
pry-rails
puma (~> 4.1)
rails (~> 6.0.3, >= 6.0.3.4)
ruby-debug-ide (>= 0.7.0)
simplecov
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data
will_paginate (~> 3.1.0)

RUBY VERSION
ruby 2.6.5p114

BUNDLED WITH
2.1.4
9 changes: 9 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
guard :minitest, autorun: false, spring: true do
watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' }
watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
watch(%r{^test/.+_test.rb$})
watch(%r{^test/test_helper.rb$}) { 'test' }
end
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.
24 changes: 24 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class CustomersController < ApplicationController
before_action :sort_column, only: [:index]
before_action :valid_pagination?, only: [:index]

def index
customers = Customer.all
customers = customers.order(params[:sort] => :asc) if params[:sort]
customers = customers.paginate(page: params[:p], per_page: params[:n]) if params[:p] || params[:n]

render json: customers.as_json(only: [:id, :name, :registered_at, :postal_code, :phone, :videos_checked_out_count]),
status: :ok
end

private

def sort_column
Customer.column_names.include?(params[:sort]) ? params[:sort] : (params[:sort] = "id")
end

def valid_pagination?
params[:p].to_i > 0 ? params[:p] : (params[:p] = nil)
params[:n].to_i > 0 ? params[:n] : (params[:n] = nil)
end
end
Loading