recopytex/backend/service/services.py

17 lines
469 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(tribe: Tribe, tribe_repo: AbstractRepository, conn):
try:
tribe_repo.add(tribe)
except TribeRepositoryError:
raise TribeExists(f"The tribe {tribe.name} already exists")
conn.commit()
return tribe