diff --git a/.DS_Store b/.DS_Store index ed253b7b..952c9f83 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/osinaweb/.DS_Store b/osinaweb/.DS_Store index 477d3a9c..2836bb73 100644 Binary files a/osinaweb/.DS_Store and b/osinaweb/.DS_Store differ diff --git a/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc b/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc index 3a6cf4df..46a5e009 100644 Binary files a/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc differ diff --git a/osinaweb/osinacore/api/__pycache__/serializers.cpython-310.pyc b/osinaweb/osinacore/api/__pycache__/serializers.cpython-310.pyc new file mode 100644 index 00000000..81f26ca5 Binary files /dev/null and b/osinaweb/osinacore/api/__pycache__/serializers.cpython-310.pyc differ diff --git a/osinaweb/osinacore/api/__pycache__/urls.cpython-310.pyc b/osinaweb/osinacore/api/__pycache__/urls.cpython-310.pyc new file mode 100644 index 00000000..6e456659 Binary files /dev/null and b/osinaweb/osinacore/api/__pycache__/urls.cpython-310.pyc differ diff --git a/osinaweb/osinacore/api/__pycache__/views.cpython-310.pyc b/osinaweb/osinacore/api/__pycache__/views.cpython-310.pyc new file mode 100644 index 00000000..96a7573e Binary files /dev/null and b/osinaweb/osinacore/api/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/osinacore/api/serializers.py b/osinaweb/osinacore/api/serializers.py new file mode 100644 index 00000000..7321ed06 --- /dev/null +++ b/osinaweb/osinacore/api/serializers.py @@ -0,0 +1,15 @@ +# serializers.py in Osina app +from rest_framework import serializers +from osinacore.models import * + +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ['id', 'username', 'email', 'password'] + +class CustomerProfileSerializer(serializers.ModelSerializer): + user = UserSerializer(required=True) + + class Meta: + model = CustomerProfile + fields = ['user', 'mobile_number', 'status', 'reference'] \ No newline at end of file diff --git a/osinaweb/osinacore/api/urls.py b/osinaweb/osinacore/api/urls.py new file mode 100644 index 00000000..26d59022 --- /dev/null +++ b/osinaweb/osinacore/api/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from . import views + + +urlpatterns = [ + path('register/', views.register_customer, name='register_customer'), +] \ No newline at end of file diff --git a/osinaweb/osinacore/api/views.py b/osinaweb/osinacore/api/views.py new file mode 100644 index 00000000..a0072b05 --- /dev/null +++ b/osinaweb/osinacore/api/views.py @@ -0,0 +1,25 @@ +from django.contrib.auth.models import User +from rest_framework import status +from rest_framework.decorators import api_view +from rest_framework.response import Response +from osinacore.models import * +from .serializers import CustomerProfileSerializer, UserSerializer + +@api_view(['POST']) +def register_customer(request): + if 'user' in request.data and 'customer' in request.data: + user_serializer = UserSerializer(data=request.data['user']) + if user_serializer.is_valid(): + user = user_serializer.save() + customer_data = request.data['customer'] + customer_data['user'] = user.id + customer_serializer = CustomerProfileSerializer(data=customer_data) + if customer_serializer.is_valid(): + customer_serializer.save() + return Response({'message': 'User and Customer registered successfully'}, status=status.HTTP_201_CREATED) + else: + return Response(customer_serializer.errors, status=status.HTTP_400_BAD_REQUEST) + else: + return Response(user_serializer.errors, status=status.HTTP_400_BAD_REQUEST) + else: + return Response({'message': 'User and Customer data are required'}, status=status.HTTP_400_BAD_REQUEST) diff --git a/osinaweb/osinacore/urls.py b/osinaweb/osinacore/urls.py index 0dfbc04d..525c04d2 100644 --- a/osinaweb/osinacore/urls.py +++ b/osinaweb/osinacore/urls.py @@ -20,11 +20,9 @@ from django.conf.urls.static import static from django.conf import settings urlpatterns = [ - path('add/', include('osinacore.add.urls')), - path('edit/', include('osinacore.edit.urls')), - path('delete/', include('osinacore.delete.urls')), + path('api/', include('osinacore.api.urls')), + - path('login', views.signin, name='signin'), path('go_online/', views.go_online, name='go_online'), path('logout/', views.signout, name='signout'), @@ -47,8 +45,6 @@ urlpatterns = [ path('tags/', views.tags, name='tags'), - - #Details Templates path('customers//', views.customerdetails, name='customerdetails'), path('businesses//', views.businessdetails, name='businessdetails'), @@ -57,6 +53,11 @@ urlpatterns = [ path('tasks//', views.taskdetails, name='detailed-task'), path('show-points//', views.show_points_modal, name='showpoints'), path('timeline//', views.timeline_modal, name='timeline'), + + + path('add/', include('osinacore.add.urls')), + path('edit/', include('osinacore.edit.urls')), + path('delete/', include('osinacore.delete.urls')), #Fetch urls diff --git a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc index d5d63acd..b78efca0 100644 Binary files a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/settings.py b/osinaweb/osinaweb/settings.py index 5514dc34..edb6be34 100644 --- a/osinaweb/osinaweb/settings.py +++ b/osinaweb/osinaweb/settings.py @@ -40,6 +40,7 @@ LOGIN_URL = 'signin' # Application definition INSTALLED_APPS = [ + 'rest_framework', 'osinacore', 'addressbook', 'billing',