mirror of
https://github.com/narrrl/holy-flavor-rater.git
synced 2026-11-03 16:41:27 +01:00
added public profiles
This commit is contained in:
1 parent
f1f974bd2a
commit
3a9eec3f22
4 files changed
+171
-2
No files matched your search
@@ -127,6 +127,23 @@ class UserViewSet(viewsets.ModelViewSet):
|
||||
else:
|
||||
return Response({'error': 'Invalid verification code'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@action(detail=False, methods=['get'], permission_classes=[permissions.AllowAny], url_path='profile/(?P<username>[^/.]+)')
|
||||
def public_profile(self, request, username=None):
|
||||
try:
|
||||
user = User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
return Response({'error': 'User not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
ratings = user.ratings.select_related('flavor', 'flavor__category').all()
|
||||
# Sort by score descending to highlight favorites
|
||||
ratings = sorted(ratings, key=lambda x: x.score, reverse=True)
|
||||
|
||||
return Response({
|
||||
'username': user.username,
|
||||
'theme': user.theme,
|
||||
'ratings': RatingSerializer(ratings, many=True).data
|
||||
})
|
||||
|
||||
@action(detail=False, methods=['get'])
|
||||
def me(self, request):
|
||||
serializer = self.get_serializer(request.user)
|
||||
|
||||
Reference in new issue
Block a user