in isshub.domain.utils View Git history
repository¶
“repository” module
Package defining bases for domain repositories.
-
exception
RepositoryException
(message, repository=None)[source]¶ Bases:
Exception
Exception raised in a repository context.
- Variables
repository (Optional[Type[AbstractRepository]]) – An optional repository attached to the exception or the exception class.
-
repository
: Optional[Type[isshub.domain.utils.repository.AbstractRepository]] = None¶
-
exception
UniquenessError
(message, repository=None)[source]¶ Bases:
isshub.domain.utils.repository.RepositoryException
Exception raised when an entity is added/updated that already exists.
-
exception
NotFoundError
(message, repository=None)[source]¶ Bases:
isshub.domain.utils.repository.RepositoryException
Exception raised when an entity couldn’t be found in its repository.
-
class
AbstractRepository
(*args, **kwds)[source]¶ Bases:
abc.ABC
,typing.Generic
Base of all repositories.
- Variables
entity_class (Optional[Type[Entity]]) – The entity class the repository is designed for. Passed as a named argument while defining the class.
NotFoundError (Type["NotFoundError"]) – Local version of the
NotFoundError
exception, bound to the current repository.UniquenessError (Type["UniquenessError"]) – Local version of the
UniquenessError
exception, bound to the current repository.
-
entity_class
: Optional[Type[Entity]] = None¶
-
NotFoundError
: Type[isshub.domain.utils.repository.NotFoundError]¶
-
UniquenessError
: Type[isshub.domain.utils.repository.UniquenessError]¶
-
exists
(identifier)[source]¶ Tell if an entity with the given identifier exists in the repository.
- Parameters
identifier (UUID) – The UUID to check for in the repository
- Returns
True
if an entity with the given UUID exists.False
otherwise.- Return type
bool
-
abstract
add
(entity)[source]¶ Add the given entity in the repository.
- Parameters
entity (Entity) – The entity to add to the repository
- Returns
The added entity
- Return type
Entity
-
abstract
get
(identifier)[source]¶ Get an entity by its identifier.
- Parameters
identifier (UUID) – The identifier of the wanted entity
- Returns
The wanted entity
- Return type
Entity
- Raises
self.NotFoundError – If no entity was found with the given identifier
-
abstract
update
(entity)[source]¶ Update the given entity in the repository.
- Parameters
entity (Entity) – The entity to updated in the repository. It must already exist.
- Returns
The updated entity
- Return type
Entity
- Raises
self.NotFoundError – If no entity was found matching the given one
-
abstract
delete
(entity)[source]¶ Delete the given entity from the repository.
For the parameters, see
AbstractRepository.delete
.- Raises
self.NotFoundError – If no entity was found matching the given one
- Return type
None
-
class
AbstractInMemoryRepository
[source]¶ Bases:
isshub.domain.utils.repository.AbstractRepository
Repository to handle entities in memory.
Notes
The class is created with
abstract=True
because as all methods from theAbstractRepository
are defined, it is not viewed as abstract byinspect.isabstract
.-
exists
(identifier)[source]¶ Tell if an entity with the given identifier exists in the repository.
For the parameters, see
AbstractRepository.exists
.- Returns
True
if an entity with the given UUID exists.False
otherwise.- Return type
bool
-
add
(entity)[source]¶ Add the given entity in the repository.
For the parameters, see
AbstractRepository.add
.Notes
The entity will be validated before being saved.
- Returns
The added entity
- Return type
Entity
- Raises
self.UniquenessError – If an entity with the same identifier as the given one already exists.
-
get
(identifier)[source]¶ Get an entity by its identifier.
For the parameters, see
AbstractRepository.get
.- Returns
The wanted entity
- Return type
Entity
- Raises
self.NotFoundError – If no entity was found with the given identifier
-
update
(entity)[source]¶ Update the given entity in the repository.
For the parameters, see
AbstractRepository.update
.Notes
The entity will be validated before being saved.
- Returns
The updated entity
- Return type
Entity
- Raises
self.NotFoundError – If no entity was found matching the given one
-
exception
NotFoundError
(message, repository=None)¶ Bases:
isshub.domain.utils.repository.NotFoundError
-
repository
¶ alias of
AbstractInMemoryRepository
-
-
exception
UniquenessError
(message, repository=None)¶ Bases:
isshub.domain.utils.repository.UniquenessError
-
repository
¶ alias of
AbstractInMemoryRepository
-
-
delete
(entity)[source]¶ Delete the given entity from the repository.
For the parameters, see
AbstractRepository.delete
.- Raises
self.NotFoundError – If no entity was found matching the given one
- Return type
None
-