Skip to content

Commit

Permalink
feat: qr function init
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-kyu committed Nov 21, 2024
1 parent aeb35f8 commit 59ef736
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
44 changes: 43 additions & 1 deletion app/api/bingo/bingo_boards/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, Depends, Path
from fastapi import APIRouter, Depends, Path, HTTPException

from .schema import (
BingoBoardRequest,
Expand Down Expand Up @@ -77,3 +77,45 @@ async def get_bingo_event_users(
bingo_boards: GetBingoEventUser = Depends(GetBingoEventUser),
):
return await bingo_boards.execute(bingo_count)

import random
@bingo_boards_router.patch("/update/{booth_id}")
async def update_bingo_status(
booth_id: str,
update_bingo_boards: UpdateBingoBoardByUserId = Depends(UpdateBingoBoardByUserId),
get_bingo_boards: GetBingoBoardByUserId = Depends(GetBingoBoardByUserId),
):
booth_exist = False
not_selected_ids = []
# TODO: get user_id
user_id = 6

# get board_data, check user_id is already have booth bingo
data = await get_bingo_boards.execute(user_id)
board_data = data.board_data
for idx, bingo_dict in board_data.items():
value, status = bingo_dict["value"], bingo_dict["status"]
if value == f'Booth {booth_id}':
booth_exist = True
break
if status == 0:
# get not selected list
not_selected_ids.append(idx)

if not booth_exist:
# update random board data
booth_idx = random.choice(not_selected_ids)
print('update idx', booth_idx)
board_data[booth_idx]["value"] = f'Booth {booth_id}'
board_data[booth_idx]["status"] = 1
print('update board_data', board_data)
new_data = BingoBoardRequest(
user_id=user_id,
board_data=board_data
)
print('update!')
return await update_bingo_boards.execute(**new_data.model_dump())
else:
# not update
print('not update!')
return
3 changes: 2 additions & 1 deletion app/api/bingo/bingo_boards/services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from core.db import AsyncSessionDepends
from models.bingo import BingoBoards
from api.bingo.bingo_boards.schema import BingoBoardResponse, UpdateBingoCountResponse, UserSelectedWordsResponse, UpdateBingoStatusResponse, GetUserBingoEventUser
from api.bingo.bingo_boards.schema import BingoBoardRequest, BingoBoardResponse, UpdateBingoCountResponse, UserSelectedWordsResponse, UpdateBingoStatusResponse, GetUserBingoEventUser


class BaseBingoBoard:
Expand All @@ -11,6 +11,7 @@ def __init__(self, session: AsyncSessionDepends):
class CreateBingoBoard(BaseBingoBoard):
async def execute(self, user_id: int, board_data: dict) -> BingoBoards:
try:
board_data = BingoBoardRequest.Config.json_schema_extra["example"]["board_data"]
res = await BingoBoards.create(self.async_session, user_id, board_data)
return BingoBoardResponse(**res.__dict__, ok=True, message="빙고판 생성에 성공하였습니다.")
except ValueError as e:
Expand Down

0 comments on commit 59ef736

Please sign in to comment.