From bfea8ca10550b6b9a13537b05862ef6a45a0f0fa Mon Sep 17 00:00:00 2001 From: julio Date: Wed, 12 Jun 2024 07:58:47 +0200 Subject: [PATCH] HA-104 - added get provider profile by user token - updated bruno definitions --- api/client/Auth/Login User.bru | 2 +- api/client/Market/Detail Provider.bru | 11 +++++++++++ api/client/Market/List Categories.bru | 2 +- api/client/Market/List News.bru | 2 +- api/client/Profile/Consumer.bru | 2 +- api/client/Profile/Provider.bru | 8 ++++++-- api/client/Profile/Update Consumer.bru | 2 +- api/client/environments/PROD.bru | 4 ++-- api/client/environments/STAGING.bru | 4 ++-- api/urls.py | 3 ++- api/views/provider.py | 14 ++++++++++++++ 11 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 api/client/Market/Detail Provider.bru diff --git a/api/client/Auth/Login User.bru b/api/client/Auth/Login User.bru index fddf4b2..46f638e 100644 --- a/api/client/Auth/Login User.bru +++ b/api/client/Auth/Login User.bru @@ -18,7 +18,7 @@ body:form-urlencoded { script:post-response { let data = res.getBody(); - let token = bru.setEnvVar("token", data.token); + let token = bru.setEnvVar("token", data.data.api_key); } tests { diff --git a/api/client/Market/Detail Provider.bru b/api/client/Market/Detail Provider.bru new file mode 100644 index 0000000..31357d4 --- /dev/null +++ b/api/client/Market/Detail Provider.bru @@ -0,0 +1,11 @@ +meta { + name: Detail Provider + type: http + seq: 3 +} + +get { + url: {{URL}}/api/v2/nodes/{{node_id}}/providers/{{provider_uuid}} + body: none + auth: none +} diff --git a/api/client/Market/List Categories.bru b/api/client/Market/List Categories.bru index 68331dc..fea1eb1 100644 --- a/api/client/Market/List Categories.bru +++ b/api/client/Market/List Categories.bru @@ -1,7 +1,7 @@ meta { name: List Categories type: http - seq: 3 + seq: 4 } get { diff --git a/api/client/Market/List News.bru b/api/client/Market/List News.bru index 75e2811..83b4e20 100644 --- a/api/client/Market/List News.bru +++ b/api/client/Market/List News.bru @@ -1,7 +1,7 @@ meta { name: List News type: http - seq: 4 + seq: 5 } get { diff --git a/api/client/Profile/Consumer.bru b/api/client/Profile/Consumer.bru index 4779344..df35b27 100644 --- a/api/client/Profile/Consumer.bru +++ b/api/client/Profile/Consumer.bru @@ -1,7 +1,7 @@ meta { name: Consumer type: http - seq: 1 + seq: 2 } get { diff --git a/api/client/Profile/Provider.bru b/api/client/Profile/Provider.bru index 4dc9b6d..d379f8f 100644 --- a/api/client/Profile/Provider.bru +++ b/api/client/Profile/Provider.bru @@ -1,11 +1,15 @@ meta { name: Provider type: http - seq: 3 + seq: 1 } get { - url: {{URL}}/api/v2/nodes/{{node_id}}/providers/{{provider_uuid}} + url: {{URL}}/api/v2/provider/ body: none auth: none } + +headers { + Authorization: Token {{token}} +} diff --git a/api/client/Profile/Update Consumer.bru b/api/client/Profile/Update Consumer.bru index cea6ec2..6fc4285 100644 --- a/api/client/Profile/Update Consumer.bru +++ b/api/client/Profile/Update Consumer.bru @@ -1,7 +1,7 @@ meta { name: Update Consumer type: http - seq: 2 + seq: 3 } put { diff --git a/api/client/environments/PROD.bru b/api/client/environments/PROD.bru index 5a58ffe..1e6ae7e 100644 --- a/api/client/environments/PROD.bru +++ b/api/client/environments/PROD.bru @@ -1,8 +1,8 @@ vars { - URL: https://app.mercadosocial.net - username: admin@mercadosocial.net + URL: https://mercadosocial.app } vars:secret [ + username, password, token, node_id, diff --git a/api/client/environments/STAGING.bru b/api/client/environments/STAGING.bru index 7717511..c222fb3 100644 --- a/api/client/environments/STAGING.bru +++ b/api/client/environments/STAGING.bru @@ -1,8 +1,8 @@ vars { - URL: https://staging.app.mercadosocial.net - username: consumidora@madrid.com + URL: https://staging.mercadosocial.app } vars:secret [ + username, password, token, node_id, diff --git a/api/urls.py b/api/urls.py index afe0b33..40f049c 100644 --- a/api/urls.py +++ b/api/urls.py @@ -10,7 +10,7 @@ from api.views.member_status import MemberStatusViewSet from api.views.news import NewsViewSet from api.views.offers import OffersViewSet -from api.views.provider import EntitiesView +from api.views.provider import EntitiesView, ProviderAuthViewSet from api.views.user import FetchUserView, PreRegisterUserView router = DefaultRouter() @@ -29,6 +29,7 @@ path("v2/reset_password/", ResetPasswordView.as_view()), path("v2/member_status/", MemberStatusViewSet.as_view()), path("v2/consumer/", ConsumerViewSet.as_view()), + path("v2/provider/", ProviderAuthViewSet.as_view()), path("v2/profile_image/", ProfileImageViewSet.as_view()), path("v1/entities/", EntitiesView.as_view()), diff --git a/api/views/provider.py b/api/views/provider.py index af82ec2..d24e80b 100644 --- a/api/views/provider.py +++ b/api/views/provider.py @@ -2,12 +2,16 @@ from django_filters.rest_framework import DjangoFilterBackend from rest_framework import viewsets from rest_framework.filters import SearchFilter +from rest_framework.generics import RetrieveUpdateAPIView from rest_framework.views import APIView from api.filters.provider import ProviderFilter from api.mixins.FilterByNodeMixin import FilterByNodeMixin from api.serializers.provider import ProviderSerializer from market.models import Provider +from rest_framework import authentication, status +from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response class ProviderViewSet(FilterByNodeMixin, viewsets.ReadOnlyModelViewSet): @@ -18,6 +22,16 @@ class ProviderViewSet(FilterByNodeMixin, viewsets.ReadOnlyModelViewSet): filterset_class = ProviderFilter +class ProviderAuthViewSet(FilterByNodeMixin, RetrieveUpdateAPIView): + authentication_classes = [authentication.TokenAuthentication] + permission_classes = (IsAuthenticated,) + + def get(self, request, *args, **kwargs): + provider = Provider.objects.get(owner=request.user) + serializer = ProviderSerializer(provider, many=False) + return Response(data=serializer.data, status=status.HTTP_200_OK) + + class EntitiesView(APIView): permission_classes = []