From 163a99d5d424b49b2d7989e9c4b654ad188e1db0 Mon Sep 17 00:00:00 2001 From: cdw8431 Date: Sat, 22 Jul 2023 18:43:13 +0900 Subject: [PATCH] =?UTF-8?q?feat(unsubscriber):=20=EA=B5=AC=EB=8F=85=20?= =?UTF-8?q?=ED=95=B4=EC=A7=80=20=EC=9C=A0=EC=A0=80=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/domain/unsubscriber/repository.py | 13 ++++++++++++- app/domain/unsubscriber/schemas.py | 4 ++++ app/router/unsubscriber.py | 11 ++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/domain/unsubscriber/repository.py b/app/domain/unsubscriber/repository.py index 5a44096..1ccd909 100644 --- a/app/domain/unsubscriber/repository.py +++ b/app/domain/unsubscriber/repository.py @@ -4,14 +4,25 @@ class UnsubscriberRepository(abc.ABC): + _UNSUBSCRIBERS_KEY = "unsubscribers" + @abc.abstractmethod async def get_unsubscribers(self) -> set[str]: raise NotImplementedError + @abc.abstractmethod + async def delete_all_unsubscribers(self) -> int: + raise NotImplementedError + class UnsubscriberRedisRepository(UnsubscriberRepository): def __init__(self, session: Redis): self._session = session async def get_unsubscribers(self) -> set[str]: - return await self._session.smembers("unsubscribers") + return await self._session.smembers(self._UNSUBSCRIBERS_KEY) + + async def delete_all_unsubscribers(self) -> int: + deleted_count = await self._session.scard(self._UNSUBSCRIBERS_KEY) + await self._session.delete(self._UNSUBSCRIBERS_KEY) + return deleted_count diff --git a/app/domain/unsubscriber/schemas.py b/app/domain/unsubscriber/schemas.py index c7e9b56..711d102 100644 --- a/app/domain/unsubscriber/schemas.py +++ b/app/domain/unsubscriber/schemas.py @@ -3,3 +3,7 @@ class UnsubscribersResponse(BaseResponse): unsubscribers: list[str] + + +class DeleteAllUnsubscribersResponse(BaseResponse): + deleted_count: int diff --git a/app/router/unsubscriber.py b/app/router/unsubscriber.py index 369cd14..6985fc4 100644 --- a/app/router/unsubscriber.py +++ b/app/router/unsubscriber.py @@ -3,7 +3,7 @@ from app.common.di import AppContainer from app.domain.unsubscriber.repository import UnsubscriberRepository -from app.domain.unsubscriber.schemas import UnsubscribersResponse +from app.domain.unsubscriber.schemas import DeleteAllUnsubscribersResponse, UnsubscribersResponse router = APIRouter(prefix="/unsubscribers", tags=["unsubscriber"]) @@ -17,3 +17,12 @@ async def unsubscribers( ) -> UnsubscribersResponse: unsubscribers = await unsub_repo.get_unsubscribers() return UnsubscribersResponse(unsubscribers=unsubscribers) + + +@router.delete("", description="구독 해지 유저 전체 삭제 API") +@inject +async def delete_all_unsubscribers( + unsub_repo: UnsubscriberRepository = Depends(provide_unsub_repository), +) -> DeleteAllUnsubscribersResponse: + deleted_count = await unsub_repo.delete_all_unsubscribers() + return DeleteAllUnsubscribersResponse(deleted_count=deleted_count)