Exemplo n.º 1
0
 def __init__(self, action_type, movie_id, user_id, created, updated):
     self.action_type = action_type
     self.movie_id = movie_id
     self.user_id = user_id
     self.created = created
     self.updated = updated
     self.engine = init_sqlalchemy_engine()
Exemplo n.º 2
0
 def __init__(self, first_name, last_name, email, password, created,
              updated):
     self.first_name = first_name
     self.last_name = last_name
     self.email = email
     self.password = password
     self.created = created
     self.updated = updated
     self.engine = init_sqlalchemy_engine()
Exemplo n.º 3
0
 def delete(action_id):
     """
     Deletes action record from Database
     :param action_id: int
     """
     Session = sessionmaker(bind=init_sqlalchemy_engine())
     session = Session()
     session.query(Action).filter(Action.id == action_id).delete()
     session.commit()
Exemplo n.º 4
0
    def check_movie_exists(title):
        """
        Checks if movie exists in Database based on title
        :param title: string
        :return: boolean
        """
        Session = sessionmaker(bind=init_sqlalchemy_engine())
        session = Session()
        results = session.query(Movie).filter(Movie.title == title.casefold()).count()

        return True if results == 0 else False
Exemplo n.º 5
0
 def __init__(self, title, description, posted_by, created, updated, full_name=None, likes=None, dislikes=None):
     self.title = title
     self.description = description
     self.posted_by = posted_by
     self.created = created
     self.updated = updated
     self.full_name = full_name
     self.likes = likes
     self.dislikes = dislikes
     self.tdiff = []
     self.engine = init_sqlalchemy_engine()
     self.mysql_engine = init_mysql_db()
Exemplo n.º 6
0
    def check_email_exists(email):
        """
        Checks if email exists on Database
        :param email: string
        :return: boolean
        """
        Session = sessionmaker(bind=init_sqlalchemy_engine())
        session = Session()
        results = session.query(User).filter(
            User.email == email.casefold()).count()

        return True if results == 0 else False
Exemplo n.º 7
0
    def select_by_user_id(user_id):
        """
        Selects user record based on user id from Database
        :param user_id: int
        :return: user: dict
        """
        Session = sessionmaker(bind=init_sqlalchemy_engine())
        session = Session()
        results = session.query(User).filter(User.id == user_id).first()

        if not results:
            print('User not found')
            return

        user = {
            'id': results.id,
            'first_name': results.first_name,
            'last_name': results.last_name
        }
        return user
Exemplo n.º 8
0
    def select_by_email(email):
        """
        Selects user record based on email from Database
        :param email: string
        :return: user: dict
        """
        Session = sessionmaker(bind=init_sqlalchemy_engine())
        session = Session()
        results = session.query(User).filter(User.email == email).first()

        if not results:
            print('User not found')
            return

        user = {
            'id': results.id,
            'first_name': results.first_name,
            'last_name': results.last_name,
            'password': results.password
        }
        return user
Exemplo n.º 9
0
    def select_user_preferences(user_id):
        """
        Selects the action records based on user id from Database
        :param user_id: int
        :return: results_action : list of dicts
        """
        Session = sessionmaker(bind=init_sqlalchemy_engine())
        session = Session()
        results = session.query(Action).filter(Action.user_id == user_id).all()
        results_actions = []
        for r in results:
            action = {
                'id': r.id,
                'action_type': r.action_type,
                'movie_id': r.movie_id,
                'user_id': r.user_id,
                'created': r.created,
                'updated': r.updated
            }
            results_actions.append(action)

        return results_actions
Exemplo n.º 10
0
from app.database.action import Action
from app.database.movie import Movie
from app.database.user import User

from app.database.utilities import init_sqlalchemy_engine, Base

if __name__ == "__main__":
    engine = init_sqlalchemy_engine()
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)