SMART-48 change implementation of create project endpoint

This commit is contained in:
s460930 2020-12-15 16:28:25 +01:00
parent 9487df0e34
commit c3a50e0552
5 changed files with 8 additions and 21 deletions

Binary file not shown.

View File

@ -2,10 +2,10 @@
@author: p.dolata
"""
from django.conf.urls import url
from rest_framework.routers import SimpleRouter
from smartpicasso.app.project.views import ProjectsView
urlpatterns = [
url(r'^projects', ProjectsView.as_view(), name='projects')
]
router = SimpleRouter(trailing_slash=False)
router.register('projects', ProjectsView, basename="projects")
urlpatterns = router.urls

View File

@ -2,31 +2,18 @@
@author p.dolata
"""
from rest_framework import status
from rest_framework.generics import CreateAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from smartpicasso.app.project.serializers import ProjectSerializer
class ProjectsView(CreateAPIView):
class ProjectsView(ModelViewSet):
"""
View for project endpoints
"""
permission_classes = (IsAuthenticated,)
serializer_class = ProjectSerializer
def post(self, request):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
project = serializer.save(user=request.user)
status_code = status.HTTP_201_CREATED
response = {
'success': 'True',
'status_code': status_code,
'data': {
'id': project.id
}
}
return Response(response, status=status_code)
def perform_create(self, serializer):
serializer.save(user=self.request.user)