recopytex/backend/service/services.py

18 lines
520 B
Python
Raw Normal View History

2022-12-30 06:19:48 +00:00
from backend.model.tribe import Tribe
from backend.repository.abstract_repository import AbstractRepository
from backend.repository.tribe_sqlite_repository import TribeRepositoryError
class TribeExists(Exception):
pass
def add_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn):
tribe = Tribe(name=name, level=level)
2022-12-30 06:19:48 +00:00
try:
tribe_repo.add(tribe)
except TribeRepositoryError:
raise TribeExists(f"The tribe {tribe.name} already exists")
conn.commit()
return tribe