17 lines
469 B
Python
17 lines
469 B
Python
|
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
|