From b9b0c00b740b7341b0af80a18afbc21af6d90a49 Mon Sep 17 00:00:00 2001 From: imperosol Date: Sat, 2 May 2026 19:31:03 +0200 Subject: [PATCH] feat: add links to response of `GET /api/club/{club_id}` --- club/api.py | 2 +- club/schemas.py | 6 ++++++ club/tests/test_club_controller.py | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/club/api.py b/club/api.py index d6a8c97d..4a055e2c 100644 --- a/club/api.py +++ b/club/api.py @@ -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 ) diff --git a/club/schemas.py b/club/schemas.py index aa4aa4e5..99d05fc1 100644 --- a/club/schemas.py +++ b/club/schemas.py @@ -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): diff --git a/club/tests/test_club_controller.py b/club/tests/test_club_controller.py index b6248e01..18d09020 100644 --- a/club/tests/test_club_controller.py +++ b/club/tests/test_club_controller.py @@ -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