Skip to content

Commit

Permalink
Merge pull request #36 from Saku-SE/develop
Browse files Browse the repository at this point in the history
Develop: recent_auctions API ready for merge onto main branch
  • Loading branch information
aroodgar committed May 20, 2023
2 parents 8be24f1 + b4ea7c3 commit 6f0b44a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions saku/auction/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ def test_not_found_auction(self):
self.assertIn(
ErrorDetail(string="Not found.", code="not_found"), response.data["detail"]
)

def test_get_recent_auctions_list(self):
response = self.client.get(path="/auction/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(2, len(response.data))
self.assertEqual("auction2", response.data[0]["name"])


class EditAuctionTest(APITestCase):
Expand Down
2 changes: 2 additions & 0 deletions saku/auction/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
AuctionScoreDetail,
CityList,
AuctionsByCityView,
RecentAuctionsView,
)

urlpatterns = [
path("", CreateListAuction.as_view(), name="auction"),
path("categories/", CategoryList.as_view()),
path("<str:token>", DetailedAuction.as_view(), name="detailed_auction"),
path("recent/<int:limit>", RecentAuctionsView.as_view(), name="recent_auctions"),
path(
"remove-picture/<str:token>",
DeleteAuctionPicture.as_view(),
Expand Down
14 changes: 13 additions & 1 deletion saku/auction/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,16 @@ def get(self, request, city_id):
}
}
return Response(response, status=status.HTTP_200_OK)


class RecentAuctionsView(generics.ListAPIView):
permission_classes = (IsAuthenticated,)

def get(self, request, limit):
recent_auctions = Auction.objects.order_by('-created_at')
if len(recent_auctions) > limit:
recent_auctions = recent_auctions[:limit]
serializer = GetAuctionRequestSerializer(
recent_auctions, many=True, context={"request": request}
)
return Response(serializer.data, status=status.HTTP_200_OK)

0 comments on commit 6f0b44a

Please sign in to comment.