-
Notifications
You must be signed in to change notification settings - Fork 19
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
bo and sai's video store API #16
base: master
Are you sure you want to change the base?
Conversation
made new empty api app
baseline with test route
added gems needed for testing and error views
generated models for movies and customers
Modify models
Model tests
Add controllers
Bt update rentals test
added some tests
wrote controller action for rental create and updated tests
updated tests and controller logic
Rental logic inventory
Update rental controller test
Update customer custom method
WIP overdue action in rental controller
… due date of next available movie
Sandbox overdue
Video StoreWhat We're Looking For
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great job! I didn't find any glaring issues or anything, keep up the great work 💯
validates :title, presence: true | ||
validates :overview, presence: true | ||
validates :release_date, presence: true, format: { with: /\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])\z/, message: "must be in YYYY-MM-DD format" } | ||
validates :inventory, presence: true, numericality: { only_integer: true, greater_than: 0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great job with the validations!
if movie.available_inventory <= 0 | ||
rentals = Rental.where(movie_id: movie.id) | ||
earliest = rentals.min_by { |rental| rental.due_date} | ||
errors.add(:availability, "Sorry, this movie is not in stock. One is due back on #{earliest.due_date}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting the earliest due date is a nice touch 👍
@@ -0,0 +1,146 @@ | |||
require "test_helper" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay tests! I dig how thorough these ones are 🎉
|
||
one: | ||
title: Titanic | ||
overview: ship disaster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg these movie overviews 😂
overdue_rentals = [] | ||
customer_ids.each do |id| | ||
customer = Customer.find_by_id(id) | ||
hash = Hash.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency you could do {} (since you do [] for a new array)...but this is me completely nitpicking bc you did such a great job 😁
end | ||
|
||
def overdue | ||
#what is the syntax for a conditional for due date? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to clean up comments! 🔍
end | ||
|
||
def valid_due_date | ||
if due_date.class != Date |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you take in the due date? Would checking if the due date is too far in the future (like if I tried to check something out for 2183721983 years) be necessary?
|
||
# Ignore Byebug command history file. | ||
.byebug_history | ||
/coverage/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also ignore that pesky .DS_Store
|
||
|
||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | ||
gem 'rails', '~> 5.0.2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh that's why some of this looks weird to me, shiny new rails! ✨ (we used 4.2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same reaction!
|
||
def check_inventory | ||
if movie | ||
if movie.available_inventory <= 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the avail inventory ever go below 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic job - it looks like you both went above and beyond the requirements and learned a lot about building an API. nice work. :)
|
||
|
||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | ||
gem 'rails', '~> 5.0.2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same reaction!
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem | ||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] | ||
|
||
group :development do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you have two 'group :development do' sections - you could combine them to clean up the Gemfile.
|
||
# update later after adding rental | ||
def movies_checked_out_count | ||
return rentals.where(returned: false).length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job pulling out business logic into models. Good work on being thorough with validations.
value(response).must_be :success? | ||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, I can tell that you really put a lot of time into writing thorough tests. Nice job testing edge cases as well.
Video Store API
Congratulations! You're submitting your assignment!
If you didn't get to the functionality the question is asking about, reply with what you would have done if you had completed it.
Comprehension Questions