-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from src.domain.entity.calendar import Calendar | ||
from src.domain.repo.i_repo import IRepo | ||
|
||
|
||
class ICalendarRepo(IRepo[Calendar]): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import abc | ||
import uuid | ||
from typing import Generic, TypeVar | ||
|
||
Entity = TypeVar("Entity") | ||
|
||
|
||
class IRepo(abc.ABC, Generic[Entity]): | ||
@abc.abstractmethod | ||
def get(self, id: uuid.UUID) -> Entity | None: | ||
... | ||
|
||
@abc.abstractmethod | ||
def save(self, entity: Entity) -> None: | ||
... | ||
|
||
def get_or_error(self, id: uuid.UUID) -> Entity: | ||
entity = self.get(id) | ||
if entity is None: | ||
raise RepositoryNotFoundError(f"{str(id)}") | ||
|
||
return entity | ||
|
||
def is_exist(self, id: uuid.UUID) -> bool: | ||
return self.get(id) is not None | ||
|
||
|
||
class RepositoryError(Exception): | ||
pass | ||
|
||
|
||
class RepositoryNotFoundError(RepositoryError): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import uuid | ||
|
||
from src.domain.entity.calendar import Calendar | ||
from src.domain.repo.i_calendar_repo import ICalendarRepo | ||
from src.infra.repo.sa import SA | ||
|
||
|
||
class SACalendarRepo(ICalendarRepo): | ||
def __init__(self, sa: SA) -> None: | ||
self.sa = sa | ||
|
||
def get(self, id: uuid.UUID) -> Calendar | None: | ||
return self.sa.session.get(Calendar, id) | ||
|
||
def save(self, entity: Calendar) -> None: | ||
self.sa.session.add(entity) |