visus-plus/api/app/infrastructure/roles_service.py

25 lines
676 B
Python

from sqlalchemy.ext.asyncio import AsyncSession
from app.application.roles_repository import RolesRepository
from app.domain.entities.role import RoleEntity
from app.domain.models import Role
class RolesService:
def __init__(self, db: AsyncSession):
self.roles_repository = RolesRepository(db)
async def get_all_roles(self) -> list[RoleEntity]:
roles = await self.roles_repository.get_all()
return [
self.model_to_entity(role)
for role in roles
]
@staticmethod
def model_to_entity(role: Role) -> RoleEntity:
return RoleEntity(
id=role.id,
title=role.title,
)