Git Product home page Git Product logo

p3-cc-rs's Introduction

Object Relations Code Challenge - Restaurants

For this assignment, we'll be working with a Yelp-style domain.

We have three models: Restaurant, Customer, and Review.

For our purposes, a Restaurant has many Reviews, a Customer has many Reviews, and a Review belongs to a Customer and to a Restaurant.

Restaurant - Customer is a many to many relationship.

Note: You should draw your domain on paper or on a whiteboard before you start coding. Remember to identify a single source of truth for your data.

Instructions

To get started, run pipenv install while inside of this directory.

Build out all of the methods listed in the deliverables. The methods are listed in a suggested order, but you can feel free to tackle the ones you think are easiest. Be careful: some of the later methods rely on earlier ones.

Remember! This code challenge has tests to help you check your work. You can run pytest to make sure your code is functional before submitting.

We've also provided you with a tool that you can use to test your code. To use it, run python debug.py from the command line. This will start a ipdb session with your classes defined. You can test out the methods that you write here. You can add code to the debug.py file to define variables and create sample instances of your objects.

Writing error-free code is more important than completing all of the deliverables listed - prioritize writing methods that work over writing more methods that don't work. You should test your code in the console as you write.

Similarly, messy code that works is better than clean code that doesn't. First, prioritize getting things working. Then, if there is time at the end, refactor your code to adhere to best practices. When you encounter duplicated logic, extract it into a shared helper method.

Before you submit! Save and run your code to verify that it works as you expect. If you have any methods that are not working yet, feel free to leave comments describing your progress.

Deliverables

Write the following methods in the classes in the files provided. Feel free to build out any helper methods if needed.

Initializers, Readers, and Writers

For any invalid inputs raise an Exception. In your future work, you should raise specific types of exceptions for specific error cases. You can do that here and the tests will pass, but you don't have to this time around!

Customer

  • Customer __init__(self, first_name, last_name)
    • Customer should be initialized with a given name and family name, (i.e., first and last name, like George Washington)"
  • Customer property first_name and Customer property last_name
    • Return first and last name, respectively
    • Names must be of type str
    • Names must be between 1 and 25 characters, inclusive
  • Customer property full_name
    • Return first and last name in one string, separated by a space. (i.e., "George Washington")

Restaurant

  • Restaurant __init__(self, name)
    • Restaurants should be initialized with a name, as a string
  • Restaurant property name
    • Returns the restaurant's name
    • Should not be able to change after the restaurant is created
  • `

Review

  • Review __init__(self, customer, restaurant, rating)
    • Reviews should be initialized with a customer, restaurant, and a rating (a number)
  • Review property rating
    • Returns the rating for a restaurant
    • Rating must be a number between 1 and 5, inclusive

Object Relationships

Review

  • Review customer
    • Returns the customer object for that review
    • Must be of type Customer
  • Review restaurant
    • Returns the restaurant object for that given review
    • Must be of type Restaurant

Restaurant

  • Restaurant property reviews
    • Returns a list of all reviews for that restaurant
    • Reviews must be of type Review
  • Restaurant proptery customers
    • Returns a unique list of all customers who have reviewed a particular restaurant.
    • Customers must be of type Customer

Customer

  • Customer property restaurants
    • Returns a unique list of all restaurants a customer has reviewed
  • Customer property reviews
    • Returns a list of all reviews a customer has written

Aggregate and Association Methods

Customer

  • Customer num_reviews()
    • Returns the total number of reviews that a customer has authored
  • Customer create_review(restaurant, rating)
    • given a restaurant object and a star rating (as an integer), creates a new review and associates it with that customer and restaurant.

Restaurant

  • Restaurant average_star_rating()

    • Returns the average star rating for a restaurant based on its reviews
    • Reminder: you can calculate the average by adding up all the ratings and dividing by the number of ratings
  • Restaurant get_all_restaurants() classmethod

    • Returns a list of all restaurants

p3-cc-rs's People

Contributors

kmluther avatar marcmajcher avatar hihijazi 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.