mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Migrates lookups
* products * files * Groups * Clubs * Accounting
This commit is contained in:
23
accounting/api.py
Normal file
23
accounting/api.py
Normal file
@ -0,0 +1,23 @@
|
||||
from typing import Annotated
|
||||
|
||||
from annotated_types import MinLen
|
||||
from ninja_extra import ControllerBase, api_controller, paginate, route
|
||||
from ninja_extra.pagination import PageNumberPaginationExtra
|
||||
from ninja_extra.schemas import PaginatedResponseSchema
|
||||
|
||||
from accounting.models import ClubAccount, Company
|
||||
from accounting.schemas import ClubAccountSchema, CompanySchema
|
||||
from core.api_permissions import CanAccessLookup
|
||||
|
||||
|
||||
@api_controller("/lookup", permissions=[CanAccessLookup])
|
||||
class AccountingController(ControllerBase):
|
||||
@route.get("/club-account", response=PaginatedResponseSchema[ClubAccountSchema])
|
||||
@paginate(PageNumberPaginationExtra, page_size=50)
|
||||
def search_club_account(self, search: Annotated[str, MinLen(1)]):
|
||||
return ClubAccount.objects.filter(name__icontains=search).values()
|
||||
|
||||
@route.get("/company", response=PaginatedResponseSchema[CompanySchema])
|
||||
@paginate(PageNumberPaginationExtra, page_size=50)
|
||||
def search_company(self, search: Annotated[str, MinLen(1)]):
|
||||
return Company.objects.filter(name__icontains=search).values()
|
15
accounting/schemas.py
Normal file
15
accounting/schemas.py
Normal file
@ -0,0 +1,15 @@
|
||||
from ninja import ModelSchema
|
||||
|
||||
from accounting.models import ClubAccount, Company
|
||||
|
||||
|
||||
class ClubAccountSchema(ModelSchema):
|
||||
class Meta:
|
||||
model = ClubAccount
|
||||
fields = ["id", "name"]
|
||||
|
||||
|
||||
class CompanySchema(ModelSchema):
|
||||
class Meta:
|
||||
model = Company
|
||||
fields = ["id", "name"]
|
Reference in New Issue
Block a user