GithubHelp home page GithubHelp logo

activerecord-vhs-store's Introduction

ActiveRecord VHS Store

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.


Associations

You will be working on a six-model domain: Client, Rental, Vhs, 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 vhs and rentals through vhs,
  • Vhs belongs to a movie,
  • Vhs has many rentals and clients through rentals,
  • Rental belongs to a client and vhs,
  • Client has many rentals and vhs through rentals.

ERD

NOTE that the below ERD does not include foreign keys -- these you need to add on your own, together with the association macros.

  Client 
    |
    ^
  Rental                  
    V
    |
    |
  Vhs >---- Movie ----< MovieGenre >---- Genre

Domain model


Getting Started

  1. Carefully read the readme.
  2. Fork and clone this lab.
  3. Run bundle.
  4. 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?), see db/schema, see rb/seeds.rb. Run rake 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.

NOTE ABOUT THE SEEDS: the seeds have been commented out -- uncomment it once you've built out your migrations and associations.Also, as you can see in the file, seeds rely on a significant amount of randomness so if you work with another person and do not share the same database, you WILL get different results in terms of number of associated instances or number of instances in general.

  1. 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.
  2. You must have noticed that one of the models is called Vhs. In rake console run:
'vhs'.pluralize
'vhs'.singularize

As you see, ActiveRecord perceives this word as already pluralized and it will pose problems when you're trying to apply .vhs method on e.g. a Movie instance (AR will look for a singularized model of Vh). To prevent this, let's tell AR that this word is the same singular as plural -- paste this in config/environment.rb:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'vhs', 'vhs'
end
  1. Run rake -T and see what process reminder tasks are available to you (they are marked with "๐ŸŽ").
  2. Start coding the setup. Test your code frequently.
  3. 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). The deliverables marked with "โญ๏ธ" require a bit more of pseudocoding and binding.pry.
  4. After you've chosen the deliverables, tackle one by one. Majority of them require helper methods (yes, plural), 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 always best think about where the method should live; for instance: is it a behavior of a Client? or is it a behavior of a Vhs 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. Check out Danny Sasse's blog post on how his pairing partner and he implemented DRY solution.

SECOND NOTE: Please know that there is the basic solution authored by me and a solution that involves moduls authored by Danny Sasse and Simon Jacobs. Feel free to check them once you're done or if you're stuck -- they are there for you to learn from!


Functionality

Build the following functionality:

Rental

READ

  • Rental#due_date - returns a date one week from when the record was created
  • Rental.past_due_date - returns a list of all the rentals past due date, currently rented or rented in the past

Client

CREATE

  • Client.first_rental - accepts and instance of arguments needed to create a new Client instance and a currently available Vhs instance (or, more difficult: a Movie instance or just a Movie title and on that basis chooses a currently available vhs); it creates a new Client instance and a new Rental instance with current set to true.

READ

  • 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_genre โญ๏ธ - puts the name of the genre that the client rented the most; in counting how many times a person watched a genre, you can treat two rentals of the same movie as two separate instances;
  • Client.non_grata - returns a list of all the clients who have a vhs past the due date (or, more difficult: who ever missed the return date)
  • Client.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)

UPDATE

  • Client#return_one - accepts an argument of an vhs instance, finds the corresponding rental and updates the rental's current attribute from true to false
  • Client#return_all- updates current attribute from true to false on all client's rentals

UPDATE AND DELETE

  • Client#last_return - updates all Client' rentals current to false and deletes the Client from the database

Vhs

CREATE

  • Vhs.hot_from_the_press - accepts arguments used to create a new instance of a Movie and a name of a genre; creates the movie, associates it with appropriate genre (if it exists, if it doesn't - creates one) and creates three instances of a Vhs associated with that Movie

READ

  • Vhs.most_used - prints a list of 3 vhs that have been most rented in the format: "serial number: 1111111 | title: 'movie title'
  • Vhs.all_genres - returns a list of all genres available at the store
  • Vhs.available_now - returns a list of all vhs currently available at the store

Movie

READ

  • Movie.available_now - returns a list of all movies currently available at the store
  • Movie.most_clients โญ๏ธ - returns an instance of Movie that has been rented by the most people
  • Movie.most_rentals - returns a list of TOP3 All Time favorites based on number of rentals
  • Movie.most_popular_female_director - returns a string that's a name of a director of the movie made by a female director with most Rentals
  • Movie.newest_first - returns a list of all the movies from the most recent ones to the oldies but goldies based on the release year
  • Movie.longest - returns a list of the movies from the longest to the shortest
  • Movie#recommendation - prints a recommendation that includes a random emoji next to the title, and in new lines: the movie description, its length, director and year of release
  • Movie.surprise_me - prints a recommendation for a random movie

DELETE

  • Movie#report_stolen - deletes a random vhs 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

READ

  • Genre.most_popular - returns a list of 5 most popular genres based on number of movies
  • Genre.longest_movies - returns a genre whose movies length average is the highest (remember to also test it with an instance of a Genre that does not have any movies associated)

Contributing

Did you find a bug? A typo? Do you have an idea for a new hot deliverable? Are you proud of a solution you've submitted and would like it to be featured as a branch here? Please create an issue describing what change you'd like to see and whether you'd like to code it. Wait for my response and if it's a ๐Ÿ‘, go ahead: fork the repo, write code and open a PR with a description of changes.

โœจ Shoutout to Danny Sasse for finding a squishing a bug in seeds!

โœจ Shoutout to Danny Sasse and Simon Jacobs for providing an alternative solution that involves modules and code that follows DRY principle.

activerecord-vhs-store's People

Contributors

dsasse07 avatar sylwiavargas avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.