Exemple #1
0
class ItemDto(db.Model):
    __tablename__ = 'items'
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    item_id: int = db.Column(db.Integer, primary_key=True, index=True)
    name: str = db.Column(db.String(30))
    price: str = db.Column(db.String(30))

    # articles = db.relationship('ArticleDto', lazy='dynamic')

    def __init__(self, item_id, name, price):
        self.item_id = item_id
        self.name = name
        self.price = price

    def __repr__(self):
        return f'Item(item_id={self.item_id}, name={self.name}, price={self.price})'

    @property
    def json(self):
        return {'itemId': self.item_id, 'name': self.name, 'price': self.price}

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Exemple #2
0
class ActorDto(db.Model):

    __tablename__ = 'actors'
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    id: int = db.Column(db.Integer, primary_key=True, index=True)
    sample1: str = db.Column(db.String(30))
    sample2: str = db.Column(db.String(30))

    def __init__(self, id, sample1, genre):
        self.id = id
        self.sample1 = sample1
        self.sample2 = sample2

    def __repr__(self):
        return f'Movie(id=\'{self.id}\',\
            sample1=\'{self.sample1}\',\
            sample2=\'{self.sample2}\',)'

    @property
    def json(self):
        return {
            'id': self.id,
            'sample1': self.sample1,
            'sample2': self.sample2
        }

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Exemple #3
0
class ActorDto(db.Model):
    __tablename__ = 'actors'
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    # columns=['photoUrl', 'age','name','realName','religion','agency', 'spouse', 'children','debutYear','actorid']
    actorid: str = db.Column(db.String(30), primary_key=True, index=True)
    photoUrl: str = db.Column(db.String(200))
    name: str = db.Column(db.String(30))
    age: str = db.Column(db.String(30))
    realName: str = db.Column(db.String(30))
    religion: str = db.Column(db.String(30))
    agency: str = db.Column(db.String(30))
    spouse: str = db.Column(db.String(30))
    children: str = db.Column(db.String(30))
    debutYear: int = db.Column(db.Integer)

    def __init__(self, photoUrl, actorid, name, age, realName, spouse,
                 children, debutYear, agency, religion):
        self.photoUrl = photoUrl
        self.actorid = actorid
        self.name = name
        self.age = age
        self.realName = realName
        self.religion = religion
        self.agency = agency
        self.spouse = spouse
        self.children = children
        self.debutYear = debutYear

    # def __repr__(self):
    #     return f'Actors(id={self.id}, user={self.userid}, \
    #             password={self.password}, name={self.name})'

    @property
    def json(self):
        return {
            'photoUrl': self.photoUrl,
            'actorid': self.actorid,
            'name': self.name,
            'age': self.age,
            'realName': self.realName,
            'spouse': self.spouse,
            'children': self.children,
            'debutYear': self.debutYear,
            'religion': self.religion,
            'agency': self.agency
        }

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit
class UserDto(db.Model):  # 여기서 DB 모델 만든 것
    """
    [Creates User Model and corresponding table]
    """
    __tablename__ = 'users'  # 테이블 이름
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    # The __table_args__ attribute allows passing extra arguments to that Table

    # Creates table columns
    usr_id: str = db.Column(db.String(30), primary_key=True, index=True)
    password: str = db.Column(db.String(30))
    fname: str = db.Column(db.String(30))
    lname: str = db.Column(db.String(30))
    age: int = db.Column(db.Integer)
    gender: str = db.Column(db.String(30))
    email: str = db.Column(db.String(80), unique=True)

    def __init__(self, usr_id, password, fname, lname, age, gender, email):
        """
        Recives 7 parameters that are used to construct User Table
        user_id = 유저 고유 아이디 (Unique)
        password = 비밀번호
        fname = 성
        lname = 이름
        age = 나이
        gender = 성별
        email = 이메일 -> 나중에는 이메일이 아이디로 사용될 것 그래서 이것도 (Unique)
        """
        self.usr_id = usr_id
        self.password = password
        self.fname = fname
        self.lname = lname
        self.age = age
        self.gender = gender
        self.email = email

    def json(self):
        """
        UserDto (User 모델)이 주어지면 json file 로 리턴한다 
        """
        return {
            'usr_id': self.usr_id,
            'password': self.password,
            'lname': self.lname,
            'age': self.age,
            'fname': self.fname,
            'gender': self.gender,
            'email': self.email
        }

    def __str__(self):
        """
        User id 를 리턴한다
        """
        return self.usr_id
