2022-04-19 23:20:03 +02:00
|
|
|
"Module used for everything related to the fat versions of models"
|
2019-09-08 01:58:21 +02:00
|
|
|
import typing
|
|
|
|
|
2020-01-26 16:02:03 +01:00
|
|
|
from hlds.definitions import location_definitions
|
2022-04-19 22:03:00 +02:00
|
|
|
from hlds.models import Dish, Location
|
2020-01-26 16:02:03 +01:00
|
|
|
from models import Order, OrderItem, User
|
2022-04-19 22:03:00 +02:00
|
|
|
from sqlalchemy.sql import desc, func
|
2016-09-10 16:52:46 +02:00
|
|
|
|
2016-09-10 23:01:13 +02:00
|
|
|
|
2019-05-29 18:02:55 +02:00
|
|
|
class FatModel:
|
2022-04-19 23:20:03 +02:00
|
|
|
"General class for the fat version of models"
|
|
|
|
|
2016-09-10 23:01:13 +02:00
|
|
|
@classmethod
|
|
|
|
def all(cls):
|
2022-04-19 23:20:03 +02:00
|
|
|
"Function to query all"
|
|
|
|
# pylint: disable=E1101
|
2016-09-10 23:01:13 +02:00
|
|
|
return cls.query.all()
|
2016-09-10 16:52:46 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def amount(cls):
|
2022-04-19 23:20:03 +02:00
|
|
|
"Function to query the amount"
|
|
|
|
# pylint: disable=E1101
|
2016-09-10 16:52:46 +02:00
|
|
|
return cls.query.count()
|
|
|
|
|
|
|
|
|
2019-05-29 18:02:55 +02:00
|
|
|
class FatLocation(Location, FatModel):
|
2022-04-19 23:20:03 +02:00
|
|
|
"Fat version of the Location model"
|
|
|
|
|
2020-01-26 16:02:03 +01:00
|
|
|
@classmethod
|
|
|
|
def all(cls):
|
|
|
|
return location_definitions
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def amount(cls):
|
|
|
|
return len(location_definitions)
|
2016-09-10 23:01:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FatOrder(Order, FatModel):
|
2022-04-19 23:20:03 +02:00
|
|
|
"Fat version of the Order model"
|
2016-09-10 23:01:13 +02:00
|
|
|
|
|
|
|
# It's hard to add the unique user constraint,
|
|
|
|
# as DISTINCT seems to apply after a GROUP BY and aggregate
|
|
|
|
# So DISTINCT ... count(user_id) ... will count all users,
|
|
|
|
# even if they get reduced by the disctinct afterwards.
|
|
|
|
@classmethod
|
|
|
|
def items_per_order(cls):
|
2022-04-19 23:20:03 +02:00
|
|
|
"Function to get the total of all items per order"
|
|
|
|
return (Order.query.join(OrderItem).group_by(Order.id).with_entities(
|
|
|
|
Order.id,
|
|
|
|
func.count(OrderItem.user_id).label("total")))
|
2016-09-10 16:52:46 +02:00
|
|
|
|
|
|
|
|
2019-05-29 18:02:55 +02:00
|
|
|
class FatUser(User, FatModel):
|
2022-04-19 23:20:03 +02:00
|
|
|
"Fat version of the User model"
|
2016-09-10 16:52:46 +02:00
|
|
|
|
|
|
|
|
2019-05-29 18:02:55 +02:00
|
|
|
class FatOrderItem(OrderItem, FatModel):
|
2022-04-19 23:20:03 +02:00
|
|
|
"Fat version of the OrderItem model"
|