Welcome to your good old neighborhood VHS store. You will build an app that tracks the store inventory, the rentals and the clients. Prepare for the 80s nostalgia.
You will be working on a six-model domain: Client
, Rental
, Dvd
, Movie
, MovieGenre
, Genre
. The associations are as follows:
- Genre has many movie_genres and movies through movie_genres,
- MovieGenre belongs to a movie and a genre,
- Movie has many movie_genres and genres through movie_genres,
- Movie has many dvds and rentals through dvds,
- Dvd belongs to a movie,
- Dvd has many rentals and clients through rentals,
- Rental belongs to a client and dvd,
- Client has many rentals and dvds through rentals.
NOTE that the below ERD does not include foreign keys -- these you need to add on your own, together with the accosiation macros.
Client
|
^
Rental
V
|
|
Dvd >---- Movie ----< MovieGenre >---- Genre
- Carefully read the readme.
- Fork and clone this lab.
- Run
bundle
. - Check the code you have been given: see
app/models
and files in it (is there a class for every model? are all the associations set up?), seedb/schema
, seerb/seeds.rb
. Runrake db:migrate:status
to see if there are any pending migrations -- if there are, check these files and see if you need to add anything before migrating it. - Now that you know what is missing, DO NOT CODE JUST YET. Discuss with your partner the plan for the setup: what are you going to do step by step and how are you going to test if it worked.
- Run
rake -T
and see what process reminder tasks are available to you (they are marked with "🎁"). - Start coding the setup. Test your code frequently.
- After all your models are hooked up correctly, choose minimum five deliverables from the list below. You need to have at least one deliverable for each of the CRUD actions. The only compulsory deliverable is
Client.paid_most
(it's a read action). - After you've chosen the deliverables, tackle one by one. Majority of them require helper methods, the use of
binding.pry
, and a good amount of pseudocoding. When writing helper methods, please remember that:
- each method should do JUST ONE JOB,
- each method name should be descriptive,
- it's alway best think about where the method should live; for instance: is it a behavior of a Client? or is it a behavior of a Dvd instance and should be called from within an instance method of a Client?
NOTE: all deliverables will make you a strong dev and will allow you for a good practice on ActiveRecord. Please spend some time on this lab, together with your partner or on your own. This lab can also be developed into a CLI that can serve as a strong portfolio piece or blog post material.
Build the following functionality:
Rental#due_date
- returns a date one week from when the record was createdRental.past_due_date
- returns a list of all the rentals past due date
Client.most_active
- returns a list of top 5 most active clients (i.e. those who had the most non-current / returned rentals)Client#favorite_genres
- lists three genres that the client rented the mostClient.non_grata
- returns a list of all the clients who have a dvd past the due date (or, more difficult: who ever missed the return date)Client#return_one
- accepts an argument of a movie instance, finds the corresponding rental and updates the rental'scurrent
attribute fromtrue
tofalse
Client#return_all
- updatescurrent
attribute fromtrue
tofalse
on all client's rentalsClient.paid_most
- returns an instance who has spent most money at the store; one rental is $5,35 upfront (bonus: additional $12 charge for every late return — do not count those that have not yet been returned)Client.total_watch_time
- returns an Integer of all movies watched by the all clients combined (assume that a rented movie is a watched movie)
Dvd.most_used
- prints a list of 3 dvds that have been most rented in the format: "serial number: 1111111 | title: 'movie title'Dvd.all_genres
- returns a list of all genres available at the storeDvd.available_now
- returns a list of all dvds currently available at the storeDvd.hot_from_the_press
- accepts arguments used to create a new instance of aMovie
and a name of a genre; creates the movie, associates it with appropriate genre and creates three instances of aDvd
associated with that Movie
Movie.most_clients
- returns a list of TOP3 All Time favorites based on number of different clients who watched itMovie.most_rentals
- returns a list of TOP3 All Time favorites based on number of rentalsMovie.newest_first
- returns a list of all the movies from the most recent ones to the oldies but goldies based on the release yearMovie.longest
- returns a list of the movies from the longest to the shortestMovie#recommendation
- prints a recommendation that includes a random emoji, the movie description, its length, director and year of releaseMovie.surprise_me
- prints a recommendation for a random movieMovie#report_stolen
- deletes a random dvd instance associated with this movie that's currently not rented out and prints information: "THANK YOU FOR YOUR REPORT. WE WILL LAUNCH AN INVESTIGATION."
Genre.most_popular
- returns a list of 5 most popular genres based on number of moviesGenre.longest_movies
- returns a genre whose movies length average is the highest
shop_fun_statistics
- should print out information about the store: how many DVDs there are in total, how many clients, how many movies available at this store (not all Movies in the database are available), how many genres, how much time clients watched the movies in total, what genre is the most popular among the clients, etc.