Skip to content

Commit

Permalink
Task
Browse files Browse the repository at this point in the history
  • Loading branch information
OluwaninsolaAO committed Apr 22, 2023
1 parent c02c132 commit 24f8420
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
12 changes: 7 additions & 5 deletions models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

class BaseModel:
"""A base class for all hbnb models"""
id = Column(String(60), nullable=False, primary_key=True)
created_at = Column(DateTime, nullable=False,
default=datetime.utcnow())
updated_at = Column(DateTime, nullable=False,
default=datetime.utcnow())

if os.environ.get('HBNB_TYPE_STORAGE') == 'db':
id = Column(String(60), nullable=False, primary_key=True)
created_at = Column(DateTime, nullable=False,
default=datetime.utcnow())
updated_at = Column(DateTime, nullable=False,
default=datetime.utcnow())

def __init__(self, *args, **kwargs):
"""Instatntiates a new model"""
Expand Down
14 changes: 11 additions & 3 deletions models/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ class Place(BaseModel, Base):
latitude = 0.0
longitude = 0.0
amenity_ids = []
reviews = []

@property
def reviews(self):
"""A getter for reviews"""
return [review for review in self.reviews if
review.place_id == self.id]
from models.review import Review
from models import storage

reviews = storage.all(Review)
result = []

for review in reviews.values():
if review.place_id == self.id:
result.append(review)

return result

@property
def amenities(self):
Expand Down
17 changes: 11 additions & 6 deletions models/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
class Review(BaseModel, Base):
""" Review classto store review information """

__tablename__ = 'reviews'
if os.environ.get('HBNB_TYPE_STORAGE') == 'db':
__tablename__ = 'reviews'

place_id = Column(String(60), ForeignKey('places.id'),
nullable=False)
user_id = Column(String(60), ForeignKey('users.id'),
nullable=False)
text = Column(String(1024), nullable=False)
place_id = Column(String(60), ForeignKey('places.id'),
nullable=False)
user_id = Column(String(60), ForeignKey('users.id'),
nullable=False)
text = Column(String(1024), nullable=False)
else:
place_id = ""
user_id = ""
text = ""

0 comments on commit 24f8420

Please sign in to comment.