11import logging
22from typing import List
33
4- from fastapi import APIRouter , Depends , HTTPException
4+ from fastapi import APIRouter , Depends , HTTPException , Query
55from sqlalchemy import func
66from sqlmodel import select
77
2727 response_model = APIResponse [List [OrganizationPublic ]],
2828 description = load_description ("organization/list.md" ),
2929)
30- def read_organizations (session : SessionDep , skip : int = 0 , limit : int = 100 ):
30+ def read_organizations (
31+ session : SessionDep ,
32+ skip : int = Query (0 , ge = 0 ),
33+ limit : int = Query (100 , ge = 1 , le = 100 ),
34+ ) -> APIResponse [List [OrganizationPublic ]]:
3135 count_statement = select (func .count ()).select_from (Organization )
3236 count = session .exec (count_statement ).one ()
3337
3438 statement = select (Organization ).offset (skip ).limit (limit )
3539 organizations = session .exec (statement ).all ()
3640
37- return APIResponse .success_response (organizations )
41+ has_more = (skip + limit ) < count
42+ return APIResponse .success_response (organizations , metadata = {"has_more" : has_more })
3843
3944
4045# Create a new organization
@@ -44,7 +49,9 @@ def read_organizations(session: SessionDep, skip: int = 0, limit: int = 100):
4449 response_model = APIResponse [OrganizationPublic ],
4550 description = load_description ("organization/create.md" ),
4651)
47- def create_new_organization (* , session : SessionDep , org_in : OrganizationCreate ):
52+ def create_new_organization (
53+ * , session : SessionDep , org_in : OrganizationCreate
54+ ) -> APIResponse [OrganizationPublic ]:
4855 new_org = create_organization (session = session , org_create = org_in )
4956 return APIResponse .success_response (new_org )
5057
@@ -55,7 +62,9 @@ def create_new_organization(*, session: SessionDep, org_in: OrganizationCreate):
5562 response_model = APIResponse [OrganizationPublic ],
5663 description = load_description ("organization/get.md" ),
5764)
58- def read_organization (* , session : SessionDep , org_id : int ):
65+ def read_organization (
66+ * , session : SessionDep , org_id : int
67+ ) -> APIResponse [OrganizationPublic ]:
5968 """
6069 Retrieve an organization by ID.
6170 """
@@ -75,7 +84,7 @@ def read_organization(*, session: SessionDep, org_id: int):
7584)
7685def update_organization (
7786 * , session : SessionDep , org_id : int , org_in : OrganizationUpdate
78- ):
87+ ) -> APIResponse [ OrganizationPublic ] :
7988 org = get_organization_by_id (session = session , org_id = org_id )
8089 if org is None :
8190 logger .error (
@@ -103,7 +112,7 @@ def update_organization(
103112 include_in_schema = False ,
104113 description = load_description ("organization/delete.md" ),
105114)
106- def delete_organization (session : SessionDep , org_id : int ):
115+ def delete_organization (session : SessionDep , org_id : int ) -> APIResponse [ None ] :
107116 org = get_organization_by_id (session = session , org_id = org_id )
108117 if org is None :
109118 logger .error (
0 commit comments