diff --git a/.idea/misc.xml b/.idea/misc.xml index 73d0fd3..ebe6eed 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/.idea/oz_03_main-001-BE.iml b/.idea/oz_03_main-001-BE.iml index e597ea1..2c80e12 100644 --- a/.idea/oz_03_main-001-BE.iml +++ b/.idea/oz_03_main-001-BE.iml @@ -1,8 +1,10 @@ - - + + + + \ No newline at end of file diff --git a/dosirock/settings/base.py b/dosirock/settings/base.py index 90f5275..b38fde6 100644 --- a/dosirock/settings/base.py +++ b/dosirock/settings/base.py @@ -71,6 +71,7 @@ CORS_ORIGIN_WHITELIST = os.getenv("CORS_ORIGIN_WHITELIST").split(" ") +CORS_ALLOW_CREDENTIALS = True TEMPLATES = [ { @@ -134,7 +135,7 @@ SIMPLE_JWT = { - "ACCESS_TOKEN_LIFETIME": timedelta(minutes=5), + "ACCESS_TOKEN_LIFETIME": timedelta(minutes=30), "REFRESH_TOKEN_LIFETIME": timedelta(days=1), "ROTATE_REFRESH_TOKENS": False, "BLACKLIST_AFTER_ROTATION": False, diff --git a/lunch/views.py b/lunch/views.py index d834b24..c40a9ff 100644 --- a/lunch/views.py +++ b/lunch/views.py @@ -80,6 +80,17 @@ def delete(self, request: Request, pk: int) -> Response: class LunchRandomList(APIView): def get(self, request: Request) -> Response: + random_lunch = Lunch.objects.order_by("?")[0:10] + serializer = LunchSerializer(random_lunch, many=True) + + return Response( + serializer.data, + status=status.HTTP_200_OK, + ) + + def post(self, request: Request) -> Response: + # if not request.user.is_authenticated or request.user.get_status_display() != "store": + # return Response({"success": False}, status=status.HTTP_403_FORBIDDEN) all_menus = Menu.objects.all() bob_menus = [menu for menu in all_menus if menu.category == "bob"] guk_menus = [menu for menu in all_menus if menu.category == "guk"] @@ -87,7 +98,7 @@ def get(self, request: Request) -> Response: random_lunch: list[Lunch] = [] - while len(random_lunch) != 10: + while len(random_lunch) != 5: selected_menus = random.sample(bob_menus, 1) + random.sample(guk_menus, 1) + random.sample(chan_menus, 3) lunch = Lunch.objects.create( @@ -111,5 +122,5 @@ def get(self, request: Request) -> Response: return Response( serializer.data, - status=status.HTTP_200_OK, + status=status.HTTP_201_CREATED, ) diff --git a/orders/serializers.py b/orders/serializers.py index 4afcb46..f47c40c 100644 --- a/orders/serializers.py +++ b/orders/serializers.py @@ -10,6 +10,7 @@ class OrderLunchSerializer(serializers.ModelSerializer): menus = LunchMenuSerializer(many=True, write_only=True) lunch_menu = LunchMenuSerializer(many=True, read_only=True) + id = serializers.IntegerField(required=False) class Meta: model = Lunch @@ -25,7 +26,6 @@ class Meta: class OrderUserSerializer(serializers.ModelSerializer): - class Meta: model = User fields = ["id"] @@ -62,17 +62,21 @@ def create(self, validated_data): lunch_data = item_data.pop("lunch") menus_data = lunch_data.pop("menus") - lunch = Lunch.objects.create(**lunch_data) + if lunch_data.get("id") is not None: + lunch = Lunch.objects.get(id=lunch_data["id"]) + + else: + lunch = Lunch.objects.create(**lunch_data) - for menu_data in menus_data: - lm = LunchMenu.objects.create( - lunch_id=lunch.pk, - menu_id=menu_data["id"], - quantity=menu_data["quantity"], - ) + for menu_data in menus_data: + lm = LunchMenu.objects.create( + lunch_id=lunch.pk, + menu_id=menu_data["id"], + quantity=menu_data["quantity"], + ) - lm.kcal = lm.menu.kcal * lm.quantity - lm.save() + lm.kcal = lm.menu.kcal * lm.quantity + lm.save() OrderItem.objects.create(order=order, lunch=lunch, **item_data)