Skip to content

Commit

Permalink
Merge pull request #7 from wakscord/feature/delete-all-unsubscribers
Browse files Browse the repository at this point in the history
구독 해지 유저 전체 삭제 API 추가
  • Loading branch information
cdw8431 authored Jul 23, 2023
2 parents 9cebafd + 163a99d commit 2b70eff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/domain/unsubscriber/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/domain/unsubscriber/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@

class UnsubscribersResponse(BaseResponse):
unsubscribers: list[str]


class DeleteAllUnsubscribersResponse(BaseResponse):
deleted_count: int
11 changes: 10 additions & 1 deletion app/router/unsubscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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)

0 comments on commit 2b70eff

Please sign in to comment.