diff --git a/CHANGELOG.md b/CHANGELOG.md index 815a58c896..96444bb8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to - Allow on-demand page size on the order and enrollment endpoints - Add yarn cli to generate joanie api client in TypeScript +- Add model and endpoints for wishlist feature ### Removed @@ -36,7 +37,6 @@ and this project adheres to - Add synchronization for course runs - Add make dbshell cmd to access database in cli -- Add model and endpoints for wishlist feature ### Fixed diff --git a/src/backend/joanie/core/api.py b/src/backend/joanie/core/api.py index 8aec5ea573..a149b6cf06 100644 --- a/src/backend/joanie/core/api.py +++ b/src/backend/joanie/core/api.py @@ -451,7 +451,7 @@ class CourseWishViewSet( permission_classes = [permissions.IsAuthenticated] def get_queryset(self): - """Custom queryset to get user addresses""" + """Custom queryset to get user wishlist""" user = User.update_or_create_from_request_user(request_user=self.request.user) queryset = user.wishlists.all() course_code = self.request.query_params.get("course_code") @@ -460,6 +460,6 @@ def get_queryset(self): return queryset def perform_create(self, serializer): - """Create a new address for user authenticated""" + """Create a new wish for user authenticated""" user = User.update_or_create_from_request_user(request_user=self.request.user) serializer.save(owner=user) diff --git a/src/backend/joanie/core/models/wishlist.py b/src/backend/joanie/core/models/wishlist.py index 9c5de4e8dc..9059515116 100644 --- a/src/backend/joanie/core/models/wishlist.py +++ b/src/backend/joanie/core/models/wishlist.py @@ -16,7 +16,7 @@ class CourseWish(BaseModel): owner = models.ForeignKey( to=User, verbose_name=_("Owner"), - related_name="wishlists", + related_name="wishlist", on_delete=models.PROTECT, ) diff --git a/src/backend/joanie/tests/core/test_api_wishlist.py b/src/backend/joanie/tests/core/test_api_wishlist.py index 6483f8fd75..ff0ef9d48d 100644 --- a/src/backend/joanie/tests/core/test_api_wishlist.py +++ b/src/backend/joanie/tests/core/test_api_wishlist.py @@ -76,7 +76,7 @@ def test_api_wish_get_wish_for_new_user(self): self.assertTrue(models.User.objects.filter(username=username).exists()) def test_api_wish_get_wishes(self): - """Get wish for a user in db with two wish linked to him""" + """Get wish for a user in db with two wishes linked to him""" user = factories.UserFactory() course1 = factories.CourseFactory() course2 = factories.CourseFactory() @@ -96,7 +96,7 @@ def test_api_wish_get_wishes(self): self.assertEqual(results[1]["id"], str(wish2.id)) def test_api_wish_get_wishes_filter_by_code(self): - """Get wish for a user in db with two wish linked to him""" + """Get wish for a user in db with two wishes linked to him""" user = factories.UserFactory() course = factories.CourseFactory() token = self.get_user_token(user.username) @@ -104,9 +104,7 @@ def test_api_wish_get_wishes_filter_by_code(self): factories.CourseWishFactory.create(owner=user) get_url = f"/api/v1.0/wishlist/?course_code={course.code}" - response = self.client.get( - get_url, HTTP_AUTHORIZATION=f"Bearer {token}" - ) + response = self.client.get(get_url, HTTP_AUTHORIZATION=f"Bearer {token}") self.assertEqual(response.status_code, 200) results = response.data["results"] @@ -115,16 +113,14 @@ def test_api_wish_get_wishes_filter_by_code(self): self.assertEqual(results[0]["id"], str(wish.id)) def test_api_wish_get_wish(self): - """Get wish for a user in db with two wish linked to him""" + """Get wish for a user in db with two wishes linked to him""" user = factories.UserFactory() token = self.get_user_token(user.username) wish = factories.CourseWishFactory.create(owner=user) factories.CourseWishFactory.create(owner=user) get_url = f"/api/v1.0/wishlist/{wish.id}/" - response = self.client.get( - get_url, HTTP_AUTHORIZATION=f"Bearer {token}" - ) + response = self.client.get(get_url, HTTP_AUTHORIZATION=f"Bearer {token}") self.assertEqual(response.status_code, 200) data = response.data