#50 feat: add StoreSettings model and API for store address and map coordinates
This commit is contained in:
@@ -18,6 +18,7 @@ from .payments import (
|
||||
Pagination,
|
||||
)
|
||||
from .admin import AdminCodeValidateView
|
||||
from .store_settings import StoreSettingsView
|
||||
|
||||
__all__ = [
|
||||
# Catalogue Images
|
||||
@@ -44,4 +45,6 @@ __all__ = [
|
||||
"Pagination",
|
||||
# Admin
|
||||
"AdminCodeValidateView",
|
||||
# Store Settings
|
||||
"StoreSettingsView",
|
||||
]
|
||||
|
||||
28
tienda_ilusion/don_confiao/api/store_settings.py
Normal file
28
tienda_ilusion/don_confiao/api/store_settings.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from ..models.store_settings import StoreSettings
|
||||
from ..permissions import IsAdministrator
|
||||
from ..serializers.store_settings import StoreSettingsSerializer
|
||||
|
||||
|
||||
class StoreSettingsView(APIView):
|
||||
def get_permissions(self):
|
||||
if self.request.method == "GET":
|
||||
return [AllowAny()]
|
||||
return [IsAuthenticated(), IsAdministrator()]
|
||||
|
||||
def get(self, request):
|
||||
settings = StoreSettings.get_singleton()
|
||||
return Response(StoreSettingsSerializer(settings).data)
|
||||
|
||||
def patch(self, request):
|
||||
settings = StoreSettings.get_singleton()
|
||||
serializer = StoreSettingsSerializer(
|
||||
settings, data=request.data, partial=True
|
||||
)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user