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 class TribeDosNotExists(Exception): pass def add_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn) -> Tribe: tribe = Tribe(name=name, level=level) try: tribe_repo.add(tribe) except TribeRepositoryError: raise TribeExists(f"The tribe {tribe.name} already exists") conn.commit() return tribe def update_tribe(name: str, level: str, tribe_repo: AbstractRepository, conn) -> Tribe: tribe = Tribe(name=name, level=level) try: tribe_repo.update(name=name, tribe=tribe) except TribeRepositoryError: raise TribeDosNotExists(f"The tribe {name} does not exists you can't update it") conn.commit() return tribe def delete_tribe(name: str, tribe_repo: AbstractRepository, conn) -> None: try: tribe_repo.delete(name=name) except TribeRepositoryError: raise TribeDosNotExists(f"The tribe {name} does not exists you can't delete it") conn.commit()