mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-27 06:27:05 -05:00
feat: Introduce lists and reviews apps, refactor user list functionality from accounts, and add user profile fields.
This commit is contained in:
@@ -13,7 +13,7 @@ from apps.api.v1.serializers.accounts import (
|
||||
PrivacySettingsSerializer,
|
||||
SecuritySettingsSerializer,
|
||||
UserStatisticsSerializer,
|
||||
TopListSerializer,
|
||||
UserListSerializer,
|
||||
AccountUpdateSerializer,
|
||||
ProfileUpdateSerializer,
|
||||
ThemePreferenceSerializer,
|
||||
@@ -26,10 +26,10 @@ from apps.accounts.services import UserDeletionService
|
||||
from apps.accounts.models import (
|
||||
User,
|
||||
UserProfile,
|
||||
TopList,
|
||||
UserNotification,
|
||||
NotificationPreference,
|
||||
)
|
||||
from apps.lists.models import UserList
|
||||
import logging
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import api_view, permission_classes
|
||||
@@ -831,7 +831,7 @@ def check_user_deletion_eligibility(request, user_id):
|
||||
user, "uploaded_ride_photos", user.__class__.objects.none()
|
||||
).count(),
|
||||
"top_lists": getattr(
|
||||
user, "top_lists", user.__class__.objects.none()
|
||||
user, "user_lists", user.__class__.objects.none()
|
||||
).count(),
|
||||
"edit_submissions": getattr(
|
||||
user, "edit_submissions", user.__class__.objects.none()
|
||||
@@ -1318,7 +1318,7 @@ def get_user_statistics(request):
|
||||
"rides_ridden": RideReview.objects.filter(user=user).values("ride").distinct().count(),
|
||||
"reviews_written": ParkReview.objects.filter(user=user).count() + RideReview.objects.filter(user=user).count(),
|
||||
"photos_uploaded": total_photos_uploaded,
|
||||
"top_lists_created": TopList.objects.filter(user=user).count(),
|
||||
"top_lists_created": UserList.objects.filter(user=user).count(),
|
||||
"member_since": user.date_joined,
|
||||
"last_activity": user.last_login,
|
||||
}
|
||||
@@ -1335,7 +1335,7 @@ def get_user_statistics(request):
|
||||
summary="Get user's top lists",
|
||||
description="Get all top lists created by the authenticated user.",
|
||||
responses={
|
||||
200: TopListSerializer(many=True),
|
||||
200: UserListSerializer(many=True),
|
||||
401: {"description": "Authentication required"},
|
||||
},
|
||||
tags=["User Content"],
|
||||
@@ -1344,8 +1344,8 @@ def get_user_statistics(request):
|
||||
@permission_classes([IsAuthenticated])
|
||||
def get_user_top_lists(request):
|
||||
"""Get user's top lists."""
|
||||
top_lists = TopList.objects.filter(user=request.user).order_by("-created_at")
|
||||
serializer = TopListSerializer(top_lists, many=True)
|
||||
top_lists = UserList.objects.filter(user=request.user).order_by("-created_at")
|
||||
serializer = UserListSerializer(top_lists, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
@@ -1353,9 +1353,9 @@ def get_user_top_lists(request):
|
||||
operation_id="create_top_list",
|
||||
summary="Create a new top list",
|
||||
description="Create a new top list for the authenticated user.",
|
||||
request=TopListSerializer,
|
||||
request=UserListSerializer,
|
||||
responses={
|
||||
201: TopListSerializer,
|
||||
201: UserListSerializer,
|
||||
400: {"description": "Validation error"},
|
||||
},
|
||||
tags=["User Content"],
|
||||
@@ -1364,7 +1364,7 @@ def get_user_top_lists(request):
|
||||
@permission_classes([IsAuthenticated])
|
||||
def create_top_list(request):
|
||||
"""Create a new top list."""
|
||||
serializer = TopListSerializer(data=request.data, context={"request": request})
|
||||
serializer = UserListSerializer(data=request.data, context={"request": request})
|
||||
|
||||
if serializer.is_valid():
|
||||
serializer.save(user=request.user)
|
||||
@@ -1377,9 +1377,9 @@ def create_top_list(request):
|
||||
operation_id="update_top_list",
|
||||
summary="Update a top list",
|
||||
description="Update a top list owned by the authenticated user.",
|
||||
request=TopListSerializer,
|
||||
request=UserListSerializer,
|
||||
responses={
|
||||
200: TopListSerializer,
|
||||
200: UserListSerializer,
|
||||
400: {"description": "Validation error"},
|
||||
404: {"description": "Top list not found"},
|
||||
},
|
||||
@@ -1390,14 +1390,14 @@ def create_top_list(request):
|
||||
def update_top_list(request, list_id):
|
||||
"""Update a top list."""
|
||||
try:
|
||||
top_list = TopList.objects.get(id=list_id, user=request.user)
|
||||
except TopList.DoesNotExist:
|
||||
top_list = UserList.objects.get(id=list_id, user=request.user)
|
||||
except UserList.DoesNotExist:
|
||||
return Response(
|
||||
{"error": "Top list not found"},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
|
||||
serializer = TopListSerializer(
|
||||
serializer = UserListSerializer(
|
||||
top_list, data=request.data, partial=True, context={"request": request}
|
||||
)
|
||||
|
||||
@@ -1423,10 +1423,10 @@ def update_top_list(request, list_id):
|
||||
def delete_top_list(request, list_id):
|
||||
"""Delete a top list."""
|
||||
try:
|
||||
top_list = TopList.objects.get(id=list_id, user=request.user)
|
||||
top_list = UserList.objects.get(id=list_id, user=request.user)
|
||||
top_list.delete()
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
except TopList.DoesNotExist:
|
||||
except UserList.DoesNotExist:
|
||||
return Response(
|
||||
{"error": "Top list not found"},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
|
||||
Reference in New Issue
Block a user