22
33from common_library .pagination_tools import iter_pagination_params
44from fastapi import Depends
5+ from models_library .api_schemas_catalog .services import ServiceListFilters
56from models_library .basic_types import VersionStr
67from models_library .products import ProductName
7- from models_library .rest_pagination import MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE
8+ from models_library .rest_pagination import (
9+ MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE ,
10+ PageMetaInfoLimitOffset ,
11+ )
812from models_library .services_enums import ServiceType
913from models_library .services_history import ServiceRelease
1014from models_library .users import UserID
1115from packaging .version import Version
16+ from pydantic import NonNegativeInt , PositiveInt
1217
1318from .models .schemas .solvers import Solver , SolverKeyId
1419from .services_rpc .catalog import CatalogService
@@ -74,27 +79,25 @@ async def get_latest_release(
7479 async def solver_release_history (
7580 self ,
7681 * ,
77- user_id : int ,
82+ user_id : UserID ,
7883 solver_key : SolverKeyId ,
79- product_name : str ,
80- ) -> list [Solver ]:
84+ product_name : ProductName ,
85+ offset : NonNegativeInt ,
86+ limit : PositiveInt ,
87+ ) -> tuple [list [Solver ], PageMetaInfoLimitOffset ]:
8188
82- service_releases : list [ServiceRelease ] = []
83- for page_params in iter_pagination_params (limit = DEFAULT_PAGINATION_LIMIT ):
84- releases , page_meta = await self ._catalog_service .list_release_history (
85- user_id = user_id ,
86- service_key = solver_key ,
87- product_name = product_name ,
88- offset = page_params .offset ,
89- limit = page_params .limit ,
90- )
91- page_params .total_number_of_items = page_meta .total
92- service_releases .extend (releases )
89+ releases , page_meta = await self ._catalog_service .list_release_history (
90+ user_id = user_id ,
91+ service_key = solver_key ,
92+ product_name = product_name ,
93+ offset = offset ,
94+ limit = limit ,
95+ )
9396
9497 service_instance = await self ._catalog_service .get (
9598 user_id = user_id ,
9699 name = solver_key ,
97- version = service_releases [- 1 ].version ,
100+ version = releases [- 1 ].version ,
98101 product_name = product_name ,
99102 )
100103
@@ -106,5 +109,25 @@ async def solver_release_history(
106109 name = service_instance .name ,
107110 service = service ,
108111 )
109- for service in service_releases
110- ]
112+ for service in releases
113+ ], page_meta
114+
115+ async def latest_solvers (
116+ self ,
117+ * ,
118+ user_id : UserID ,
119+ product_name : ProductName ,
120+ offset : NonNegativeInt ,
121+ limit : PositiveInt ,
122+ ) -> tuple [list [Solver ], PageMetaInfoLimitOffset ]:
123+ """Lists the latest solvers with pagination."""
124+ services , page_meta = await self ._catalog_service .list_latest_releases (
125+ user_id = user_id ,
126+ product_name = product_name ,
127+ offset = offset ,
128+ limit = limit ,
129+ filters = ServiceListFilters (service_type = ServiceType .COMPUTATIONAL ),
130+ )
131+
132+ solvers = [Solver .create_from_service (service ) for service in services ]
133+ return solvers , page_meta
0 commit comments