Exemple #5
0
class ReviewDto(db.Model):
    __tablename__ = "reviews"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    rev_id: int = db.Column(db.Integer, primary_key=True, index=True)
    title: str = db.Column(db.String(100))
    content: str = db.Column(db.String(500))
    label: int = db.Column(db.Integer)

    usr_id: str = db.Column(db.String(30), db.ForeignKey(UserDto.usr_id))
    mov_id: int = db.Column(db.Integer, db.ForeignKey(MovieDto.mov_id))

    # movie = db.relationship('MovieDto', back_populates="reviews")

    def __init__(self, title, content, label, usr_id, mov_id):
        self.title = title
        self.content = content
        self.label = label
        self.usr_id = usr_id
        self.mov_id = mov_id

    def __repr__(self):
        return f'rev_id = {self.rev_id}, usr_id = {self.usr_id}, mov_id = {self.mov_id},\
            title = {self.title}, content = {self.content}, label = {self.label}'

    def json(self):
        return {
            'rev_id': self.rev_id,
            'usr_id': self.usr_id,
            'mov_id': self.mov_id,
            'title': self.title,
            'content': self.content,
            'label': self.label
        }
Exemple #6
0
class ReviewDto(db.Model):
    __tablename__ = "reviews"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    id: int = db.Column(db.Integer, primary_key=True, index=True)
    title: str = db.Column(db.String(100))
    content: str = db.Column(db.String(500))

    userid: str = db.Column(db.String(30))  #, db.ForeignKey(UserDto.userid))
    movie_id: int = db.Column(db.Integer)  #, db.ForeignKey(MovieDto.id))

    def __init__(self, title, content, userid, movie_id):
        self.title = title
        self.content = content
        self.userid = userid
        self.movie_id = movie_id

    def __repr__(self):
        return f'id={self.id}, user_id={self.userid}, movie_id={self.movie_id},\
            title={self.title}, content={self.content}'

    @property
    def json(self):
        return {
            'id': self.id,
            'userid': self.userid,
            'movie_id': self.movie_id,
            'title': self.title,
            'content': self.content
        }

    def save(self):
        db.session.add(self)

    def delete(self):
        db.session.delete(self)
        db.session.commit()
class RatingDto(db.Model):

    __tablename__ = 'ratings'
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    # 'userid', 'mov_id', 'rating'
    rat_id: int = db.Column(db.Integer, primary_key=True, index=True)
    usr_id: str = db.Column(db.String(30), db.ForeignKey(UserDto.usr_id))
    mov_id: int = db.Column(db.Integer, db.ForeignKey(MovieDto.mov_id))
    rating: float = db.Column(db.Float)

    def __init__(self, rat_id, usr_id, mov_id, rating):
        self.rat_id = rat_id
        self.usr_id = usr_id
        self.mov_id = mov_id
        self.rating = rating

    def json(self):
        return {
            'rat_id': self.rat_id,
            'usr_id': self.usr_id,
            'mov_id': self.mov_id,
            'rating': self.rating
        }
Exemple #8
0
class UserDto(db.Model):

    __tablename__ = 'users'
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    user_id: int = db.Column(db.Integer, primary_key=True, index=True)
    password: str = db.Column(db.String(1))
    name: str = db.Column(db.String(100))
    pclass: int = db.Column(db.Integer)
    gender: int = db.Column(db.Integer)
    age_group: int = db.Column(db.Integer)
    embarked: int = db.Column(db.Integer)
    rank: int = db.Column(db.Integer)

    def __init__(self, user_id, password, name, pclass, gender, age_group,
                 embarked, rank):
        self.user_id = user_id
        self.password = password
        self.name = name
        self.pclass = pclass
        self.gender = gender
        self.age_group = age_group
        self.embarked = embarked
        self.rank = rank

    def __repr__(self):
        return f'User(user_id={self.user_id},\
            password={self.password},name={self.name}, pclass={self.pclass}, gender={self.gender}, \
                age_group={self.age_group}, embarked={self.embarked}, rank={self.rank})'

    @property
    def json(self):
        return {
            'userId': self.user_id,
            'password': self.password,
            'name': self.name,
            'pclass': self.pclass,
            'gender': self.gender,
            'ageGroup': self.age_group,
            'embarked': self.embarked,
            'rank': self.rank
        }
