luanpoppe
commited on
Commit
·
6996fa9
1
Parent(s):
d37e9cb
feat: adicionando endpoint de Salvar
Browse files- db.sqlite3 +0 -0
- endpoint_teste/views.py +25 -1
- setup/urls.py +3 -3
db.sqlite3
CHANGED
Binary files a/db.sqlite3 and b/db.sqlite3 differ
|
|
endpoint_teste/views.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from rest_framework import viewsets, filters
|
2 |
from django_filters.rest_framework import DjangoFilterBackend
|
3 |
from rest_framework.response import Response
|
|
|
4 |
|
5 |
from endpoint_teste.models import EndpointTesteModel
|
6 |
from endpoint_teste.serializer import EndpointTesteSerializer
|
@@ -20,7 +21,30 @@ def raiz(request):
|
|
20 |
"teste": "Vamo Brasil BIRL"
|
21 |
})
|
22 |
|
|
|
23 |
def salvar(request):
|
|
|
|
|
24 |
if request.method == "POST":
|
25 |
serializer = EndpointTesteSerializer(data=request.data)
|
26 |
-
serializer.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from rest_framework import viewsets, filters
|
2 |
from django_filters.rest_framework import DjangoFilterBackend
|
3 |
from rest_framework.response import Response
|
4 |
+
from rest_framework.decorators import api_view
|
5 |
|
6 |
from endpoint_teste.models import EndpointTesteModel
|
7 |
from endpoint_teste.serializer import EndpointTesteSerializer
|
|
|
21 |
"teste": "Vamo Brasil BIRL"
|
22 |
})
|
23 |
|
24 |
+
@api_view(['GET', 'POST'])
|
25 |
def salvar(request):
|
26 |
+
print('request.data', request.method)
|
27 |
+
print('\n\n\n\n\n\n')
|
28 |
if request.method == "POST":
|
29 |
serializer = EndpointTesteSerializer(data=request.data)
|
30 |
+
if serializer.is_valid(raise_exception=True):
|
31 |
+
serializer.save()
|
32 |
+
return Response(request.data)
|
33 |
+
|
34 |
+
if request.method == "GET":
|
35 |
+
revisoes = EndpointTesteModel.objects.all()
|
36 |
+
serializer = EndpointTesteSerializer(revisoes, many=True)
|
37 |
+
return Response(serializer.data)
|
38 |
+
|
39 |
+
# @api_view(['GET', 'POST'])
|
40 |
+
# def salvar(request):
|
41 |
+
# print('request.data', request.method)
|
42 |
+
# print('\n\n\n\n\n\n')
|
43 |
+
# if request.method == "POST":
|
44 |
+
# serializer = EndpointTesteSerializer(data=request.data) # Ensure EndpointTesteSerializer is defined
|
45 |
+
# if serializer.is_valid():
|
46 |
+
# serializer.save()
|
47 |
+
# return Response(serializer.data)
|
48 |
+
# return Response(serializer.errors, status=400)
|
49 |
+
# elif request.method == "GET":
|
50 |
+
# return Response({"message": "GET request received"})
|
setup/urls.py
CHANGED
@@ -3,12 +3,12 @@ from django.urls import path, include
|
|
3 |
from rest_framework import routers
|
4 |
from endpoint_teste.views import EndpointTesteViewSet, raiz, salvar
|
5 |
|
6 |
-
router = routers.DefaultRouter()
|
7 |
-
router.register("endpoint-teste", EndpointTesteViewSet, basename="Basename do endpoint-teste")
|
8 |
|
9 |
urlpatterns = [
|
10 |
path("admin/", admin.site.urls),
|
11 |
-
path("
|
12 |
path("salvar/", salvar),
|
13 |
# path('', include(router.urls)),
|
14 |
]
|
|
|
3 |
from rest_framework import routers
|
4 |
from endpoint_teste.views import EndpointTesteViewSet, raiz, salvar
|
5 |
|
6 |
+
# router = routers.DefaultRouter()
|
7 |
+
# router.register("endpoint-teste", EndpointTesteViewSet, basename="Basename do endpoint-teste")
|
8 |
|
9 |
urlpatterns = [
|
10 |
path("admin/", admin.site.urls),
|
11 |
+
path("", raiz),
|
12 |
path("salvar/", salvar),
|
13 |
# path('', include(router.urls)),
|
14 |
]
|