Skip to content

Commit 57941ba

Browse files
committed
Merge branch 'develop' of https://github.com/Kalgoc/piggy-wallet-backend into develop
2 parents 708ab39 + f2c5d0e commit 57941ba

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

piggies/views.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,25 @@ def get_user_id_from_token(self, request):
3333
def list(self, request):
3434
try:
3535
username = self.get_user_id_from_token(request)
36+
User = get_user_model()
37+
users = [{"user_id": str(x.user_id), "first_name": x.first_name} for x in User.objects.all()]
38+
39+
filtered_users = []
40+
41+
for user in users:
42+
if user["user_id"] != username:
43+
filtered_users.append(user)
44+
3645
piggies = Piggies.objects.filter(username=username)
3746
serializer = PiggiesSerializer(piggies, many=True)
38-
return Response(data=serializer.data)
47+
final_users = []
48+
49+
for pig in serializer.data:
50+
for user in filtered_users:
51+
if str(pig["piggy"]) == user["user_id"]:
52+
final_users.append(user)
53+
54+
return Response(data=final_users)
3955
except Piggies.DoesNotExist:
4056
return Response({"error": "Piggies not found"}, status=status.HTTP_404_NOT_FOUND)
4157
except Exception as e:

0 commit comments

Comments
 (0)