Skip to content

Commit

Permalink
Merge pull request #9 from Matsadura/db_models
Browse files Browse the repository at this point in the history
[UPDATE] Change DB Schema
  • Loading branch information
naanaa59 authored Sep 11, 2024
2 parents 2cc23ce + 9f5d3f4 commit 24ff1b3
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 55 deletions.
1 change: 1 addition & 0 deletions server/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
app.register_blueprint(app_views)
HOST = "0.0.0.0"
PORT = 5000
SECRET_KEY = os.getenv('SECRET_KEY')


@app.route('/volumes')
Expand Down
8 changes: 4 additions & 4 deletions server/api/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def status():
def stats():
"""Return the count of all classes"""
from models.user import User
from models.mood import Mood
from models.recommendation import Recommendation
from models.movie import Movie
from models.user_movie import User_Movie
from models import storage

return {"Users": storage.count(User),
"Moods": storage.count(Mood),
"Recommendations": storage.count(Recommendation)
"Movies": storage.count(Movie),
"User_Movies": storage.count(User_Movie)
}
6 changes: 3 additions & 3 deletions server/models/engine/db_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"""

from models.base_model import BaseModel, Base
from models.mood import Mood
from models.recommendation import Recommendation
from models.movie import Movie
from models.user_movie import User_Movie
from models.user import User
from os import getenv
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

classes = {"Mood": Mood, "Recommendation": Recommendation, "User": User}
classes = {"Movie": Movie, "User_Movie": User_Movie, "User": User}


class DBStorage:
Expand Down
18 changes: 0 additions & 18 deletions server/models/mood.py

This file was deleted.

18 changes: 18 additions & 0 deletions server/models/movie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
"""Holds class Movie"""
from models.base_model import BaseModel, Base
from sqlalchemy import Column, String
from sqlalchemy.orm import relationship


class Movie(BaseModel, Base):
"""Representation of a user """
__tablename__ = 'movies'
movie = Column(String(60), nullable=False)
user_movies = relationship("User_Movie",
back_populates="movie",
cascade="all, delete-orphan")

def __init__(self, *args, **kwargs):
"""Initializes user"""
super().__init__(*args, **kwargs)
26 changes: 0 additions & 26 deletions server/models/recommendation.py

This file was deleted.

8 changes: 4 additions & 4 deletions server/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class User(BaseModel, Base):
password = Column(String(128), nullable=False)
first_name = Column(String(128), nullable=False)
last_name = Column(String(128), nullable=False)
recent_mood = Column(String(24), nullable=False)
recommendations = relationship("Recommendation",
back_populates="user",
cascade="all, delete-orphan")
avatar = Column(String(256), nullable=True)
user_movies = relationship("User_Movie",
back_populates="user",
cascade="all, delete-orphan")

def __init__(self, *args, **kwargs):
"""Initializes user"""
Expand Down
24 changes: 24 additions & 0 deletions server/models/user_movie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
"""Holds class User_Movie"""
from models.base_model import BaseModel, Base
from sqlalchemy import Column, String, Boolean, ForeignKey
from sqlalchemy.orm import relationship


class User_Movie(BaseModel, Base):
"""Representation of a vault """
__tablename__ = 'user_movies'
user_id = Column(String(128),
ForeignKey('users.id', ondelete='CASCADE'),
nullable=False)
movie_id = Column(String(128),
ForeignKey('movies.id', ondelete='CASCADE'),
nullable=False)
seen = Column(Boolean, nullable=True)
like = Column(Boolean, nullable=True)
movie = relationship("Movie", back_populates="user_movies")
user = relationship("User", back_populates="user_movies",)

def __init__(self, *args, **kwargs):
"""initializes vault"""
super().__init__(*args, **kwargs)

0 comments on commit 24ff1b3

Please sign in to comment.