Skip to content

Commit

Permalink
signup serializer implementation completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigeriancoder committed Jun 8, 2022
1 parent 7287058 commit ff99b0e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
60 changes: 59 additions & 1 deletion core/api_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
from cmath import e
import logging
# from math import perm
import traceback

from requests import request

from core.custom_classes import YkGenericViewSet
from rest_framework.views import APIView
from rest_framework.viewsets import ViewSet, ModelViewSet, GenericViewSet
Expand All @@ -12,18 +19,69 @@
from django.contrib.auth import get_user_model

from core.models.implementation import Category, Product
from core.models.model_serializer import(
from core.model_serializer import(
ProductSerializer,
CategorySerializer,
UserSerializer,
)
from core.models import TempCode

from rest_framework.decorators import action
from django.db.models import Q
from drf_yasg import openapi # type: ignore
from drf_yasg.utils import swagger_auto_schema # type: ignore

from .responses_serialisers import (
EmptySerializer,
NotFoundResponseSerializer,
BadRequestResponseSerializer,

)

from .responses import(
GoodResponse,
BadRequestResponse,
NotFoundResponse
)

from .input_serializer import(
SignupInputSerializer
)


logger = logging.getLogger()

User = get_user_model()

class AuthViewset(YkGenericViewSet):
queryset = User.objects.all()

serializer = UserSerializer


@swagger_auto_schema(
operation_summary="Signup",
operation_description="Signup using your email",
responses={200: EmptySerializer(), 400: BadRequestResponseSerializer()},
request_body=SignupInputSerializer(),
)

@action(methods=["POST"], detail=False)
def signup(self, request, *args, **kwargs):
try:
rcv_ser = SignupInputSerializer(data=self.request.data)
if rcv_ser.is_valid():
print("hello")
else:
return BadRequestResponse(
"Unable to confirm",
"confirm_error",
request=self.request,
)
except Exception as e:
logger.error(traceback.print_exc())
return BadRequestResponse(str(e), "Uknown", request=self.request)



class ProductViewset(
Expand Down
19 changes: 19 additions & 0 deletions core/input_serializer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from datetime import datetime, timedelta

from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractBaseUser
from django.forms import CharField, EmailField
from rest_framework.serializers import Serializer

User = get_user_model()

class SignupInputSerializer(Serializer):
username = CharField()
first_name = CharField()
last_name = CharField()
email = EmailField()
phone = CharField()
password = CharField()

class Meta:
ref_name = None
File renamed without changes.
Empty file removed core/models/input_serializer.py
Empty file.
2 changes: 1 addition & 1 deletion core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rest_framework_simplejwt.views import TokenRefreshView
# from rest_framework_simplejwt.views import TokenVerifyView

from .api_views import(
from core.api_views import(
AuthViewset,
ProductViewset,
CategoryViewset,
Expand Down

0 comments on commit ff99b0e

Please sign in to comment.