mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-12-04 23:44:05 +03:00
d45d98e300
* Add application * Dockerize the app * Fix 204 content-leength error * Rename database file * Add tests * Add README * Fix a typo in FastAPI example * Add docs on FastAPI + SQLAlchemy example * Update changelog * Add link to the example to README and other docs pages * Add EOF to the config.yml
27 lines
724 B
Python
27 lines
724 B
Python
"""Services module."""
|
|
|
|
from uuid import uuid4
|
|
from typing import Iterator
|
|
|
|
from .repositories import UserRepository
|
|
from .models import User
|
|
|
|
|
|
class UserService:
|
|
|
|
def __init__(self, user_repository: UserRepository) -> None:
|
|
self._repository: UserRepository = user_repository
|
|
|
|
def get_users(self) -> Iterator[User]:
|
|
return self._repository.get_all()
|
|
|
|
def get_user_by_id(self, user_id: int) -> User:
|
|
return self._repository.get_by_id(user_id)
|
|
|
|
def create_user(self) -> User:
|
|
uid = uuid4()
|
|
return self._repository.add(email=f'{uid}@email.com', password='pwd')
|
|
|
|
def delete_user_by_id(self, user_id: int) -> None:
|
|
return self._repository.delete_by_id(user_id)
|