From 1cead7642b49dc839d7fbce53380e53a77000f56 Mon Sep 17 00:00:00 2001 From: JamesRamm Date: Fri, 3 Feb 2017 20:34:35 +0000 Subject: [PATCH] Make api functions writing to db atomic --- longclaw/basket/api.py | 4 +++- longclaw/checkout/api.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/longclaw/basket/api.py b/longclaw/basket/api.py index acbed1e..7355b58 100644 --- a/longclaw/basket/api.py +++ b/longclaw/basket/api.py @@ -1,5 +1,5 @@ from django.apps import apps -from django.conf import settings +from django.db import transaction from rest_framework.decorators import api_view, permission_classes from rest_framework import permissions, status from rest_framework.response import Response @@ -33,6 +33,7 @@ def get_item_count(request): count = 0 return Response(data={"quantity": count}, status=status.HTTP_200_OK) +@transaction.atomic @api_view(["POST"]) @permission_classes([permissions.AllowAny]) def add_to_basket(request): @@ -59,6 +60,7 @@ def add_to_basket(request): return Response(data=serializer.data, status=status.HTTP_201_CREATED) +@transaction.atomic @api_view(["POST"]) @permission_classes([permissions.AllowAny]) def remove_from_basket(request): diff --git a/longclaw/checkout/api.py b/longclaw/checkout/api.py index 40433d6..fce3e49 100644 --- a/longclaw/checkout/api.py +++ b/longclaw/checkout/api.py @@ -2,6 +2,7 @@ Shipping logic and payment capture API ''' from django.utils.module_loading import import_string +from django.db import transaction from rest_framework.decorators import api_view, permission_classes from rest_framework import permissions, status from rest_framework.response import Response @@ -23,7 +24,7 @@ def create_token(request): token = gateway.get_token(request) return Response({'token': token}, status=status.HTTP_200_OK) - +@transaction.atomic @api_view(['POST']) @permission_classes([permissions.AllowAny]) def capture_payment(request):