Working version
This commit is contained in:
@ -1,15 +1,21 @@
|
||||
from litestar import Router
|
||||
|
||||
from app.controllers.fiscal_payment_mapping import FiscalPaymentMappingController
|
||||
from app.controllers.machine import MachineController
|
||||
from app.domain.machine import Machine
|
||||
|
||||
from . import machines
|
||||
|
||||
__all__ = ["create_router"]
|
||||
|
||||
|
||||
def create_router() -> Router:
|
||||
return Router(
|
||||
path="/v1",
|
||||
route_handlers=[machines.MachineController,],
|
||||
signature_namespace={"Machine": Machine,},
|
||||
route_handlers=[
|
||||
MachineController,
|
||||
FiscalPaymentMappingController,
|
||||
],
|
||||
signature_namespace={
|
||||
"Machine": Machine,
|
||||
"FiscalPaymentMappingController": FiscalPaymentMappingController,
|
||||
},
|
||||
)
|
||||
|
||||
69
app/controllers/fiscal_payment_mapping.py
Normal file
69
app/controllers/fiscal_payment_mapping.py
Normal file
@ -0,0 +1,69 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from litestar import Controller, get, post
|
||||
from litestar.contrib.repository.filters import SearchFilter
|
||||
from litestar.di import Provide
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.domain.fiscal_payment_mapping import (
|
||||
FiscalPaymentMapping,
|
||||
FiscalPaymentMappingReadDTO,
|
||||
FiscalPaymentMappingWriteDTO,
|
||||
Repository,
|
||||
Service,
|
||||
)
|
||||
from app.lib.filters import ExactFilter
|
||||
from app.lib.responses import ObjectListResponse, ObjectResponse
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
|
||||
DETAIL_ROUTE = "/{id:int}"
|
||||
|
||||
|
||||
def provides_service(db_session: AsyncSession) -> Service:
|
||||
"""Constructs repository and service objects for the request."""
|
||||
return Service(Repository(session=db_session))
|
||||
|
||||
|
||||
class FiscalPaymentMappingController(Controller):
|
||||
dto = FiscalPaymentMappingWriteDTO
|
||||
return_dto = FiscalPaymentMappingReadDTO
|
||||
path = "/fiscal-payment-mappings"
|
||||
dependencies = {
|
||||
"service": Provide(provides_service, sync_to_thread=False),
|
||||
}
|
||||
tags = ["FiscalPaymentMappings"]
|
||||
|
||||
@post()
|
||||
async def create_fiscal_payment_mappings(
|
||||
self, data: FiscalPaymentMapping, service: Service
|
||||
) -> FiscalPaymentMapping:
|
||||
return await service.create(data)
|
||||
|
||||
@get()
|
||||
async def get_fiscal_payment_mappings(
|
||||
self, service: Service, payment_device_code: Optional[int] = None
|
||||
) -> ObjectListResponse[FiscalPaymentMapping]:
|
||||
filters = []
|
||||
|
||||
if payment_device_code is not None:
|
||||
filters.append(
|
||||
ExactFilter[int](
|
||||
field_name="payment_device_code",
|
||||
value=payment_device_code,
|
||||
),
|
||||
)
|
||||
|
||||
content = await service.list(*filters)
|
||||
return ObjectListResponse(content=content)
|
||||
|
||||
@get(DETAIL_ROUTE)
|
||||
async def get_fiscal_payment_mapping(
|
||||
self, service: Service, id: int
|
||||
) -> ObjectResponse[FiscalPaymentMapping]:
|
||||
content = await service.get(id)
|
||||
return ObjectResponse(content=content)
|
||||
@ -70,7 +70,7 @@ class MachineController(Controller):
|
||||
LimitOffset(limit=20, offset=0),
|
||||
]
|
||||
|
||||
if search:
|
||||
if search is not None:
|
||||
filters.append(
|
||||
SearchFilter(
|
||||
field_name="caption",
|
||||
Reference in New Issue
Block a user