SMART-48 implemented create project endpoint

This commit is contained in:
s460930 2020-12-14 20:29:38 +01:00
parent ee9261f504
commit 97c968c3cb
7 changed files with 60 additions and 2 deletions

Binary file not shown.

View File

@ -0,0 +1,17 @@
"""
@author p.dolata
"""
from rest_framework import serializers
from smartpicasso.app.project.models import Project
class ProjectSerializer(serializers.ModelSerializer):
"""
Class to manage serializing Project
"""
class Meta:
model = Project
fields = ('id', 'name', 'created_at', 'updated_at')

View File

@ -0,0 +1,11 @@
"""
@author: p.dolata
"""
from django.conf.urls import url
from smartpicasso.app.project.views import ProjectsView
urlpatterns = [
url(r'^projects', ProjectsView.as_view(), name='projects')
]

View File

@ -1,3 +1,32 @@
from django.shortcuts import render
"""
@author p.dolata
"""
# Create your views here.
from rest_framework import status
from rest_framework.generics import CreateAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from smartpicasso.app.project.serializers import ProjectSerializer
class ProjectsView(CreateAPIView):
"""
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)

View File

@ -19,5 +19,6 @@ from django.urls import path, include
urlpatterns = [
path('api/', include('smartpicasso.app.user.urls')),
path('api/', include('smartpicasso.app.user_profile.urls')),
path('api/', include('smartpicasso.app.project.urls')),
path('admin/', admin.site.urls),
]