Skip to content

Commit

Permalink
feat: change to update user name in interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-kyu committed Nov 22, 2024
1 parent 3f0099b commit 73af6c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 39 deletions.
30 changes: 4 additions & 26 deletions app/api/bingo/bingo_boards/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,11 @@ class Config:
json_schema_extra = {
"example": {
"user_id": 1,
# 동명이인(user)이 있을 수 있으므로 value 외에 user_id도 저장
"board_data": {
"0": {"value": "AI 스타트업 재직자", "selected": 1, "status": 1},
"1": {"value": "AI 아티스트", "selected": 1, "status": 0},
"2": {"value": "AI 뉴스레터 구독자", "selected": 1, "status": 0},
"3": {"value": "AI 유튜브 채널 구독자", "selected": 0, "status": 0},
"4": {"value": "프론트엔드, 백엔드 엔지니어", "selected": 0, "status": 1},
"5": {"value": "오픈소스 기여자", "selected": 0, "status": 0},
"6": {"value": "SNS 사용자", "selected": 0, "status": 0},
"7": {"value": "직전 경력 특이한", "selected": 0, "status": 1},
"8": {"value": "AI 모델 배포 경험자", "selected": 0, "status": 0},
"9": {"value": "기술 블로그 운영자", "selected": 0, "status": 0},
"10": {"value": "해외 컨퍼런스 참가경험", "selected": 0, "status": 0},
"11": {"value": "귀여운 IT 굿즈 받아본자", "selected": 0, "status": 0},
"12": {"value": "Welcome to PseudoCon", "selected": 0, "status": 0},
"13": {"value": "부트캠프 참가경험", "selected": 0, "status": 0},
"14": {"value": "AI 관련 해커톤 경험자", "selected": 0, "status": 0},
"15": {"value": "올해를 알차게 보낸자", "selected": 0, "status": 0},
"16": {"value": "AI 윤리/정책 연구자", "selected": 0, "status": 0},
"17": {"value": "로봇/드론 관련 연구자", "selected": 0, "status": 0},
"18": {"value": "내 MBTI 설명 가능한자", "selected": 0, "status": 0},
"19": {"value": "VR/AR 헤드셋 보유자", "selected": 0, "status": 0},
"20": {"value": "Kaggle 또는 Dacon 우승자", "selected": 0, "status": 0},
"21": {"value": "멀티모달 관련 연구자", "selected": 0, "status": 0},
"22": {"value": "특별한 경험을 가진자", "selected": 0, "status": 0},
"23": {"value": "DevOps, MLOps, SRE", "selected": 0, "status": 0},
"24": {"value": "이전 기수 참가자", "selected": 0, "status": 0},
},
str(i): {"value": "", "selected": 0, "status": 0, "user_id": None}
for i in range(25)
}
}
}

Expand Down
1 change: 0 additions & 1 deletion app/api/bingo/bingo_boards/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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
33 changes: 21 additions & 12 deletions app/models/bingo/bingo_boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,35 @@ async def update_bingo_status_by_selected_user(
cls, session: AsyncSession, send_user_id: int, receive_user_id: int
) -> BingoInteractionSchema:
board = await cls.get_board_by_userid(session, receive_user_id)
selected_words = await cls.get_user_selected_words(session, send_user_id)
# selected_words = await cls.get_user_selected_words(session, send_user_id)
board_data = board.board_data
update_words = []
already_interaction = False

for board_item in board_data.values():
if board_item["value"] in selected_words:
board_item["status"] = 1
update_words.append(board_item["value"])
selected_words.remove(board_item["value"])

if not selected_words:
not_selected_ids = []
for idx, bingo_dict in board_data.items():
status, user_id = bingo_dict["status"], bingo_dict["user_id"]
if user_id == send_user_id: # 이미 interaction 한 유저인 경우는 Pass
already_interaction = True
break
if status == 0:
# get not selected list
not_selected_ids.append(idx)

await cls.update_board_by_userid(session, receive_user_id, board_data)
board = await cls.update_bingo_count(session, receive_user_id)
user = None
if not already_interaction:
user = await session.get(cls, send_user_id)
# update random board data
update_idx = random.choice(not_selected_ids)
board_data[update_idx]["value"] = user
board_data[update_idx]["status"] = 1
board_data[update_idx]["user_id"] = send_user_id
await cls.update_board_by_userid(session, receive_user_id, board_data)
board = await cls.update_bingo_count(session, receive_user_id)

return BingoInteractionSchema(
send_user_id=send_user_id,
receive_user_id=receive_user_id,
updated_words=update_words,
updated_words=[user],
bingo_count=board.bingo_count,
)

Expand Down

0 comments on commit 73af6c8

Please sign in to comment.