._.
This commit is contained in:
parent
d573369114
commit
0100d371c5
@ -9,6 +9,7 @@ class UserEntity(BaseModel):
|
||||
login: str
|
||||
password: str
|
||||
role_id: Optional[int] = None
|
||||
role_name: Optional[str] = None
|
||||
total_orders: List[int] = []
|
||||
|
||||
class Config:
|
||||
|
||||
@ -10,7 +10,7 @@ class UsersService:
|
||||
self.repository = UsersRepository(db)
|
||||
|
||||
def get_all_users(self) -> List[UserEntity]:
|
||||
users = self.repository.get_all()
|
||||
users = self.repository.get_all_with_role()
|
||||
return [
|
||||
UserEntity(
|
||||
id=user.id,
|
||||
@ -19,7 +19,8 @@ class UsersService:
|
||||
login=user.login,
|
||||
password=user.password,
|
||||
role_id=user.role_id,
|
||||
total_orders=[to.id for to in user.total_orders] if user.total_orders else []
|
||||
total_orders=[to.id for to in user.total_orders] if user.total_orders else [],
|
||||
role_name=user.role.name,
|
||||
)
|
||||
for user in users
|
||||
]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
from app.infrastructure.database.models.users import User
|
||||
|
||||
|
||||
@ -9,6 +9,11 @@ class UsersRepository:
|
||||
def get_all(self):
|
||||
return self.db.query(User).all()
|
||||
|
||||
def get_all_with_role(self):
|
||||
return self.db.query(User) \
|
||||
.options(joinedload(User.role)) \
|
||||
.all()
|
||||
|
||||
def get_by_id(self, user_id: int):
|
||||
return self.db.query(User).filter(User.id == user_id).first()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user