Coverage for postrfp / ref / handlers / readers.py: 100%
13 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 01:35 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-12-03 01:35 +0000
1"""
2HTTP handler functions supporting a consumer of the content
3managed by this system
4"""
6from typing import Optional
8from sqlalchemy.orm import Session
10from postrfp.shared.pager import Pager
11from postrfp.shared.decorators import http
12from postrfp.model import User
13from postrfp.shared.serial.refmodels import (
14 ListResponse,
15 ContentDocument,
16)
17from postrfp.ref.service.search_service import search_content_by_subject
20@http
21def get_search(
22 session: Session,
23 user: User,
24 q_subject_id: Optional[int] = None,
25 q_term: Optional[str] = None,
26 pager: Optional[Pager] = None,
27) -> ListResponse:
28 """
29 List content items related to a specific subject
31 Returns a list of content items that are associated with the specified subject
32 and that the current user has permission to view. Results can be filtered
33 by content title and are paginated.
34 """
35 if pager is None:
36 pager = Pager(page=1, page_size=20)
38 # Use service function to perform the search
39 total_records, records = search_content_by_subject(
40 session=session,
41 user_org_id=user.org_id,
42 subject_id=q_subject_id,
43 search_term=q_term,
44 pager=pager,
45 )
47 return ListResponse(
48 items=[ContentDocument.model_validate(content) for content in records],
49 pagination=pager.as_pagination(total_records, len(records)),
50 )