Skip to content

Commit

Permalink
Merge pull request #92 from oz-main-project-team-02/feature/wallets
Browse files Browse the repository at this point in the history
🔨Refactor: validation로직 추가
  • Loading branch information
moonyu012 authored Nov 4, 2024
2 parents b6dfbf2 + 166bdd0 commit fb3b879
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 fb3b879

Please sign in to comment.