Ejemplo n.º 1
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String(32),
                        db.ForeignKey('user.id'),
                        nullable=False)
    accommodation_id = db.Column(db.String(32),
                                 db.ForeignKey('accommodation.id'),
                                 nullable=False)
    content = db.Column(db.Text, nullable=False)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

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

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 2
0
class AccommodationAmenity(db.Model):
    __tablename__ = 'link'
    accommodation_id = db.Column(db.String(32),
                                 db.ForeignKey('accommodation.id'),
                                 primary_key=True)
    amenity_id = db.Column(db.Integer,
                           db.ForeignKey('amenity.id'),
                           primary_key=True)
Ejemplo n.º 3
0
class Booking(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String(32), db.ForeignKey('user.id'))
    member_id = db.Column(db.String(32), db.ForeignKey('member.id'))
    accommodation_id = db.Column(db.String(32),
                                 db.ForeignKey('accommodation.id'))
    code = db.Column(db.String(255), nullable=False)
    status = db.Column(db.SmallInteger, nullable=False)
    number_of_guess = db.Column(db.Integer, nullable=False)
    number_of_night = db.Column(db.Integer, nullable=False)
    total_price = db.Column(db.Float, nullable=False)
    check_in = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    check_out = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)

    @classmethod
    def code_generation(cls):
        chars = string.ascii_uppercase + string.digits
        return ''.join(random.choice(chars) for x in range(6))

    @classmethod
    def get_all_booking(cls):
        return cls.query.all()

    @classmethod
    def find_by_code(cls, code):
        return cls.query.filter_by(code=code).first()

    @classmethod
    def get_booking_by_user_id(cls, user_id):
        return db.session.query(Booking).join(User).filter(
            Booking.user_id == User.id).filter(User.id == user_id).all()

    @classmethod
    def get_booking_by_member_id(cls, member_id):
        return db.session.query(Booking).join(Member).filter(
            Booking.member_id == Member.id).filter(
                Member.id == member_id).all()

    @classmethod
    def get_booking_by_accommodation_id(cls, accommodation_id):
        return db.session.query(Booking).join(Accommodation).filter(
            Booking.accommodation_id == Accommodation.id).filter(
                Accommodation.id == accommodation_id).first()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
Ejemplo n.º 4
0
class Like(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String(32),
                        db.ForeignKey('user.id'),
                        nullable=False)
    accommodation_id = db.Column(db.String(32),
                                 db.ForeignKey('accommodation.id'),
                                 nullable=False)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)
Ejemplo n.º 5
0
class Promotion(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    accommodation_id = db.Column(db.String(32),
                                 db.ForeignKey('accommodation.id'))
    member_id = db.Column(db.String(32), db.ForeignKey('member.id'))
    code = db.Column(db.String(255), nullable=False)
    discount_amount = db.Column(db.Float, nullable=False)
    start_time = db.Column(db.DateTime, nullable=False)
    end_time = db.Column(db.DateTime, nullable=False)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)

    @classmethod
    def find_by_code(cls, code):
        return cls.query.filter_by(code=code).first()

    @classmethod
    def get_all_promotion(cls):
        return cls.query.all()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def get_promotion_by_member_id(cls, id):
        return db.session.query(Promotion).join(Member).filter(
            Promotion.member_id == Member.id).filter(Member.id == id).all()

    @classmethod
    def get_promotion_by_accommodation_id(cls, id):
        return db.session.query(Promotion).join(Accommodation).filter(
            Promotion.accommodation_id == Accommodation.id).filter(
                Accommodation.id == id).all()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
Ejemplo n.º 6
0
class Amenity(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    amenity_category_id = db.Column(db.Integer,
                                    db.ForeignKey('amenity_category.id'))
    accommodations = db.relationship('Accommodation', secondary='link')
    name = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)
Ejemplo n.º 7
0
class Image(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    accommodation_id = db.Column(db.String(32),
                                 db.ForeignKey('accommodation.id'))
    member_id = db.Column(db.String(32), db.ForeignKey('member.id'))
    image_url = db.Column(db.String(255), default=None)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)

    @classmethod
    def get_all_image(cls):
        return cls.query.all()

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def find_by_url(cls, url):
        return cls.query.filter_by(image_url=url).first()

    @classmethod
    def get_image_by_accommodation_id(cls, accommodation_id):
        return db.session.query(Image).join(Accommodation).filter(
            Image.accommodation_id == Accommodation.id).filter(
                Accommodation.id == accommodation_id).all()

    def delete(self):
        db.session.delete(self)
        db.commit()

    def save_to_db(self):
        db.session.add(self)
        db.commit()
Ejemplo n.º 8
0
class UserProfile(db.Model):
    user_id = db.Column(db.String(32),
                        db.ForeignKey('user.id'),
                        primary_key=True)
    last_name = db.Column(db.String(255), default=None)
    first_name = db.Column(db.String(255), default=None)
    phone_number = db.Column(db.String(255), default=None)
    gender = db.Column(db.String(255), default=None)
    avatar_url = db.Column(db.String(255), default=None)
    address = db.Column(db.String(255), default=None)
    description = db.Column(db.Text, default=None)
    birthday = db.Column(db.DateTime, default=None)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)

    def __init__(self, user_id, first_name, last_name, phone_number):
        self.user_id = user_id
        self.first_name = first_name
        self.last_name = last_name
        self.phone_number = phone_number

    @classmethod
    def find_by_email(cls, email):
        return db.session.query(UserProfile).join(User).filter(
            User.id == UserProfile.user_id).filter(
                User.email == email).first()

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(user_id=_id).first()

    @classmethod
    def get_all_profile(cls):
        return UserProfile.query.all()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()
Ejemplo n.º 9
0
class Accommodation(db.Model):
    id = db.Column(db.String(32), primary_key=True)
    likes = db.relationship('Like', backref='accommodation', lazy=True)
    promotions = db.relationship('Promotion',
                                 backref='accommodation',
                                 lazy=True)
    comments = db.relationship('Comment', backref='accommodation', lazy=True)
    images = db.relationship('Image', backref='accommodation', lazy=True)
    bookings = db.relationship('Booking', backref='accommodation', lazy=True)
    amenities = db.relationship('Amenity', secondary='link')
    member_id = db.Column(db.String(32),
                          db.ForeignKey('member.id'),
                          nullable=False)
    property_type_id = db.Column(db.Integer,
                                 db.ForeignKey('property_type.id'),
                                 nullable=False)
    room_type_id = db.Column(db.Integer,
                             db.ForeignKey('room_type.id'),
                             nullable=False)
    bed_type_id = db.Column(db.Integer, db.ForeignKey('bed_type.id'))
    name = db.Column(db.String(255), nullable=False)
    address = db.Column(db.String(255))
    description = db.Column(db.Text)
    special_notices = db.Column(db.Text)
    status = db.Column(db.SmallInteger, nullable=False)
    standard_guess = db.Column(db.Integer, nullable=False)
    max_guess = db.Column(db.Integer, nullable=False)
    num_bathrooms = db.Column(db.SmallInteger)
    num_bedrooms = db.Column(db.SmallInteger)
    num_beds = db.Column(db.SmallInteger)
    apartment_manual = db.Column(db.Text)
    apartment_rule = db.Column(db.Text)
    direction_manual = db.Column(db.Text)
    checkin_guide = db.Column(db.Text)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)
    deleted_at = db.Column(db.DateTime)

    @classmethod
    def get_all_accommodation(cls):
        return cls.query.all()

    @classmethod
    def find_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

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

    def delete(self):
        db.session.delete(self)
        db.session.commit()