Skip to content

Commit

Permalink
🔨Refactor: validation로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
moonyu012 committed Nov 4, 2024
1 parent af172c8 commit 166bdd0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/wallets/views/wallet_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def post(self, request, *args, **kwargs):
serializer.is_valid(raise_exception=True)
coin_amount = serializer.validated_data["coin"]

if wallet.coin < coin_amount:
return Response({"error": "잔액이 부족합니다."}, status=status.HTTP_400_BAD_REQUEST)

# F expression으로 잔액에서 차감
wallet.coin = F("coin") - coin_amount
wallet.save()
Expand Down

0 comments on commit 166bdd0

Please sign in to comment.