refactor(backend): standardize model-to-response conversion naming

Issue #8: Inconsistent naming for model-to-response conversion functions.

Changes:
- Rename build_invite_response to _to_invite_response (invites.py)
- Rename _map_counter_record to _to_counter_record_response (audit.py)
- Rename _map_sum_record to _to_sum_record_response (audit.py)

All conversion functions now follow the _to_X_response pattern,
using underscore prefix for module-private functions.
This commit is contained in:
counterweight 2025-12-22 09:16:05 +01:00
parent fdab4a5dac
commit e7e3c97102
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 10 additions and 8 deletions

View file

@ -61,7 +61,9 @@ async def paginate_with_user_email(
return records, total, calculate_total_pages(total, per_page)
def _map_counter_record(record: CounterRecord, email: str) -> CounterRecordResponse:
def _to_counter_record_response(
record: CounterRecord, email: str
) -> CounterRecordResponse:
return CounterRecordResponse(
id=record.id,
user_email=email,
@ -71,7 +73,7 @@ def _map_counter_record(record: CounterRecord, email: str) -> CounterRecordRespo
)
def _map_sum_record(record: SumRecord, email: str) -> SumRecordResponse:
def _to_sum_record_response(record: SumRecord, email: str) -> SumRecordResponse:
return SumRecordResponse(
id=record.id,
user_email=email,
@ -91,7 +93,7 @@ async def get_counter_records(
) -> PaginatedCounterRecords:
"""Get paginated counter action records."""
records, total, _ = await paginate_with_user_email(
db, CounterRecord, page, per_page, _map_counter_record
db, CounterRecord, page, per_page, _to_counter_record_response
)
return create_paginated_response(records, total, page, per_page)
@ -105,7 +107,7 @@ async def get_sum_records(
) -> PaginatedSumRecords:
"""Get paginated sum action records."""
records, total, _ = await paginate_with_user_email(
db, SumRecord, page, per_page, _map_sum_record
db, SumRecord, page, per_page, _to_sum_record_response
)
return create_paginated_response(records, total, page, per_page)

View file

@ -31,7 +31,7 @@ admin_router = APIRouter(prefix="/api/admin", tags=["admin"])
MAX_INVITE_COLLISION_RETRIES = 3
def build_invite_response(invite: Invite) -> InviteResponse:
def _to_invite_response(invite: Invite) -> InviteResponse:
"""Build an InviteResponse from an Invite with loaded relationships."""
return InviteResponse(
id=invite.id,
@ -150,7 +150,7 @@ async def create_invite(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Failed to create invite",
)
return build_invite_response(invite)
return _to_invite_response(invite)
@admin_router.get("/invites", response_model=PaginatedInviteRecords)
@ -197,7 +197,7 @@ async def list_all_invites(
invites = result.scalars().all()
# Build responses using preloaded relationships
records = [build_invite_response(invite) for invite in invites]
records = [_to_invite_response(invite) for invite in invites]
return create_paginated_response(records, total, page, per_page)
@ -230,7 +230,7 @@ async def revoke_invite(
await db.commit()
await db.refresh(invite)
return build_invite_response(invite)
return _to_invite_response(invite)
# All routers from this module for easy registration