Exemple #9
0
class ReviewDto(db.Model):
    '''
    데이터베이스에 생성 될 Review table, Columns 관리
    로직을 가지고 있지 않은 순수 데이터 클래스
    '''

    __tablename__ = "reviews"  # 테이블 이름
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}

    # Creates table columns
    rev_id: int = db.Column(db.Integer, primary_key=True, index=True)
    title: str = db.Column(db.String(100))
    content: str = db.Column(db.String(500))
    label: int = db.Column(db.Integer)

    # User Id, Movie Id 는 Users, Movies 테이블에서 Primary key를 받아와 Reviews 테이블의 Foreign Key로 사용한다
    usr_id: str = db.Column(db.String(30), db.ForeignKey(UserDto.usr_id))
    mov_id: int = db.Column(db.Integer, db.ForeignKey(MovieDto.mov_id))

    def __init__(self, title, content, label, usr_id, mov_id):
        self.title = title
        self.content = content
        self.label = label
        self.usr_id = usr_id
        self.mov_id = mov_id

    def __repr__(self):
        return f'rev_id = {self.rev_id}, usr_id = {self.usr_id}, mov_id = {self.mov_id},\
            title = {self.title}, content = {self.content}, label = {self.label}'

    def json(self):
        return {
            'rev_id': self.rev_id,
            'usr_id': self.usr_id,
            'mov_id': self.mov_id,
            'title': self.title,
            'content': self.content,
            'label': self.label
        }
Exemple #10
0
class UserDto(db.Model):  # 여기서 DB 모델 만든 것
    """
    [Creates User Model and corresponding table]
    """
    __tablename__ = 'users'  # 테이블 이름
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    # The __table_args__ attribute allows passing extra arguments to that Table

    # Creates table columns
    user_id: str = db.Column(db.String(30), primary_key=True, index=True)
    password: str = db.Column(db.String(30))
    fname: str = db.Column(db.String(30))
    lname: str = db.Column(db.String(30))
    age: int = db.Column(db.Integer)
    gender: str = db.Column(db.String(30))
    email: str = db.Column(db.String(80), unique=True)

    def __init__(self, user_id, password, fname, lname, age, gender, email):
        """
        Recives 7 parameters that are used to construct User Table
        user_id = 유저 고유 아이디 (Unique)
        password = 비밀번호
        fname = 성
        lname = 이름
        age = 나이
        gender = 성별
        email = 이메일 -> 나중에는 이메일이 아이디로 사용될 것 그래서 이것도 (Unique)
        """
        self.user_id = user_id
        self.password = password
        self.fname = fname
        self.lname = lname
        self.age = age
        self.gender = gender
        self.email = email

    @hybrid_property
    def fullname(self):
        """
        성과 이름을 합쳐서 풀네임을 만들어서 return 한다
        returns fullname
        """
        if self.fname is not None:
            return self.fname + " " + self.lname
        else:
            return self.lname

    # some_user = session.query(User).first()
    # print(s()ome_user.fullname)
    # as well as usable within queries:
    # some_user = session.query(User).filter(User.fullname == "John Smith").first

    def json(self):
        """
        UserDto (User 모델)이 주어지면 json file 로 리턴한다 
        """
        return {
            'user_id': self.user_id,
            'password': self.password,
            'lname': self.lname,
            'age': self.age,
            'fname': self.fname,
            'gender': self.gender,
            'email': self.email
        }

    def __str__(self):
        """
        User id 를 리턴한다
        """
        return self.user_id
Exemple #11
0
class MovieDto(db.Model):

    __tablename__ = 'movies'
    __talbe_args__ = {'mysql_collate': 'utf8_general_ci'}
    '''
    DataFrame Columns(14)
    'movieid', 
    'title_kor', 
    'title_naver_eng', 
    'genres_kor', 
    'keyword_kor',
    'running_time_kor', 
    'year_kor', 
    'director_naver_kor', 
    'actor_naver_kor',
    'movie_l_rating', 
    'movie_l_rating_count', 
    'movie_l_popularity',
    'link_naver', 
    'image_naver'
    '''
    mov_id: int = db.Column(db.Integer, primary_key=True, index=True)
    title_kor: str = db.Column(db.String(100))
    title_naver_eng: str = db.Column(db.String(100))
    genres_kor: str = db.Column(db.String(30))
    keyword_kor: str = db.Column(db.String(150))
    running_time_kor: int = db.Column(db.Integer)
    year_kor: str = db.Column(db.String(4))
    director_naver_kor: str = db.Column(db.String(50))
    actor_naver_kor: str = db.Column(db.String(50))
    movie_l_rating: float = db.Column(db.Float)
    movie_l_rating_count: int = db.Column(db.Integer)
    movie_l_popularity: float = db.Column(db.Float)
    link_naver: str = db.Column(db.String(80))
    image_naver: str = db.Column(db.String(80))

    def __init__(self, mov_id, title_kor, title_naver_eng, genres_kor,
                 keyword_kor, running_time_kor, year_kor, director_naver_kor,
                 actor_naver_kor, movie_l_rating, movie_l_rating_count,
                 movie_l_popularity, link_naver, image_naver):
        self.mov_id = mov_id
        self.title_kor = title_kor
        self.title_naver_eng = title_naver_eng
        self.genres_kor = genres_kor
        self.keyword_kor = keyword_kor
        self.running_time_kor = running_time_kor
        self.year_kor = year_kor
        self.director_naver_kor = director_naver_kor
        self.actor_naver_kor = actor_naver_kor
        self.movie_l_rating = movie_l_rating
        self.movie_l_rating_count = movie_l_rating_count
        self.movie_l_popularity = movie_l_popularity
        self.link_naver = link_naver
        self.image_naver = image_naver

    def json(self):
        return {
            'mov_id': self.mov_id,
            'title_kor': self.title_kor,
            'title_naver_eng': self.title_naver_eng,
            'genres_kor': self.genres_kor,
            'keyword_kor': self.keyword_kor,
            'running_time_kor': self.running_time_kor,
            'year_kor': self.year_kor,
            'director_naver_kor': self.director_naver_kor,
            'actor_naver_kor': self.actor_naver_kor,
            'movie_l_rating': self.movie_l_rating,
            'movie_l_rating_count': self.movie_l_rating_count,
            'movie_l_popularity': self.movie_l_popularity,
            'link_naver': self.link_naver,
            'image_naver': self.image_naver
        }
