Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit c39a523

Browse files
Solved the AppRating Bug in the view that always give point to user
1 parent 852c27a commit c39a523

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed
175 Bytes
Binary file not shown.

Profile/views.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,22 @@ class AppRating(APIView):
189189
authentication_classes = [TokenAuthentication]
190190

191191
def post(self, request, *args):
192-
user_wallet = Wallet.objects.get(user=request.user)
192+
# Check if the user already has an object for App rating
193+
user = request.user
194+
existing_rating = RecentEarnings.objects.filter(user=user, way_to_earn='App Rating').exists()
195+
196+
if existing_rating:
197+
return Response({'message': 'You have already received points for App rating.'}, status=status.HTTP_400_BAD_REQUEST)
198+
199+
user_wallet = Wallet.objects.get(user=user)
193200
user_wallet.points += 30
194201
user_wallet.save()
195202

196203
# Adding entry to recent earnings
197-
user_recent_earning = RecentEarnings.objects.create(user=request.user, way_to_earn="App Rating", point_earned=30)
204+
user_recent_earning = RecentEarnings.objects.create(user=user, way_to_earn="App Rating", point_earned=30)
198205
user_recent_earning.save()
199206

200-
return Response({"message": "Done"}, status=status.HTTP_200_OK)
201-
207+
return Response({"message": "Points added for App rating."}, status=status.HTTP_200_OK)
202208

203209

204210

0 commit comments

Comments
 (0)