Code Monkey home page Code Monkey logo

arshavineroy / sqlalchemy-code-challenge Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 127 KB

A restaurant review system built with Python and utilizes SQLAlchemy and Alembic Migrations, SQLAlchemy Relationships, Class and Instance Methods, and SQLAlchemy Querying in a Yelp-style domain with three models: Restaurant, Review, and Customer.

License: MIT License

Python 96.08% Mako 3.92%
alembic object-oriented-programming python3 sqlalchemy sqlalchemy-database-migrations sqlalchemy-models sqlalchemy-orm sqlalchemy-orm-queries

sqlalchemy-code-challenge's Introduction

Restaurant Review System with SQLAlchemy

Phase 3 Week 3 Code Challenge

license python version SQLAlchemy version alembic version faker version platforms


Introduction

This is a Restaurant Review System built with Python and utilizes SQLAlchemy and Alembic Migrations, SQLAlchemy Relationships, Class and Instance Methods, and SQLAlchemy Querying working with a Yelp-style domain with three models: Restaurant, Review, and Customer.

NOTE: Some methods in the deliverables have been changed so they don't conflict with table names.


Table of Contents


Prerequisites

The packages are included in the Pipfile, and can be installed through it into the virtual environment.

  • Python3 v3.10 +

  • SQLAlchemy v2.0.20

  • Alembic v1.12.0

  • Faker v19.3.1


Features

  • Create and manage customer and restaurant profiles
  • Add, retrieve, and delete reviews for restaurants
  • Find customers and restaurants based on reviews
  • Retrieve a list of all reviews
  • Find the fanciest restaurant in the list
  • Find a customer's favorite restaurant

Project Setup

1. Clone the repository

git clone https://github.com/ArshavineRoy/sqlalchemy-code-challenge

2. Navigate to the project's directory

cd sqlalchemy-code-challenge

3. Install required dependencies

The root directory of this repository contains the Pipfile with all the required dependencies. To install them into your virtual environment, run this command from the root directory:

pipenv install

If pipenv is not already installed, you can do so using pip:

pip install pipenv

4. Activate the virtual environment

pipenv shell

5. Navigate into the app directory

Run all commands from within this directory

cd app

5. Run main.py for testing

./main.py

Entity Relationship Diagram

The Restaurant Review System uses the Association Object Models for the associations and relationships between the three models: Restaurant, Customer, and Reviews.

A Restaurant has many Reviews, a Customer has many Reviews, and a Review belongs to a Restaurant and to a Customer. The ERD below shows these relationships:

ERD


Usage

You can use the Restaurant Review System to simulate interactions between customers, restaurants, and reviews to:

  1. Create customer and restaurant instances.
  2. Add reviews using the add_review method.
  3. Retrieve information about customers, restaurants, and reviews using the provided methods.

For example, you should be able to call session.query(Customer).first().all_restaurants() and see a list of the restaurants for the first customer in the database based on your seed data; and session.query(Review).first().customer should return the customer for the first review in the database.

Methods

Use the seed.py file to create sample data to test the models and relationships by the following methods.

Restaurant


self.all_reviews()

  • changed from self.reviews() in deliverables

  • returns a collection of all the reviews for the Restaurant

self.all_customers()

  • changed from self.customers() in deliverables.

  • returns a collection of all the customers who reviewed the Restaurant

cls.fanciest()

  • A class method that returns one restaurant instance for the restaurant that has the highest price

self.all_reviews_formatted()

  • returns a list of strings with all the reviews for this restaurant in the following format:
[ "Review for {insert restaurant name} by {insert customer's full name}: {insert review star_rating} stars.",

"Review for {insert restaurant name} by {insert customer's full name}: {insert review star_rating} stars.", ]

Customer


self.all_reviews()

  • changed from self.reviews() in deliverables.

  • returns a collection of all the reviews that the Customer has left

self.all_restaurants()

changed from self.restaurants() in deliverables.

  • returns a collection of all the restaurants that the Customer has reviewed

self.full_name()

  • returns the full name of the customer, with the first name and the last name concatenated, Western style.

self.favorite_restaurant()

  • returns the restaurant instance that has the highest star rating from this customer

self.add_review(restaurant, rating)

  • takes a restaurant (an instance of the Restaurant class) and a rating

  • creates a new review for the restaurant with the given restaurant_id

self.delete_reviews(restaurant)

  • takes a restaurant (an instance of the Restaurant class) and

  • removes all their reviews for this restaurant

Review


review.customer()

  • returns the Customer instance for this review

review.restaurant()

  • returns the Restaurant instance for this review

review.full_review()

  • returns a string in the following format:
Review for {insert restaurant name} by {customer full_name}: {review star_rating} stars.

Author & License

Authored by Arshavine Waema.

Licensed under the MIT License - see the LICENSE file for details.

sqlalchemy-code-challenge's People

Contributors

arshavineroy 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.