Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop -> Main 배포 CORS Credentail, Order 변경 #35

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions .idea/oz_03_main-001-BE.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dosirock/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

CORS_ORIGIN_WHITELIST = os.getenv("CORS_ORIGIN_WHITELIST").split(" ")

CORS_ALLOW_CREDENTIALS = True

TEMPLATES = [
{
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions lunch/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,25 @@ 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"]
chan_menus = [menu for menu in all_menus if menu.category == "chan"]

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(
Expand All @@ -111,5 +122,5 @@ def get(self, request: Request) -> Response:

return Response(
serializer.data,
status=status.HTTP_200_OK,
status=status.HTTP_201_CREATED,
)
24 changes: 14 additions & 10 deletions orders/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +26,6 @@ class Meta:


class OrderUserSerializer(serializers.ModelSerializer):

class Meta:
model = User
fields = ["id"]
Expand Down Expand Up @@ -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)

Expand Down
Loading