mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 05:26:07 +00:00
Refactor Docker configuration and API endpoints
- Merged production and development Docker configurations - Updated Dockerfile to use multi-stage build - Removed separate Dockerfile.prod - Modified docker-compose.yml for production settings - Added new API endpoints for user filtering by ID card - Updated serializers and views for Atoll and Island management - Enhanced user and atoll-related filters and views
This commit is contained in:
@ -13,4 +13,8 @@ class UserFilter(django_filters.FilterSet):
|
||||
"username",
|
||||
"last_name",
|
||||
"first_name",
|
||||
"email",
|
||||
"is_active",
|
||||
"id_card",
|
||||
"mobile",
|
||||
]
|
||||
|
@ -46,9 +46,19 @@ class CustomReadOnlyUserSerializer(serializers.ModelSerializer):
|
||||
"username",
|
||||
"mobile",
|
||||
"address",
|
||||
"id_card",
|
||||
)
|
||||
|
||||
|
||||
class CustomReadOnlyUserByIDCardSerializer(serializers.ModelSerializer):
|
||||
"""serializer for the user object"""
|
||||
|
||||
class Meta: # type: ignore
|
||||
model = User
|
||||
# fields = "__all__"
|
||||
fields = ("id_card",)
|
||||
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
"""serializer for the user object"""
|
||||
|
||||
@ -93,13 +103,16 @@ class KnoxTokenSerializer(serializers.ModelSerializer):
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class AtollSerializer(serializers.ModelSerializer):
|
||||
class Meta: # type: ignore
|
||||
model = Atoll
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class IslandSerializer(serializers.ModelSerializer):
|
||||
class Meta: # type: ignore
|
||||
model = Island
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class AtollSerializer(serializers.ModelSerializer):
|
||||
islands = IslandSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta: # type: ignore
|
||||
model = Atoll
|
||||
fields = "__all__"
|
||||
depth = 2
|
||||
|
@ -11,10 +11,12 @@ from .views import (
|
||||
UserDetailAPIView,
|
||||
healthcheck,
|
||||
test_email,
|
||||
ListCreateAtollView,
|
||||
ListAtollView,
|
||||
CreateAtollView,
|
||||
RetrieveUpdateDestroyAtollView,
|
||||
ListCreateIslandView,
|
||||
RetrieveUpdateDestroyIslandView,
|
||||
ListUserByIDCardView,
|
||||
)
|
||||
|
||||
|
||||
@ -28,9 +30,11 @@ 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("healthcheck/", healthcheck, name="healthcheck"),
|
||||
path("test/", test_email, name="testemail"),
|
||||
path("atolls/", ListCreateAtollView.as_view(), name="atolls"),
|
||||
path("atolls/", ListAtollView.as_view(), name="atolls"),
|
||||
path("atolls/new/", CreateAtollView.as_view(), name="atoll-new"),
|
||||
path(
|
||||
"atolls/<int:pk>/",
|
||||
RetrieveUpdateDestroyAtollView.as_view(),
|
||||
|
20
api/views.py
20
api/views.py
@ -28,6 +28,7 @@ from .serializers import (
|
||||
AuthSerializer,
|
||||
CustomUserSerializer,
|
||||
CustomReadOnlyUserSerializer,
|
||||
CustomReadOnlyUserByIDCardSerializer,
|
||||
)
|
||||
|
||||
|
||||
@ -195,6 +196,16 @@ class ListUserView(StaffEditorPermissionMixin, generics.ListAPIView):
|
||||
queryset = User.objects.all()
|
||||
|
||||
|
||||
class ListUserByIDCardView(generics.ListAPIView):
|
||||
# Create user API view
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = CustomReadOnlyUserByIDCardSerializer
|
||||
filter_backends = [DjangoFilterBackend]
|
||||
filterset_fields = "__all__"
|
||||
filterset_class = UserFilter
|
||||
queryset = User.objects.all()
|
||||
|
||||
|
||||
class UserDetailAPIView(StaffEditorPermissionMixin, generics.RetrieveAPIView):
|
||||
queryset = User.objects.all()
|
||||
serializer_class = CustomReadOnlyUserSerializer
|
||||
@ -228,7 +239,7 @@ def test_email(request):
|
||||
return Response({"status": "ok"}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
class ListCreateAtollView(StaffEditorPermissionMixin, generics.ListCreateAPIView):
|
||||
class CreateAtollView(StaffEditorPermissionMixin, generics.CreateAPIView):
|
||||
serializer_class = AtollSerializer
|
||||
queryset = Atoll.objects.all()
|
||||
|
||||
@ -242,6 +253,13 @@ class ListCreateAtollView(StaffEditorPermissionMixin, generics.ListCreateAPIView
|
||||
return super().create(request, *args, **kwargs)
|
||||
|
||||
|
||||
class ListAtollView(generics.ListAPIView):
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = AtollSerializer
|
||||
queryset = Atoll.objects.all()
|
||||
throttle_classes = () # override throttling
|
||||
|
||||
|
||||
class RetrieveUpdateDestroyAtollView(
|
||||
StaffEditorPermissionMixin, generics.RetrieveUpdateDestroyAPIView
|
||||
):
|
||||
|
Reference in New Issue
Block a user