示例#1
0
class Booking(db.Model):
    __tablename__ = "booking"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    user_id = db.Column(db.Integer,
                        db.ForeignKey("user.id"),
                        primary_key=False)
    user = relationship("User", back_populates="booking")

    table_id = db.Column(db.Integer,
                         db.ForeignKey("table.id"),
                         primary_key=False)
    table = relationship("Table", back_populates="booking")

    booking_number = db.Column(db.Integer, nullable=False)

    start_booking = db.Column(db.DateTime, nullable=False)
    end_booking = db.Column(db.DateTime, nullable=False)
    confirmed_booking = db.Column(db.Boolean, default=False)
    checkin = db.Column(db.Boolean, default=False)

    def user_already_booked(self, id):
        user_list = list(
            db.session.query(Booking.user_id).filter_by(
                booking_number=self.booking_number).all())

        id_user_list = []
        for user in user_list:
            id_user = user[0]
            id_user_list.append(id_user)

        return id in id_user_list
示例#2
0
class Mark(TimestampMixin, db.Model):
    __tablename__ = "mark"
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
    authority_id = db.Column(db.Integer,
                             db.ForeignKey("authority.id"),
                             primary_key=True)

    authority = db.relationship("HealthAuthority", back_populates="marks")
    user = db.relationship("User", back_populates="marks")

    duration = db.Column(db.Integer, default=14)
示例#3
0
class Review(TimestampMixin, db.Model):
    __tablename__ = "review"
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), primary_key=True)
    restaurant_id = db.Column(db.Integer,
                              db.ForeignKey("restaurant.id"),
                              primary_key=True)

    restaurant = db.relationship("Restaurant", back_populates="reviews")
    user = db.relationship("User", back_populates="reviews")

    rating = db.Column(db.SmallInteger, nullable=False)
    message = db.Column(db.UnicodeText)
class RestaurantsPrecautions(db.Model):
    __tablename__ = "restaurants_precautions"

    restaurant_id = db.Column(db.Integer,
                              db.ForeignKey("restaurant.id"),
                              primary_key=True)
    restaurant = relationship(
        "Restaurant", foreign_keys="RestaurantsPrecautions.restaurant_id")

    precautions_id = db.Column(db.Integer,
                               db.ForeignKey("precautions.id"),
                               primary_key=True)
    precautions = relationship(
        "Precautions", foreign_keys="RestaurantsPrecautions.precautions_id")
示例#5
0
class Restaurant(SearchableMixin, db.Model):
    __tablename__ = "restaurant"
    __searchable__ = ["name", "phone", "average_rating"]

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    name = db.Column(db.Text(100))

    lat = db.Column(db.Float)  # restaurant latitude
    lon = db.Column(db.Float)  # restaurant longitude

    phone = db.Column(db.Unicode(40))
    time_of_stay = db.Column(db.Integer)  # minutes
    cuisine_type = db.Column(db.Enum(CuisineType))
    opening_hours = db.Column(db.Integer)
    closing_hours = db.Column(db.Integer)
    operator_id = db.Column(db.Integer, db.ForeignKey("operator.id"))
    average_rating = db.Column(db.Integer, default=0)

    # precautions = db.relationship("Precaution", secondary=precautions, backref="restaurants")
    tables = db.relationship("Table", back_populates="restaurant")
    reviews = db.relationship("Review", back_populates="restaurant")
    menus = db.relationship("Menu", back_populates="restaurant")

    def get_bookings(self, starting_booking_datetime: datetime):
        """Get all the bookings that were confirmed starting from a specific time.

        Args:
            starting_booking_time (datetime): the starting time of the booking
        """
        total_real_bookings = []
        for table in self.tables:
            bookings = [
                b for b in table.booking
                if b.checkin and b.start_booking == starting_booking_datetime
            ]
            total_real_bookings.extend(bookings)

        return total_real_bookings

    def get_free_table(self, seats, date_hour):
        filtered_tables = []
        tables_list = Table.query.filter_by(restaurant_id=self.id).order_by(
            Table.seats.asc())
        for table in tables_list:
            if table.seats >= seats:
                filtered_tables.append(table)

        id_booked_tables = []
        for table in filtered_tables:
            for booking in table.booking:
                if booking.start_booking == date_hour:
                    id_booked_tables.append(table.id)
                    break

        for table in filtered_tables:
            if table.id not in id_booked_tables:
                return table.id
        return None
示例#6
0
class Menu(db.Model):
    __tablename__ = "menu"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    name = db.Column(db.Text(100))
    restaurant_id = db.Column(db.Integer, db.ForeignKey("restaurant.id"))

    restaurant = db.relationship("Restaurant", back_populates="menus")
    foods = db.relationship("Food", secondary=MenuItems, back_populates="menu")
示例#7
0
class Table(db.Model):
    __tablename__ = "table"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    name = db.Column(db.Text(100))
    seats = db.Column(db.Integer)

    restaurant_id = db.Column(db.Integer, db.ForeignKey("restaurant.id"))

    restaurant = db.relationship("Restaurant", back_populates="tables")
    booking = db.relationship("Booking", back_populates="table")
示例#8
0
from monolith import db
import enum

MenuItems = db.Table(
    "menuitems",
    db.Column("menu_id",
              db.Integer,
              db.ForeignKey("menu.id"),
              primary_key=True),
    db.Column("food_id",
              db.Integer,
              db.ForeignKey("food.id"),
              primary_key=True),
)


class FoodCategory(enum.Enum):
    STARTERS = "Starters"
    MAIN_COURSES = "Main Courses"
    SIDE_DISHES = "Side Dishes"
    DESSERTS = "Desserts"
    DRINKS = "Drinks"
    PIZZAS = "Pizzas"
    BURGERS = "Burgers"
    SANDWICHES = "Sandwiches"

    @classmethod
    def choices(cls):
        return [(choice.name, choice.value) for choice in cls]