diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 006ab8e..a535fbe 100644 Binary files a/rest-app/db.sqlite3 and b/rest-app/db.sqlite3 differ diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index 74b8e33..8ca7aeb 100644 Binary files a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc and b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc index 624cd2c..532843f 100644 Binary files a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc and b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/project/serializers.py b/rest-app/smartpicasso/app/project/serializers.py new file mode 100644 index 0000000..0eb99b2 --- /dev/null +++ b/rest-app/smartpicasso/app/project/serializers.py @@ -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') diff --git a/rest-app/smartpicasso/app/project/urls.py b/rest-app/smartpicasso/app/project/urls.py new file mode 100644 index 0000000..72aa447 --- /dev/null +++ b/rest-app/smartpicasso/app/project/urls.py @@ -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') +] diff --git a/rest-app/smartpicasso/app/project/views.py b/rest-app/smartpicasso/app/project/views.py index 91ea44a..a20dc68 100644 --- a/rest-app/smartpicasso/app/project/views.py +++ b/rest-app/smartpicasso/app/project/views.py @@ -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) diff --git a/rest-app/smartpicasso/urls.py b/rest-app/smartpicasso/urls.py index bd27833..146dbd0 100644 --- a/rest-app/smartpicasso/urls.py +++ b/rest-app/smartpicasso/urls.py @@ -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), ]