diff --git a/app/api/bingo/bingo_boards/routes.py b/app/api/bingo/bingo_boards/routes.py index 6ffc68e..8fdaae1 100644 --- a/app/api/bingo/bingo_boards/routes.py +++ b/app/api/bingo/bingo_boards/routes.py @@ -6,6 +6,7 @@ UpdateBingoCountResponse, UserSelectedWordsResponse, UpdateBingoStatusResponse, + UpdateBingoStatusResponseByQRScan, GetUserBingoEventUser, ) from .services import ( @@ -80,10 +81,10 @@ async def get_bingo_event_users( return await bingo_boards.execute(bingo_count) -@bingo_boards_router.patch("/update/{user_id}/{booth_id}") +@bingo_boards_router.patch("/update/{user_id}/{booth_id}", response_model=UpdateBingoStatusResponseByQRScan) async def update_bingo_status_booth( - user_id: str, - booth_id: str, + user_id: int = Path(..., title="요청 유저 ID", ge=0), + booth_id: int = Path(..., title="요청 부스 ID", ge=0), bingo_boards: UpdateBingoStatusByQRScan = Depends(UpdateBingoStatusByQRScan), ): return await bingo_boards.execute(user_id, booth_id) diff --git a/app/api/bingo/bingo_boards/schema.py b/app/api/bingo/bingo_boards/schema.py index 524e0a7..3db188c 100644 --- a/app/api/bingo/bingo_boards/schema.py +++ b/app/api/bingo/bingo_boards/schema.py @@ -61,12 +61,18 @@ class UpdateBingoCountResponse(BaseSchema): class UserSelectedWordsResponse(BaseSchema): selected_words: Optional[list[str]] = Field(title="선택한 단어들", default=None) + class UpdateBingoStatusResponse(BaseSchema): send_user_id: Optional[int] = Field(title="요청 유저 ID", default=None) receive_user_id: Optional[int] = Field(title="대상 유저 ID", default=None) updated_words: Optional[list[str]] = Field(title="업데이트된 단어들", default=None) bingo_count: Optional[int] = Field(title="업데이트된 빙고 갯수", default=None) + +class UpdateBingoStatusResponseByQRScan(UpdateBingoCountResponse): + booth_id: Optional[int] = Field(title="요청 부스 ID", default=None) + updated_words: Optional[list[str]] = Field(title="업데이트된 단어들", default=None) + + class GetUserBingoEventUser(BaseSchema): bingo_event_users: Optional[list[BingoEventUserInfo]] = Field(title="빙고 이벤트 당첨 유저 목록", default=None) - diff --git a/app/api/bingo/bingo_boards/services.py b/app/api/bingo/bingo_boards/services.py index 0c9212e..c8171e7 100644 --- a/app/api/bingo/bingo_boards/services.py +++ b/app/api/bingo/bingo_boards/services.py @@ -1,6 +1,6 @@ from core.db import AsyncSessionDepends from models.bingo import BingoBoards -from api.bingo.bingo_boards.schema import BingoBoardRequest, BingoBoardResponse, UpdateBingoCountResponse, UserSelectedWordsResponse, UpdateBingoStatusResponse, GetUserBingoEventUser +from api.bingo.bingo_boards.schema import BingoBoardRequest, BingoBoardResponse, UpdateBingoCountResponse, UserSelectedWordsResponse, UpdateBingoStatusResponse, GetUserBingoEventUser, UpdateBingoStatusResponseByQRScan class BaseBingoBoard: @@ -70,9 +70,9 @@ async def execute(self, bingo_count: int) -> list[str]: return GetUserBingoEventUser(ok=False, message=str(e)) class UpdateBingoStatusByQRScan(BaseBingoBoard): - async def execute(self, iser_id: int, booth_id: int) -> BingoBoards: + async def execute(self, user_id: int, booth_id: int) -> BingoBoards: try: - res = await BingoBoards.update_bingo_status_by_qr_scan(self.async_session, iser_id, booth_id) - return UpdateBingoStatusResponse(**res.__dict__, ok=True, message="빙고판 상태 업데이트에 성공하였습니다.") + res = await BingoBoards.update_bingo_status_by_qr_scan(self.async_session, user_id, booth_id) + return UpdateBingoStatusResponseByQRScan(**res.__dict__, ok=True, message="빙고판 상태 업데이트에 성공하였습니다.") except ValueError as e: - return UpdateBingoStatusResponse(ok=False, message=str(e)) + return UpdateBingoStatusResponseByQRScan(ok=False, message=str(e)) diff --git a/app/models/bingo/bingo_boards.py b/app/models/bingo/bingo_boards.py index a5da127..c3e55db 100644 --- a/app/models/bingo/bingo_boards.py +++ b/app/models/bingo/bingo_boards.py @@ -9,7 +9,7 @@ from core.db import AsyncSession from models.base import Base -from models.bingo.schema import BingoInteractionSchema, BingoEventUserInfo +from models.bingo.schema import BingoInteractionSchema, BingoEventUserInfo, BingoQRScanSchema from models.user import BingoUser @@ -144,9 +144,10 @@ async def update_bingo_status_by_qr_scan(cls, session: AsyncSession, user_id: in # get board_data, check user_id is already have booth bingo board = await cls.get_board_by_userid(session, user_id) board_data = board.board_data + updated_booth_name = f'Booth {booth_id}' for idx, bingo_dict in board_data.items(): value, status = bingo_dict["value"], bingo_dict["status"] - if value == f'Booth {booth_id}': + if value == updated_booth_name: booth_exist = True break if status == 0: @@ -156,6 +157,14 @@ async def update_bingo_status_by_qr_scan(cls, session: AsyncSession, user_id: in if not booth_exist: # update random board data booth_idx = random.choice(not_selected_ids) - board_data[booth_idx]["value"] = f'Booth {booth_id}' + board_data[booth_idx]["value"] = updated_booth_name board_data[booth_idx]["status"] = 1 await cls.update_board_by_userid(session, user_id, board_data) + + + return BingoQRScanSchema( + user_id=user_id, + booth_id=booth_id, + updated_words=[updated_booth_name], + bingo_count=board.bingo_count, + ) \ No newline at end of file diff --git a/app/models/bingo/schema.py b/app/models/bingo/schema.py index 2dd87bf..f2acfd1 100644 --- a/app/models/bingo/schema.py +++ b/app/models/bingo/schema.py @@ -19,13 +19,22 @@ class BingoBoardSchema(BaseModel): model_config = ConfigDict(from_attributes=True) + class BingoInteractionSchema(BaseModel): send_user_id: int receive_user_id: int updated_words: list[str] bingo_count: int + +class BingoQRScanSchema(BaseModel): + user_id: int + booth_id: int + updated_words: list[str] + bingo_count: int + + class BingoEventUserInfo(BaseModel): rank: int user_name: str - bingo_count: int \ No newline at end of file + bingo_count: int