mirror of
https://github.com/ae-utbm/sith.git
synced 2026-05-13 12:38:09 +00:00
feat: add links to response of GET /api/club/{club_id}
This commit is contained in:
+1
-1
@@ -41,7 +41,7 @@ class ClubController(ControllerBase):
|
||||
queryset=Membership.objects.ongoing().select_related("user", "role"),
|
||||
)
|
||||
return self.get_object_or_exception(
|
||||
Club.objects.prefetch_related(prefetch), id=club_id
|
||||
Club.objects.prefetch_related(prefetch, "links"), id=club_id
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from typing import Annotated
|
||||
|
||||
from django.db.models import Q
|
||||
from ninja import FilterLookup, FilterSchema, ModelSchema
|
||||
from pydantic import HttpUrl
|
||||
|
||||
from club.models import Club, ClubRole, Membership
|
||||
from core.schemas import NonEmptyStr, SimpleUserSchema
|
||||
@@ -62,6 +63,11 @@ class ClubSchema(ModelSchema):
|
||||
fields = ["id", "name", "logo", "is_active", "short_description", "address"]
|
||||
|
||||
members: list[ClubMemberSchema]
|
||||
links: list[HttpUrl]
|
||||
|
||||
@staticmethod
|
||||
def resolve_links(obj: Club):
|
||||
return [link.url for link in obj.links.all()]
|
||||
|
||||
|
||||
class UserMembershipSchema(ModelSchema):
|
||||
|
||||
@@ -88,8 +88,8 @@ class TestFetchClub:
|
||||
def test_fetch_club_nb_queries(self, client: Client, club: Club):
|
||||
user = subscriber_user.make()
|
||||
client.force_login(user)
|
||||
with assertNumQueries(6):
|
||||
with assertNumQueries(7):
|
||||
# - 4 queries for authentication
|
||||
# - 2 queries for the actual data
|
||||
# - 3 queries for the actual data
|
||||
res = client.get(reverse("api:fetch_club", kwargs={"club_id": club.id}))
|
||||
assert res.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user