From b0f220089d15a4e319b39de8ffd25db34cd8b357 Mon Sep 17 00:00:00 2001 From: eld_master Date: Mon, 9 Dec 2024 14:08:53 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B0=9C=EC=9D=B8-=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/app/db/crud_room_score.py | 35 ++++++++++++++++++++ fastapi/app/process/room/room_score.py | 45 ++++++++++++++++++++++++++ fastapi/app/router/room_score_api.py | 13 ++++++-- 3 files changed, 91 insertions(+), 2 deletions(-) diff --git a/fastapi/app/db/crud_room_score.py b/fastapi/app/db/crud_room_score.py index 30d3160..b027ed8 100644 --- a/fastapi/app/db/crud_room_score.py +++ b/fastapi/app/db/crud_room_score.py @@ -144,6 +144,41 @@ async def participant_user_list(room_type, room_seq, db): return db.execute(query).fetchall() +# 요청자가 방장인지 확인 +async def check_requester_room_master_auth(room_seq, db): + query = text(f""" + select + user_seq + from room_main + where room_seq = {room_seq} + """) + return db.execute(query).fetchall() + + +# 요청자가 방장인지 확인 +async def update_room_status(room_seq, room_status, before_status, db): + query = text(f""" + update room_main + set room_status = (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_STATUS' and reserve_code = '{room_status}') + where room_seq = {room_seq} + and room_status = (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_STATUS' and reserve_code = '{before_status}') + """) + try: + db.execute(query) + db.commit() + return True + except Exception as e: + logger.error(f"sql error: {e}") + return False + + + + + + + + + diff --git a/fastapi/app/process/room/room_score.py b/fastapi/app/process/room/room_score.py index f8904fc..cfa7efc 100644 --- a/fastapi/app/process/room/room_score.py +++ b/fastapi/app/process/room/room_score.py @@ -111,6 +111,51 @@ async def participant_user_list(room_type, room_seq, db): } +# 요청자가 방장인지 확인 +async def check_requester_room_master_auth(user_seq, room_seq, db): + db_result_ori = await crud_room_score.check_requester_room_master_auth(room_seq=room_seq, db=db) + if len(db_result_ori) != 1: + return { + "result": "FAIL" + } + + room_master_user_seq = db_result_ori[0][0] + + # 조회된 방장 SEQ와 요청자 SEQ 비교 + if int(room_master_user_seq) == int(user_seq): + return { + "result": "OK" + } + else: + return { + "result": "FAIL" + } + + +# 요청자가 방장인지 확인 +async def update_room_status(room_seq, room_status, db): + room_status_follow_list = ['WAIT', 'RUNNING', 'FINISH'] + before_status_index = room_status_follow_list.index(room_status)-1 + if before_status_index < 0: + return { + "result": "FAIL", + } + before_status = room_status_follow_list[before_status_index] + db_result = await crud_room_score.update_room_status(room_seq=room_seq, room_status=room_status, before_status=before_status, db=db) + + if db_result: + return { + "result": "OK" + } + else: + return { + "result": "FAIL", + } + + + + + diff --git a/fastapi/app/router/room_score_api.py b/fastapi/app/router/room_score_api.py index fc5a22d..38b58b5 100644 --- a/fastapi/app/router/room_score_api.py +++ b/fastapi/app/router/room_score_api.py @@ -148,8 +148,17 @@ async def start_private_room(request: Request, body: bytes = Depends(get_body), user_seq_result = cert_process.get_user_seq_by_token(token=auth_token['token']) if user_seq_result["result"] == 'OK': user_seq = user_seq_result['data']['user_seq'] - body['user_seq'] = user_seq - # TODO + # 요청자가 방장인지 확인 + check_requester_room_master_auth_result = await room_score.check_requester_room_master_auth(user_seq=user_seq, room_seq=body['room_seq'], db=db) + if check_requester_room_master_auth_result['result'] == 'OK': + # 방 상태 RUNNING으로 변경 + update_room_status_result = await room_score.update_room_status(room_seq=body['room_seq'], room_status='RUNNING', db=db) + if update_room_status_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data={}, db=db) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='게임 시작처리 에러', msg_content='게임 시작처리중 에러가 발생했습니다. 관리자에게 문의해주세요.', data={}) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='게임 시작처리 에러', msg_content='방장에게만 게임시작 권한이 있습니다.', data={}) else: return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={})