Created
July 6, 2018 14:47
-
-
Save mattmecoli/fef698f3a561f709e3e0dc92d339a62d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Matt Mecoli | |
#CUSTOMER CLASS | |
from lib.review import * | |
class Customer: | |
_all = [] | |
def __init__(self, first_name, last_name): | |
self._first_name = first_name | |
self._last_name = last_name | |
Customer._all.append(self) | |
#CLASSMETHODS | |
@classmethod | |
def all(cls): | |
return cls._all | |
@classmethod | |
def find_by_name(cls, full_name): | |
found_names = [] | |
full_name_split = full_name.split() | |
for customer in cls.all(): | |
if full_name_split[0] == customer.first_name and full_name_split[1] == customer.last_name: | |
return customer | |
#note the potential to break if a full name is not entered as first name space last name | |
#would be good to build in a warning to a user that lets the user know if they've entered | |
#an argument in a form that will break the function | |
@classmethod | |
def find_all_by_first_name(cls, name): | |
return [customer for customer in cls.all() if customer.first_name == name] | |
@classmethod | |
def all_names(cls): | |
return [customer.first_name + ' ' + customer.last_name for customer in cls.all()] | |
#INSTANCEMETHODS | |
def add_review(self, restaurant, rating): | |
new_review = Review(self, restaurant, rating) | |
return new_review | |
#as a note to future developers, this function can only be used once, or it will overwrite | |
#the new_review variable each time. It should be refactored to generate a new and unique review name every time it is used to avoid this potential error. This was outside the time and scope of | |
#this project. | |
#DECORATORS | |
#decorators for _first_name | |
@property | |
def first_name(self): | |
return self._first_name | |
@first_name.setter | |
def first_name(self, first_name): | |
self._first_name = first_name | |
#decorators for _last_name | |
@property | |
def last_name(self): | |
return self._last_name | |
@last_name.setter | |
def last_name(self, last_name): | |
self._last_name = last_name | |
#RESTAURANT CLASS | |
from lib.review import * | |
class Restaurant: | |
pass | |
_all = [] | |
def __init__(self, name): | |
self._name = name | |
Restaurant._all.append(self) | |
#CLASSMETHODS | |
@classmethod | |
def all(cls): | |
return cls._all | |
@classmethod | |
def find_by_name(cls, name): | |
for restaurant in cls.all(): | |
if name == restaurant.name: | |
return restaurant | |
#INSTANCEMETHODS | |
def reviews(self): | |
return [review for review in Review.all() if review.restaurant == self] | |
def customers(self): | |
return [review.customer for review in self.reviews()] | |
#DECORATORS | |
#decorators for _name | |
@property | |
def name(self): | |
return self._name | |
@name.setter | |
def name(self, name): | |
self._name = name | |
#REVIEWS CLASS | |
class Review: | |
_all = [] | |
def __init__(self, customer, restaurant, rating): | |
self._customer = customer | |
self._restaurant = restaurant | |
self._rating = rating | |
Review._all.append(self) | |
#CLASSMETHODS | |
@classmethod | |
def all(cls): | |
return cls._all | |
#DECORATORS | |
#decorators for _customer | |
@property | |
def customer(self): | |
return self._customer | |
@customer.setter | |
def customer(self, customer): | |
self._customer = customer | |
#decorators for _restaurant | |
@property | |
def restaurant(self): | |
return self._restaurant | |
@restaurant.setter | |
def restaurant(self, restaurant): | |
self._restaurant = restaurant | |
#decorators for _rating | |
@property | |
def rating(self): | |
return self._rating | |
@rating.setter | |
def rating(self, rating): | |
self._rating = rating |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment