Feat: add response error when tribe already exists
This commit is contained in:
@@ -2,11 +2,21 @@ from backend.model.tribe import Tribe
|
||||
from backend.repository.abstract_repository import AbstractRepository
|
||||
|
||||
|
||||
class TribeRepositoryError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class TribeSQLiteRepository(AbstractRepository):
|
||||
def __init__(self, conn) -> None:
|
||||
self.conn = conn
|
||||
|
||||
def add(self, tribe: Tribe) -> None:
|
||||
tribes = self.list()
|
||||
if tribe.name in map(lambda x: x.name, tribes):
|
||||
raise TribeRepositoryError(
|
||||
f"The tribe {tribe.name} already exists. Can't add it"
|
||||
)
|
||||
|
||||
self.conn.execute(
|
||||
"""
|
||||
INSERT INTO tribes(name, level) VALUES (?, ?)
|
||||
|
||||
Reference in New Issue
Block a user