Skip to content

Commit

Permalink
캘린더 레파지토리 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
qodot committed Sep 17, 2023
1 parent b4d4cf7 commit 05fc91e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/domain/repo/i_calendar_repo.py
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]):
...
35 changes: 35 additions & 0 deletions src/domain/repo/i_repo.py
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
16 changes: 16 additions & 0 deletions src/infra/repo/sa_calendar_repo.py
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)

0 comments on commit 05fc91e

Please sign in to comment.