Skip to content

Commit 718d652

Browse files
authored
Create atleta_service.py
1 parent bb9db3f commit 718d652

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

app/services/atleta_service.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from sqlalchemy.exc import IntegrityError
2+
from app.repositories.atleta_repo import AtletaRepository
3+
from app.models.atleta import Atleta
4+
from app.schemas.atleta import AtletaCreate
5+
6+
class AtletaService:
7+
def __init__(self, repo: AtletaRepository):
8+
self.repo = repo
9+
10+
async def list(self, nome: str | None = None, cpf: str | None = None, limit: int = 10, offset: int = 0):
11+
return await self.repo.list(nome=nome, cpf=cpf, limit=limit, offset=offset)
12+
13+
async def count(self, nome: str | None = None, cpf: str | None = None):
14+
return await self.repo.count(nome=nome, cpf=cpf)
15+
16+
async def create(self, payload: AtletaCreate):
17+
atleta = Atleta(nome=payload.nome, cpf=payload.cpf, categoria_id=payload.categoria_id, centro_id=payload.centro_id)
18+
try:
19+
return await self.repo.create(atleta)
20+
except IntegrityError as ex:
21+
# relança e será tratado pelo handler global
22+
raise ex

0 commit comments

Comments
 (0)