mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-19 17:36:53 +00:00
Refactor User model: update mobile field to allow null values, enforce unique id_card, and implement user filtering API endpoint
This commit is contained in:
parent
aa69977d63
commit
ddfbeba2f4
17
api/migrations/0009_alter_user_mobile.py
Normal file
17
api/migrations/0009_alter_user_mobile.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.1.2 on 2025-03-24 10:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("api", "0008_alter_user_mobile"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="mobile",
|
||||
field=models.CharField(blank=True, max_length=255, unique=True),
|
||||
),
|
||||
]
|
17
api/migrations/0010_alter_user_mobile.py
Normal file
17
api/migrations/0010_alter_user_mobile.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.1.2 on 2025-03-24 10:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("api", "0009_alter_user_mobile"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="mobile",
|
||||
field=models.CharField(blank=True, max_length=255, null=True, unique=True),
|
||||
),
|
||||
]
|
24
api/migrations/0011_alter_user_email.py
Normal file
24
api/migrations/0011_alter_user_email.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.1.2 on 2025-03-24 13:19
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("api", "0010_alter_user_mobile"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="email",
|
||||
field=models.EmailField(
|
||||
blank=True,
|
||||
default=datetime.datetime(2025, 3, 24, 13, 19, 18, 477594),
|
||||
max_length=254,
|
||||
verbose_name="email address",
|
||||
),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
17
api/migrations/0012_alter_user_id_card.py
Normal file
17
api/migrations/0012_alter_user_id_card.py
Normal file
@ -0,0 +1,17 @@
|
||||
# Generated by Django 5.1.2 on 2025-03-26 17:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("api", "0011_alter_user_email"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="id_card",
|
||||
field=models.CharField(blank=True, max_length=255, unique=True),
|
||||
),
|
||||
]
|
@ -9,12 +9,11 @@ from django.utils import timezone
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
email = models.EmailField(unique=True, blank=True, null=True)
|
||||
address = models.CharField(max_length=255, blank=True)
|
||||
mobile = models.CharField(max_length=255, blank=True, unique=True, default=0)
|
||||
mobile = models.CharField(max_length=255, blank=True, unique=True, null=True)
|
||||
designation = models.CharField(max_length=255, blank=True)
|
||||
acc_no = models.CharField(max_length=255, blank=True)
|
||||
id_card = models.CharField(max_length=255, blank=True)
|
||||
id_card = models.CharField(max_length=255, blank=True, unique=True)
|
||||
verified = models.BooleanField(default=False)
|
||||
dob = models.DateField(blank=True, null=True)
|
||||
terms_accepted = models.BooleanField(default=False)
|
||||
|
@ -16,7 +16,7 @@ from .views import (
|
||||
RetrieveUpdateDestroyAtollView,
|
||||
ListCreateIslandView,
|
||||
RetrieveUpdateDestroyIslandView,
|
||||
ListUserByIDCardView,
|
||||
filter_user,
|
||||
)
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ urlpatterns = [
|
||||
# path("auth/", CustomAuthToken.as_view()),
|
||||
path("users/", ListUserView.as_view(), name="users"),
|
||||
path("users/<int:pk>/", UserDetailAPIView.as_view(), name="user-detail"),
|
||||
path("users/idcard/", ListUserByIDCardView.as_view(), name="users-idcard"),
|
||||
path("users/filter/", filter_user, name="filter-users"),
|
||||
path("healthcheck/", healthcheck, name="healthcheck"),
|
||||
path("test/", test_email, name="testemail"),
|
||||
path("atolls/", ListAtollView.as_view(), name="atolls"),
|
||||
|
23
api/views.py
23
api/views.py
@ -20,6 +20,7 @@ from django_filters.rest_framework import DjangoFilterBackend
|
||||
import re
|
||||
from typing import cast, Dict, Any
|
||||
from django.core.mail import send_mail
|
||||
from django.db.models import Q
|
||||
|
||||
# local apps import
|
||||
from .serializers import (
|
||||
@ -196,6 +197,28 @@ class ListUserView(StaffEditorPermissionMixin, generics.ListAPIView):
|
||||
queryset = User.objects.all()
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
def filter_user(request):
|
||||
id_card = request.GET.get("id_card", "").strip() or None
|
||||
mobile = request.GET.get("mobile", "").strip() or None
|
||||
|
||||
if not id_card and not mobile:
|
||||
return Response({"ok": False})
|
||||
|
||||
filters = Q()
|
||||
if id_card is not None:
|
||||
filters |= Q(id_card=id_card)
|
||||
if mobile is not None:
|
||||
filters |= Q(mobile=mobile)
|
||||
|
||||
user = User.objects.filter(filters).first()
|
||||
|
||||
print(f"Querying with filters: {filters}")
|
||||
print(f"Found user: {user}")
|
||||
|
||||
return Response({"ok": True if user else False})
|
||||
|
||||
|
||||
class ListUserByIDCardView(generics.ListAPIView):
|
||||
# Create user API view
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
|
Loading…
x
Reference in New Issue
Block a user