a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
25 lines
737 B
Python
25 lines
737 B
Python
from typing import Optional
|
|
|
|
from app.users.models import User
|
|
|
|
|
|
class UserService:
|
|
"""Plain service class — registered as a FastAPI dependency via
|
|
class-based `Depends(UserService)`. Its methods are called from
|
|
route handlers that receive the instance through a parameter."""
|
|
|
|
def __init__(self) -> None:
|
|
self._users: dict[str, User] = {}
|
|
|
|
def find_one(self, user_id: str) -> Optional[User]:
|
|
return self._users.get(user_id)
|
|
|
|
def find_all(self) -> list[User]:
|
|
return list(self._users.values())
|
|
|
|
def create(self, email: str, name: str) -> User:
|
|
uid = f"usr_{len(self._users) + 1}"
|
|
u = User(id=uid, email=email, name=name)
|
|
self._users[uid] = u
|
|
return u
|