Exemple #12
0
class MovieDto(db.Model):
    
    __tablename__ = 'movies'
    __table_args__= {'mysql_collate':'utf8_general_ci'}

    id : int = db.Column(db.Integer, primary_key = True, index = True)
    movie_name : str = db.Column(db.String(30))
    genre : str = db.Column(db.String(30))
    country : str = db.Column(db.String(30))
    year : str = db.Column(db.String(4))
    company : str = db.Column(db.String(30))
    director : str = db.Column(db.String(30))
    actor : str = db.Column(db.String(30))
    keyword : str = db.Column(db.String(30))

    articles = db.relationship('ArticleModel', lazy='dynamic')

    def __init__(self, id, movie_name, genre, country, year, company, director, actor, keyword):
        self.id = id
        self.movie_name = movie_name
        self.genre = genre
        self.country = country
        self.year = year
        self.company = company
        self.director = director
        self.actor = actor
        self.keyword = keyword


    def __repr__(self):
        return f'Movie(id=\'{self.id}\',\
            movie_name=\'{self.movie_name}\',\
            genre=\'{self.genre}\',\
            country=\'{self.country}\',\
            year=\'{self.year}\',\
            company=\'{self.company}\',\
            director=\'{self.director}\',\
            actor=\'{self.actor}\',\
            keyword=\'{self.keyword}\',)'

    @property
    def json(self):
        return {
            'id' : self.id,
            'movie_name' : self.movie_name,
            'genre' : self.genre,
            'country' : self.country,
            'year' : self.year,
            'company' : self.company,
            'director' : self.director,
            'actor' : self.actor,
            'keyword' : self.keyword
        }

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Exemple #13
0
class ActorDto(db.Model):
    __tablename__ = 'actors'
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    # 'photoUrl', 'age', 'act_id', 'name', 'realName', 'religion', 'agency',
    #  'spouse', 'children', 'debutYear', 'gender', 'state'

    # columns=['photoUrl', 'age','name','realName','religion','agency',
    #          'spouse', 'children','debutYear','act_id']
    act_id: str = db.Column(db.String(30), primary_key=True, index=True)
    name: str = db.Column(db.String(30))
    gender: str = db.Column(db.String(1))
    age: str = db.Column(db.String(30))
    real_name: str = db.Column(db.String(30))
    religion: str = db.Column(db.String(30))
    agency: str = db.Column(db.String(30))
    spouse: str = db.Column(db.String(30))
    children: str = db.Column(db.String(100))
    debut_year: int = db.Column(db.Integer)
    state: str = db.Column(db.String(1))
    photo_url: str = db.Column(db.String(200))

    def __init__(self, photo_url, act_id, name, gender, age, real_name, spouse,
                 children, debut_year, agency, religion, state):
        self.photo_url = photo_url
        self.act_id = act_id
        self.name = name
        self.gender = gender
        self.age = age
        self.real_name = real_name
        self.religion = religion
        self.agency = agency
        self.spouse = spouse
        self.children = children
        self.debut_year = debut_year
        self.state = state

    def json(self):
        return {
            'photo_url': self.photo_url,
            'act_id': self.act_id,
            'name': self.name,
            'gender': self.gender,
            'age': self.age,
            'real_name': self.real_name,
            'spouse': self.spouse,
            'children': self.children,
            'debut_year': self.debut_year,
            'religion': self.religion,
            'agency': self.agency,
            'state': self.state
        }