From 9eabb5774c5943af6f2e19acce59379b0a8d4934 Mon Sep 17 00:00:00 2001 From: eld_master Date: Thu, 12 Dec 2024 00:04:29 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B1=EC=97=94=EB=93=9C=201=EC=B0=A8=20?= =?UTF-8?q?=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 | 453 ++++++++++++++++-- .../app/process/certification/cert_process.py | 2 +- fastapi/app/process/room/room_score.py | 241 +++++++++- .../app/process/room/room_score_pattern.py | 30 +- fastapi/app/router/room_score_api.py | 330 ++++++++++++- 5 files changed, 1006 insertions(+), 50 deletions(-) diff --git a/fastapi/app/db/crud_room_score.py b/fastapi/app/db/crud_room_score.py index b027ed8..92050b5 100644 --- a/fastapi/app/db/crud_room_score.py +++ b/fastapi/app/db/crud_room_score.py @@ -12,7 +12,7 @@ from db.base import get_db # 방 생성 def create_room(data, db): query = text(f""" - insert into room_main(room_type_seq, user_seq, room_title, room_intro, open_yn, room_pw, room_status, create_dt, update_dt, delete_yn) + insert into room_main(room_type_seq, user_seq, room_title, room_intro, open_yn, room_pw, running_time, number_of_people, room_status, create_dt, update_dt, delete_yn) values( (select room_type_seq from room_type where room_type_name = '{str(data['room_type']).upper()}'), {data['user_seq']}, @@ -20,6 +20,8 @@ def create_room(data, db): '{data['room_intro']}', '{data['open_yn']}', '{data['room_pw']}', + {data['running_time']}, + {data['number_of_people']}, (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_STATUS' and reserve_code = '{data['room_status']}'), now(), now(), @@ -75,13 +77,41 @@ async def select_room_seq_by_data(data, db): # 점수 공개 범위 설정 데이터 입력 async def insert_score_open_range(data, db): + if data['room_type'] == 'private': + query = text(f""" + insert into room_score_private(room_seq, score_open_range) + values( + {data['room_seq']}, + (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_{str(data['room_type']).upper()}' and reserve_code = '{data['score_open_range']}') + ) + """) + elif data['room_type'] == 'team': + query = text(f""" + insert into room_score_team(room_seq, number_of_teams, score_open_range) + values( + {data['room_seq']}, + {data['number_of_teams']}, + (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_{str(data['room_type']).upper()}' and reserve_code = '{data['score_open_range']}') + ) + """) + else: + return False + try: + db.execute(query) + db.commit() + return True + except Exception as e: + logger.error(f"sql error: {e}") + return False + + +# 점수 공개 범위 설정 데이터 입력 +async def insert_team_name(data, db): + values_str = ','.join([f"({data['room_seq']}, '{chr(65 + x)}')" for x in range(int(data['number_of_teams']))]) query = text(f""" - insert into room_score_{data['room_type']}(room_seq, number_of_people, score_open_range) - values( - {data['room_seq']}, - {data['number_of_people']}, - (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_{str(data['room_type']).upper()}' and reserve_code = '{data['score_open_range']}') - ) + insert into room_score_team_name(room_seq, team_name) + values + {values_str} """) try: db.execute(query) @@ -94,16 +124,29 @@ async def insert_score_open_range(data, db): # 방장 참여자 입력 async def insert_creater_user(data, db): - query = text(f""" - insert into room_score_{data['room_type']}_participant(room_seq, participant_type, user_seq, nickname, score) - values( - {data['room_seq']}, - (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TYPE' and reserve_code = 'ADMIN'), - {data['user_seq']}, - (select nickname from manage_user where user_seq = {data['user_seq']}), - 0 - ) - """) + if data['room_type'] == 'private': + query = text(f""" + insert into room_score_private_participant(room_seq, participant_type, user_seq, nickname, score) + values( + {data['room_seq']}, + (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TYPE' and reserve_code = 'ADMIN'), + {data['user_seq']}, + (select nickname from manage_user where user_seq = {data['user_seq']}), + 0 + ) + """) + elif data['room_type'] == 'team': + query = text(f""" + insert into room_score_team_participant(room_seq, participant_type, user_seq, nickname, team_name, score) + values( + {data['room_seq']}, + (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TYPE' and reserve_code = 'ADMIN'), + {data['user_seq']}, + (select nickname from manage_user where user_seq = {data['user_seq']}), + (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TEAM_NAME' and reserve_code = 'ADMIN'), + 0 + ) + """) try: db.execute(query) db.commit() @@ -127,20 +170,39 @@ async def check_auth_user(user_seq, room_type, room_seq, db): # 참가자 정보 가져오기 async def participant_user_list(room_type, room_seq, db): - query = text(f""" - select - a.user_seq, - a.participant_type, - a.nickname, {'a.team_name,' if room_type == 'team' else ''} - a.score, - b.profile_img, - b.department, - b.introduce_myself - from room_score_{room_type}_participant a - left join manage_user b - on a.user_seq = b.user_seq - where a.room_seq = {room_seq} - """) + if room_type == 'private' or room_type == 'PRIVATE': + query = text(f""" + select + a.user_seq, + a.participant_type, + a.nickname, + a.score, + b.profile_img, + b.department, + b.introduce_myself + from room_score_private_participant a + left join manage_user b + on a.user_seq = b.user_seq + where a.room_seq = {room_seq} + """) + elif room_type == 'team' or room_type == 'TEAM': + query = text(f""" + select + a.user_seq, + a.participant_type, + a.nickname, + a.team_name, + a.score, + b.profile_img, + b.department, + b.introduce_myself + from room_score_team_participant a + left join manage_user b + on a.user_seq = b.user_seq + where a.room_seq = {room_seq} + """) + else: + return [[]] return db.execute(query).fetchall() @@ -155,6 +217,18 @@ async def check_requester_room_master_auth(room_seq, db): return db.execute(query).fetchall() +# 팀전일 경우 team_name이 WAIT상태가 없는지 확인 +async def check_granted_team_name(room_seq, db): + query = text(f""" + select + count(team_name) + from room_score_team_participant + where room_seq = {room_seq} + and team_name = (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TEAM_NAME' and reserve_code = 'WAIT') + """) + return db.execute(query).fetchall() + + # 요청자가 방장인지 확인 async def update_room_status(room_seq, room_status, before_status, db): query = text(f""" @@ -172,10 +246,327 @@ async def update_room_status(room_seq, room_status, before_status, db): return False +# 방 설정정보 가져오기 +async def select_room_setting_info(room_seq, room_type, db): + if room_type == 'private' or room_type == 'PRIVATE': + query = text(f""" + select + a.user_seq, + a.room_title, + a.room_intro, + a.open_yn, + a.running_time, + b.room_type_name, + 0, + a.number_of_people, + c.score_open_range + from room_main a + left join room_type b + on a.room_type_seq = b.room_type_seq + left join room_score_private c + on a.room_seq = c.room_seq + where a.room_seq = {room_seq} + """) + elif room_type == 'team' or room_type == 'TEAM': + query = text(f""" + select + a.user_seq, + a.room_title, + a.room_intro, + a.open_yn, + a.running_time, + b.room_type_name, + c.number_of_teams, + a.number_of_people, + c.score_open_range + from room_main a + left join room_type b + on a.room_type_seq = b.room_type_seq + left join room_score_team c + on a.room_seq = c.room_seq + where a.room_seq = {room_seq} + """) + else: + return [[]] + + return db.execute(query).fetchall() +# 방 설정정보 수정하기 +async def update_room_setting_info_room_main(data, db): + query = text(f""" + update room_main + set room_title = '{data['room_title']}', + room_intro = '{data['room_intro']}', + open_yn = '{data['open_yn']}', + room_pw = '{data['room_pw']}', + running_time = '{data['running_time']}' + where room_seq = {data['room_seq']} + """) + try: + db.execute(query) + db.commit() + return True + except Exception as e: + logger.error(f"sql error: {e}") + return False +# 방 설정정보 수정하기-개인 +async def update_room_setting_info_room_score_private(data, db): + query = text(f""" + update room_score_private + set score_open_range = (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_{str(data['room_type']).upper()}' and reserve_code = '{data['score_open_range']}') + where room_seq = {data['room_seq']} + """) + try: + db.execute(query) + db.commit() + return True + except Exception as e: + logger.error(f"sql error: {e}") + return False + + +# 방 설정정보 수정하기-팀 +async def update_room_setting_info_room_score_team(data, db): + query = text(f""" + update room_score_team + set score_open_range = (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_{str(data['room_type']).upper()}' and reserve_code = '{data['score_open_range']}') + where room_seq = {data['room_seq']} + """) + try: + db.execute(query) + db.commit() + return True + except Exception as e: + logger.error(f"sql error: {e}") + return False + + +# 방 사회자 권한 확인 +async def check_admin_auth_user(user_seq, room_type, room_seq, db): + query = text(f""" + select + user_seq + from room_score_{room_type}_participant + where room_seq = {room_seq} + and user_seq = {user_seq} + and participant_type = 'ADMIN' + """) + return db.execute(query).fetchall() + + +# 참가자 역할&팀 수정하기 +async def update_participant_role_team(data, db): + if data['room_type'] == 'private': + query = text(f""" + update room_score_private_participant + set participant_type = (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TYPE' and reserve_code = '{data['participant_type']}') + where room_seq = {data['room_seq']} + and user_seq = {data['target_user_seq']} + """) + elif data['room_type'] == 'team': + query = text(f""" + update room_score_team_participant + set participant_type = (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TYPE' and reserve_code = '{data['participant_type']}'), + team_name = (select team_name from room_score_team_name where room_seq = {data['room_seq']} and team_name = '{data['team_name']}') + where room_seq = {data['room_seq']} + and user_seq = {data['target_user_seq']} + """) + else: + return False + try: + db.execute(query) + db.commit() + return True + except Exception as e: + logger.error(f"sql error: {e}") + return False + + +# 방 리스트 가져오기-방번호, 방타입명 +async def select_room_seq_list(search_type, search_value, db): + query = text(f""" + select + a.room_seq, + b.room_type_name + from room_main a + left join room_type b + on a.room_type_seq = b.room_type_seq + where a.room_status = (select reserve_code from reserve_code where reserve_code_group = 'ROOM_SCORE_STATUS' and reserve_code = '{str(search_type).upper()}') + and a.delete_yn = 'N' + """) + return db.execute(query).fetchall() + + +# 방 리스트 가져오기-개인전 +async def select_room_list_private(room_seq_list_private, db): + if room_seq_list_private == '()': + return [] + query = text(f""" + select + a.room_seq, + c.nickname, + a.room_status, + a.open_yn, + b.room_type_name, + a.number_of_people, + a.start_dt, + count(d.user_seq) as now_number_of_people, + a.room_intro + from room_main a + left join room_type b + on a.room_type_seq = b.room_type_seq + left join manage_user c + on a.user_seq = c.user_seq + left join room_score_private_participant d + on a.room_seq = d.room_seq + where a.room_seq in {room_seq_list_private} + group by a.room_seq, c.nickname, a.room_status, a.open_yn, b.room_type_name, a.number_of_people, a.start_dt, a.room_intro + """) + return db.execute(query).fetchall() + + +# 방 리스트 가져오기-팀전 +async def select_room_list_team(room_seq_list_team, db): + if room_seq_list_team == '()': + return [] + query = text(f""" + select + a.room_seq, + c.nickname, + a.room_status, + a.open_yn, + b.room_type_name, + a.number_of_people, + a.start_dt, + count(d.user_seq) as now_number_of_people, + a.room_intro + from room_main a + left join room_type b + on a.room_type_seq = b.room_type_seq + left join manage_user c + on a.user_seq = c.user_seq + left join room_score_team_participant d + on a.room_seq = d.room_seq + where a.room_seq in {room_seq_list_team} + group by a.room_seq, c.nickname, a.room_status, a.open_yn, b.room_type_name, a.number_of_people, a.start_dt, a.room_intro + """) + return db.execute(query).fetchall() + + +# 방번호로 방 상태 체크 +async def select_room_status_by_room_seq(room_seq, db): + query = text(f""" + select + room_status + from room_main + where room_seq = {room_seq} + """) + return db.execute(query).fetchall() + + +# 방번호로 방 상태 체크 +async def check_already_enter_user(room_seq, room_type, user_seq, db): + if room_type == 'private' or room_type == 'PRIVATE': + query = text(f""" + select + count(user_seq) + from room_score_private_participant + where user_seq = {user_seq} + and room_seq = {room_seq} + """) + elif room_type == 'team' or room_type == 'TEAM': + query = text(f""" + select + count(user_seq) + from room_score_team_participant + where user_seq = {user_seq} + and room_seq = {room_seq} + """) + else: + return [[]] + return db.execute(query).fetchall() + + +# 방번호, 방종류로 현재 인원수 체크 후 입장 가능여부 확인 +async def select_now_number_of_people(room_seq, room_type, db): + query = text(f""" + select + count(b.user_seq) as now_people_cnt, + a.number_of_people + from room_main a + left join room_score_{room_type}_participant b + on a.room_seq = b.room_seq + where a.room_seq = {room_seq} + group by a.room_seq + """) + return db.execute(query).fetchall() + + +# 방 입장하기 +async def enter_room_user(room_seq, room_type, user_seq, db): + if room_type == 'private' or room_type == 'PRIVATE': + query = text(f""" + insert into room_score_private_participant(room_seq, participant_type, user_seq, nickname, score) + values( + {room_seq}, + (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TYPE' and reserve_code = 'PLAYER'), + {user_seq}, + (select nickname from manage_user where user_seq = {user_seq}), + 0 + ) + """) + elif room_type == 'team' or room_type == 'TEAM': + query = text(f""" + insert into room_score_team_participant(room_seq, participant_type, user_seq, nickname, team_name, score) + values( + {room_seq}, + (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TYPE' and reserve_code = 'ADMIN'), + {user_seq}, + (select nickname from manage_user where user_seq = {user_seq}), + (select reserve_code from reserve_code where reserve_code_group = 'PARTICIPANT_TEAM_NAME' and reserve_code = 'WAIT'), + 0 + ) + """) + else: + return False + try: + db.execute(query) + db.commit() + return True + except Exception as e: + logger.error(f"sql error: {e}") + return False + + +# 점수 수정하기 +async def update_user_score(target_user_seq, after_score, room_type, room_seq, db): + if room_type == 'private' or room_type == 'PRIVATE': + query = text(f""" + update room_score_private_participant + set score = {after_score} + where room_seq = {room_seq} + and user_seq = {target_user_seq} + """) + elif room_type == 'team' or room_type == 'TEAM': + query = text(f""" + update room_score_team_participant + set score = {after_score} + where room_seq = {room_seq} + and user_seq = {target_user_seq} + """) + else: + return False + 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/certification/cert_process.py b/fastapi/app/process/certification/cert_process.py index 532ff49..0219089 100644 --- a/fastapi/app/process/certification/cert_process.py +++ b/fastapi/app/process/certification/cert_process.py @@ -93,7 +93,7 @@ def renew_cert(request: Request): if iat <= now and now <= exp: return { "result": "OK", - "data": make_auth_data(create_jwt(user_seq=user_seq, period=3600), 'Y') + "data": make_auth_data(create_jwt(user_seq=user_seq, period=60*60*24*30), 'Y') } else: return { diff --git a/fastapi/app/process/room/room_score.py b/fastapi/app/process/room/room_score.py index cfa7efc..b046fcc 100644 --- a/fastapi/app/process/room/room_score.py +++ b/fastapi/app/process/room/room_score.py @@ -25,11 +25,17 @@ async def insert_score_open_range(data, db): select_room_seq_by_data = await crud_room_score.select_room_seq_by_data(data=data, db=db) data['room_seq'] = select_room_seq_by_data[0][0] # 점수 공개 범위 설정 데이터 입력 - db_result = await crud_room_score.insert_score_open_range(data=data, db=db) - - if db_result: + insert_score_open_range_result = await crud_room_score.insert_score_open_range(data=data, db=db) + if insert_score_open_range_result: + if data['room_type'] == 'team': + # 팀수에 따른 팀 이름 입력 + insert_team_name_result = await crud_room_score.insert_team_name(data=data, db=db) + if not insert_team_name_result: + return { + "result": "FAIL", + } return { - "result": "OK" + "result": "OK", } else: return { @@ -37,6 +43,8 @@ async def insert_score_open_range(data, db): } + + # 방장 참여자 입력 async def insert_creater_user(data, db): # room_seq 조회 @@ -78,7 +86,7 @@ async def participant_user_list(room_type, room_seq, db): db_result_ori = await crud_room_score.participant_user_list(room_type=room_type, room_seq=room_seq, db=db) db_result = [] for db_data in db_result_ori: - if room_type == 'private': + if room_type == 'private' or room_type == 'PRIVATE': db_result.append({ "user_seq": db_data[0], "participant_type": db_data[1], @@ -88,7 +96,7 @@ async def participant_user_list(room_type, room_seq, db): "department": db_data[5], "introduce_myself": db_data[6] }) - elif room_type == 'team': + elif room_type == 'team' or room_type == 'TEAM': db_result.append({ "user_seq": db_data[0], "participant_type": db_data[1], @@ -99,7 +107,7 @@ async def participant_user_list(room_type, room_seq, db): "department": db_data[6], "introduce_myself": db_data[7] }) - + if len(db_result) == 0: return { "result": "FAIL" @@ -132,6 +140,19 @@ async def check_requester_room_master_auth(user_seq, room_seq, db): } +# 팀전일 경우 team_name이 WAIT상태가 없는지 확인 +async def check_granted_team_name(room_seq, db): + db_result_ori = await crud_room_score.check_granted_team_name(room_seq=room_seq, db=db) + if db_result_ori[0][0] == 0: + return { + "result": "OK" + } + else: + return { + "result": "FAIL" + } + + # 요청자가 방장인지 확인 async def update_room_status(room_seq, room_status, db): room_status_follow_list = ['WAIT', 'RUNNING', 'FINISH'] @@ -153,6 +174,212 @@ async def update_room_status(room_seq, room_status, db): } +# 방 설정정보 가져오기 +async def select_room_setting_info(user_seq, room_seq, room_type, db): + db_result_ori = await crud_room_score.select_room_setting_info(room_seq=room_seq, room_type=room_type, db=db) + if len(db_result_ori) == 1: + db_data = db_result_ori[0] + db_result = { + "room_master_yn": 'Y' if int(db_data[0]) == int(user_seq) else 'N', + "room_title": db_data[1], + "room_intro": db_data[2], + "open_yn": db_data[3], + "running_time": db_data[4], + "room_type_name": db_data[5], + "number_of_teams": db_data[6], + "number_of_people": db_data[7], + "score_open_range": db_data[8], + } + return { + "result": "OK", + "data": db_result + } + return { + "result": "FAIL", + } + + +# 방 설정정보 수정하기 +async def update_room_setting_info(data, db): + if await crud_room_score.update_room_setting_info_room_main(data=data, db=db): + if data['room_type'] == 'private': + if await crud_room_score.update_room_setting_info_room_score_private(data=data, db=db): + return { + "result": "OK" + } + elif data['room_type'] == 'team': + if await crud_room_score.update_room_setting_info_room_score_team(data=data, db=db): + return { + "result": "OK" + } + return { + "result": "FAIL", + } + + +# 방 사회자 권한 확인 +async def check_admin_auth_user(user_seq, room_type, room_seq, db): + db_result_ori = await crud_room_score.check_admin_auth_user(user_seq=user_seq, room_type=room_type, room_seq=room_seq, db=db) + db_result = [] + for db_data in db_result_ori: + db_result.append(db_data) + + # 일치하는 유저가 있는지 확인 + if int(db_result[0][0]) == int(user_seq): + return { + "result": "OK" + } + else: + return { + "result": "FAIL" + } + + +# 참가자 역할&팀 수정하기 +async def update_participant_role_team(data, db): + if await crud_room_score.update_participant_role_team(data=data, db=db): + return { + "result": "OK" + } + else: + return { + "result": "FAIL", + } + + +# 방 리스트 가져오기 +async def select_room_list(search_type, search_value, db): + try: + room_seq_list = await crud_room_score.select_room_seq_list(search_type=search_type, search_value=search_value, db=db) + room_seq_list_private = [] + room_seq_list_team = [] + for (room_seq, room_type) in room_seq_list: + if room_type == 'PRIVATE': + room_seq_list_private.append(str(room_seq)) + elif room_type == 'TEAM': + room_seq_list_team.append(str(room_seq)) + else: + return { + "result": "FAIL", + } + room_seq_list_private = f"({','.join(room_seq_list_private)})" + room_seq_list_team = f"({','.join(room_seq_list_team)})" + + db_result_ori_room_list_private = await crud_room_score.select_room_list_private(room_seq_list_private=room_seq_list_private, db=db) + db_result_ori_room_list_team = await crud_room_score.select_room_list_team(room_seq_list_team=room_seq_list_team, db=db) + db_result = [] + for db_result_ori in [db_result_ori_room_list_private, db_result_ori_room_list_team]: + for db_data in db_result_ori: + db_result.append({ + "room_seq": db_data[0], + "nickname": db_data[1], + "room_status": db_data[2], + "open_yn": db_data[3], + "room_type_name": db_data[4], + "number_of_people": db_data[5], + "start_dt": db_data[6], + "now_number_of_people": db_data[7], + "room_intro": db_data[8], + }) + return { + "result": "OK", + "data": db_result + } + + except Exception as e: + return { + "result": "FAIL", + } + + +# 방번호로 방 상태 체크 +async def check_room_status_by_room_seq_room_status(room_seq, room_status, db): + db_result_ori = await crud_room_score.select_room_status_by_room_seq(room_seq=room_seq, db=db) + if len(db_result_ori) != 1: + return { + "result": "FAIL", + } + # room_status 상태가 아니면 FAIL + if db_result_ori[0][0] == room_status: + return { + "result": "OK" + } + else: + return { + "result": "FAIL", + } + + +# 방번호로 방 상태 체크 +async def check_already_enter_user(room_seq, room_type, user_seq, db): + db_result_ori = await crud_room_score.check_already_enter_user(room_seq=room_seq, room_type=room_type, user_seq=user_seq, db=db) + if len(db_result_ori) == 0: + return { + "result": "FAIL", + } + # 조회된 유저가 0이면 입장 가능 + if db_result_ori[0][0] == 0: + return { + "result": "OK" + } + else: + return { + "result": "FAIL", + } + + +# 방번호, 방종류로 현재 인원수 체크 후 입장 가능여부 확인 +async def check_now_number_of_people_and_can_enter(room_seq, room_type, db): + db_result_ori = await crud_room_score.select_now_number_of_people(room_seq=room_seq, room_type=room_type, db=db) + if len(db_result_ori) != 1: + return { + "result": "FAIL", + } + # 현재 인원수<최대인원수 조건이면 OK + (now_people_cnt, max_people_cnt) = db_result_ori[0] + if now_people_cnt < max_people_cnt: + return { + "result": "OK" + } + else: + return { + "result": "FAIL", + } + + +# 방 입장하기 +async def enter_room_user(room_seq, room_type, user_seq, db): + if await crud_room_score.enter_room_user(room_seq=room_seq, room_type=room_type, user_seq=user_seq, db=db): + return { + "result": "OK" + } + else: + return { + "result": "FAIL", + } + + +# 점수 수정하기 +async def update_user_score(target_user_seq, after_score, room_type, room_seq, db): + if await crud_room_score.update_user_score(target_user_seq=target_user_seq, after_score=after_score, room_type=room_type, room_seq=room_seq, db=db): + return { + "result": "OK" + } + else: + return { + "result": "FAIL", + } + + + + + + + + + + + diff --git a/fastapi/app/process/room/room_score_pattern.py b/fastapi/app/process/room/room_score_pattern.py index 1caf456..d83ee51 100644 --- a/fastapi/app/process/room/room_score_pattern.py +++ b/fastapi/app/process/room/room_score_pattern.py @@ -12,6 +12,13 @@ async def verify_create_room_data(data, db): verify_room_type_result = await crud_room_score.verify_room_type(room_type=data['room_type'], db=db) if verify_room_type_result[0][0] != 1: return 'room_type이 정확하지 않습니다.' + + # team전일 경우 팀수도 입력됐는지 체크 + if data['room_type'] == 'team': + if not 'number_of_teams' in data: + return '팀전일 경우 팀수를 입력해야 합니다.' + if not is_non_negative_integer(data['number_of_teams']): + return '팀수는 정수이어야 하며, 1이상의 정수값만 가능합니다.' # room_title 체크 if not (0 < len(data['room_title']) and len(data['room_title']) < 100): @@ -26,11 +33,17 @@ async def verify_create_room_data(data, db): return '방 공개 여부를 확인해주세요.' # room_pw 체크 - if not (data['open_yn'] == 'Y' and data['room_pw'] == ''): - return '공개 방입니다. 방 비밀번호를 확인해주세요.' + if data['open_yn'] == 'Y': + if not data['room_pw'] == '': + return '공개 방입니다. 방 비밀번호를 확인해주세요.' - if data['open_yn'] == 'N' and not (0 < len(data['room_pw']) and len(data['room_pw']) < 100): - return '방 비밀번호를 확인해주세요.' + if data['open_yn'] == 'N': + if not (0 < len(data['room_pw']) and len(data['room_pw']) < 100): + return '방 비밀번호를 확인해주세요.' + + # running_time 체크 + if not is_non_negative_integer(data['running_time']): + return '운영시간을 확인해주세요.' # room_status 체크 verify_room_status_result = await crud_room_score.verify_room_status(room_status=data['room_status'], db=db) @@ -41,7 +54,14 @@ async def verify_create_room_data(data, db): return None - +def is_non_negative_integer(value): + try: + # 정수로 변환 시도 + num = int(value) + # 0 이상인지 확인 + return num > 0 + except (ValueError, TypeError): + return False diff --git a/fastapi/app/router/room_score_api.py b/fastapi/app/router/room_score_api.py index 38b58b5..109220a 100644 --- a/fastapi/app/router/room_score_api.py +++ b/fastapi/app/router/room_score_api.py @@ -126,10 +126,10 @@ async def get_waiting_private_room_info(request: Request, body: bytes = Depends( #================================================================================================== -# 대기중인 방-개인 게임 시작하기 +# 대기중인 방-게임 시작하기 #================================================================================================== -@router.post("/start/private") -async def start_private_room(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): +@router.post("/game/start") +async def start_game(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): try: # 인증서 갱신 auth_token = cert_process.renew_cert(request=request) @@ -151,6 +151,15 @@ async def start_private_room(request: Request, body: bytes = Depends(get_body), # 요청자가 방장인지 확인 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': + # 방 상태가 대기중 인지 확인 + check_room_status_by_room_seq_room_status_result = await room_score.check_room_status_by_room_seq_room_status(room_seq=body['room_seq'], room_status='WAIT', db=db) + if check_room_status_by_room_seq_room_status_result['result'] == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='게임 시작 실패', msg_content='게임 시작은 대기중 상태에서만 가능합니다.', data={}) + # 팀전일 경우 team_name이 WAIT상태가 없는지 확인 + if body['room_type'] == 'team' or body['room_type'] == 'TEAM': + check_granted_team_name_result = await room_score.check_granted_team_name(room_seq=body['room_seq'], db=db) + if check_granted_team_name_result['result'] == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='게임 시작 실패', msg_content='팀전일 경우 팀배치가 완료되어야 시작가능합니다.', data={}) # 방 상태 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': @@ -163,8 +172,8 @@ async def start_private_room(request: Request, body: bytes = Depends(get_body), return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) except Exception as e: - logger.error(f"request error. URL: /room/score/start/private\nerror message: {e}") - return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(대기중인 방-개인 게임 시작하기) 에러', msg_content='(대기중인 방-개인 게임 시작하기) 처리중 에러가 발생했습니다.', data={}) + logger.error(f"request error. URL: /room/score/game/start\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(대기중인 방-게임 시작하기) 에러', msg_content='(대기중인 방-게임 시작하기) 처리중 에러가 발생했습니다.', data={}) #================================================================================================== @@ -191,7 +200,15 @@ async def get_waiting_team_room_info(request: Request, body: bytes = Depends(get if user_seq_result["result"] == 'OK': user_seq = user_seq_result['data']['user_seq'] body['user_seq'] = user_seq - # TODO + # 방 참여자 조회 권한 확인 + check_auth_user_result = await room_score.check_auth_user(user_seq=user_seq, room_type='team', room_seq=body['room_seq'], db=db) + if check_auth_user_result == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='참가자 조회 실패', msg_content='참가자 조회 권한이 없습니다.', data={}) + # 참가자 정보 가져오기 + participant_user_list_result = await room_score.participant_user_list(room_type='team', room_seq=body['room_seq'], db=db) + if participant_user_list_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data=participant_user_list_result['data'], db=db) + 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={}) @@ -200,6 +217,307 @@ async def get_waiting_team_room_info(request: Request, body: bytes = Depends(get return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(대기중인 방-팀 참가자 정보) 에러', msg_content='(대기중인 방-팀 참가자 정보) 처리중 에러가 발생했습니다.', data={}) +#================================================================================================== +# 방 설정정보 가져오기 +#================================================================================================== +@router.post("/room/setting/info") +async def get_room_setting_info(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): + try: + # 인증서 갱신 + auth_token = cert_process.renew_cert(request=request) + if auth_token['result'] == 'OK': + auth_token = auth_token['data'] + elif auth_token['result'] == 'TOKEN_EXPIRED': + raise token_expired_return_process(auth_token['msg']) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) + # body에서 ID 추출 + try: + body = json.loads(body) + except json.JSONDecodeError as e: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='데이터 에러', msg_content='데이터 처리 장애가 발생했습니다. 요청정보를 정확히 입력했는지 확인해주세요.', data={}) + + 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'] + # 방 참여자 조회 권한 확인 + check_auth_user_result = await room_score.check_auth_user(user_seq=user_seq, room_type=body['room_type'], room_seq=body['room_seq'], db=db) + if check_auth_user_result == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='참가자 조회 실패', msg_content='참가자 조회 권한이 없습니다.', data={}) + # 방 설정정보 가져오기 + select_room_setting_info_result = await room_score.select_room_setting_info(user_seq=user_seq, room_seq=body['room_seq'], room_type=body['room_type'], db=db) + if select_room_setting_info_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data=select_room_setting_info_result['data'], db=db) + 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={}) + + except Exception as e: + logger.error(f"request error. URL: /room/score/room/setting/info\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(방 설정정보 가져오기) 에러', msg_content='(방 설정정보 가져오기) 처리중 에러가 발생했습니다.', data={}) + + +#================================================================================================== +# 방 설정 수정하기 +#================================================================================================== +@router.post("/update/room/setting/info") +async def update_room_setting_info(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): + try: + # 인증서 갱신 + auth_token = cert_process.renew_cert(request=request) + if auth_token['result'] == 'OK': + auth_token = auth_token['data'] + elif auth_token['result'] == 'TOKEN_EXPIRED': + raise token_expired_return_process(auth_token['msg']) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) + # body에서 ID 추출 + try: + body = json.loads(body) + except json.JSONDecodeError as e: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='데이터 에러', msg_content='데이터 처리 장애가 발생했습니다. 요청정보를 정확히 입력했는지 확인해주세요.', data={}) + + 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'] + # 방 참여자 조회 권한 확인 + check_auth_user_result = await room_score.check_auth_user(user_seq=user_seq, room_type=body['room_type'], room_seq=body['room_seq'], db=db) + if check_auth_user_result == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='참가자 조회 실패', msg_content='참가자 조회 권한이 없습니다.', data={}) + # 방 설정정보 가져오기 + select_room_setting_info_result = await room_score.select_room_setting_info(user_seq=user_seq, room_seq=body['room_seq'], room_type=body['room_type'], db=db) + if select_room_setting_info_result['result'] == 'OK': + room_master_yn = select_room_setting_info_result['data']['room_master_yn'] + if room_master_yn == 'Y': + # 방 설정정보 수정하기 + update_room_setting_info_result = await room_score.update_room_setting_info(data=body, db=db) + if update_room_setting_info_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data={}, db=db) + else: + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='방 설정정보 수정 실패', msg_content='방 설정정보 수정 권한이 없습니다.', data={}) + 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={}) + + except Exception as e: + logger.error(f"request error. URL: /room/score/update/room/setting/info\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(방 설정 수정하기) 에러', msg_content='(방 설정 수정하기) 처리중 에러가 발생했습니다.', data={}) + + +#================================================================================================== +# 유저 상태 수정하기 +#================================================================================================== +@router.post("/update/user/role") +async def update_user_role(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): + try: + # 인증서 갱신 + auth_token = cert_process.renew_cert(request=request) + if auth_token['result'] == 'OK': + auth_token = auth_token['data'] + elif auth_token['result'] == 'TOKEN_EXPIRED': + raise token_expired_return_process(auth_token['msg']) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) + # body에서 ID 추출 + try: + body = json.loads(body) + except json.JSONDecodeError as e: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='데이터 에러', msg_content='데이터 처리 장애가 발생했습니다. 요청정보를 정확히 입력했는지 확인해주세요.', data={}) + + 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'] + # 방 사회자 권한 확인 + check_admin_auth_user_result = await room_score.check_admin_auth_user(user_seq=user_seq, room_type=body['room_type'], room_seq=body['room_seq'], db=db) + if check_admin_auth_user_result == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='참가자 조회 실패', msg_content='참가자 조회 권한이 없습니다.', data={}) + # 참가자 역할&팀 수정하기 + update_participant_role_team_result = await room_score.update_participant_role_team(data=body, db=db) + if update_participant_role_team_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data={}, db=db) + 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={}) + + except Exception as e: + logger.error(f"request error. URL: /room/score/update/user/role\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(유저 상태 수정하기) 에러', msg_content='(유저 상태 수정하기) 처리중 에러가 발생했습니다.', data={}) + + +#================================================================================================== +# 검색 방 리스트 가져오기 +#================================================================================================== +@router.post("/room/list") +async def get_room_list(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): + try: + # 인증서 갱신 + auth_token = cert_process.renew_cert(request=request) + if auth_token['result'] == 'OK': + auth_token = auth_token['data'] + elif auth_token['result'] == 'TOKEN_EXPIRED': + raise token_expired_return_process(auth_token['msg']) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) + # body에서 ID 추출 + try: + body = json.loads(body) + except json.JSONDecodeError as e: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='데이터 에러', msg_content='데이터 처리 장애가 발생했습니다. 요청정보를 정확히 입력했는지 확인해주세요.', data={}) + + 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 + # search_type(waiting, running, finish), search_value + # 방 리스트 가져오기 + select_room_list_result = await room_score.select_room_list(search_type=body['search_type'], search_value=body['search_value'], db=db) + if select_room_list_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data=select_room_list_result['data'], db=db) + 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={}) + + except Exception as e: + logger.error(f"request error. URL: /room/score/room/list\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(검색 방 리스트 가져오기) 에러', msg_content='(검색 방 리스트 가져오기) 처리중 에러가 발생했습니다.', data={}) + + +#================================================================================================== +# 방 입장하기 +#================================================================================================== +@router.post("/enter/room") +async def enter_room(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): + try: + # 인증서 갱신 + auth_token = cert_process.renew_cert(request=request) + if auth_token['result'] == 'OK': + auth_token = auth_token['data'] + elif auth_token['result'] == 'TOKEN_EXPIRED': + raise token_expired_return_process(auth_token['msg']) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) + # body에서 ID 추출 + try: + body = json.loads(body) + except json.JSONDecodeError as e: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='데이터 에러', msg_content='데이터 처리 장애가 발생했습니다. 요청정보를 정확히 입력했는지 확인해주세요.', data={}) + + 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 + # 방번호로 방 상태 체크 + check_room_status_by_room_seq_room_status_result = await room_score.check_room_status_by_room_seq_room_status(room_seq=body['room_seq'], room_status='WAIT', db=db) + if check_room_status_by_room_seq_room_status_result['result'] == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='방 입장 실패', msg_content='대기중 상태인 방에만 입장이 가능합니다.', data={}) + # 이미 입장한 유저인지 확인 + check_already_enter_user_result = await room_score.check_already_enter_user(room_seq=body['room_seq'], room_type=body['room_type'], user_seq=user_seq, db=db) + if check_already_enter_user_result['result'] == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='방 입장 실패', msg_content='이미 입장한 유저입니다.', data={}) + # 방번호, 방종류로 현재 인원수 체크 후 입장 가능여부 확인 + check_now_number_of_people_and_can_enter_result = await room_score.check_now_number_of_people_and_can_enter(room_seq=body['room_seq'], room_type=body['room_type'], db=db) + if check_now_number_of_people_and_can_enter_result['result'] == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='방 입장 실패', msg_content='방 입장 정원이 초과됐습니다.', data={}) + # 방 입장하기 + enter_room_user_result = await room_score.enter_room_user(room_seq=body['room_seq'], room_type=body['room_type'], user_seq=user_seq, db=db) + if enter_room_user_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={}) + + except Exception as e: + logger.error(f"request error. URL: /room/score/enter/room\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(방 입장하기) 에러', msg_content='(방 입장하기) 처리중 에러가 발생했습니다.', data={}) + + +#================================================================================================== +# 진행중인방 점수 정보 가져오기 +#================================================================================================== +@router.post("/running/room/score/info") +async def get_running_room_score_info(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): + try: + # 인증서 갱신 + auth_token = cert_process.renew_cert(request=request) + if auth_token['result'] == 'OK': + auth_token = auth_token['data'] + elif auth_token['result'] == 'TOKEN_EXPIRED': + raise token_expired_return_process(auth_token['msg']) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) + # body에서 ID 추출 + try: + body = json.loads(body) + except json.JSONDecodeError as e: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='데이터 에러', msg_content='데이터 처리 장애가 발생했습니다. 요청정보를 정확히 입력했는지 확인해주세요.', data={}) + + 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'] + # 방 참여자 조회 권한 확인 + check_auth_user_result = await room_score.check_auth_user(user_seq=user_seq, room_type=body['room_type'], room_seq=body['room_seq'], db=db) + if check_auth_user_result == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='참가자 조회 실패', msg_content='참가자 조회 권한이 없습니다.', data={}) + # 방 상태가 진행중 인지 확인 + check_room_status_by_room_seq_room_status_result = await room_score.check_room_status_by_room_seq_room_status(room_seq=body['room_seq'], room_status='RUNNING', db=db) + if check_room_status_by_room_seq_room_status_result['result'] == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='점수 조회 실패', msg_content='점수 정보 조회는 진행중 상태만 조회가 가능합니다.', data={}) + # 점수 정보 가져오기 + participant_user_list_result = await room_score.participant_user_list(room_type=body['room_type'], room_seq=body['room_seq'], db=db) + if participant_user_list_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data=participant_user_list_result['data'], db=db) + 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={}) + + except Exception as e: + logger.error(f"request error. URL: /room/score/running/room/score/info\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(진행중인방 점수 정보 가져오기) 에러', msg_content='(진행중인방 점수 정보 가져오기) 처리중 에러가 발생했습니다.', data={}) + + +#================================================================================================== +# 점수 수정하기 +#================================================================================================== +@router.post("/update/score") +async def update_running_room_score(request: Request, body: bytes = Depends(get_body), db: Session = Depends(get_db)): + try: + # 인증서 갱신 + auth_token = cert_process.renew_cert(request=request) + if auth_token['result'] == 'OK': + auth_token = auth_token['data'] + elif auth_token['result'] == 'TOKEN_EXPIRED': + raise token_expired_return_process(auth_token['msg']) + else: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='토큰 에러', msg_content='토큰 정보가 정확하지 않습니다.', data={}) + # body에서 ID 추출 + try: + body = json.loads(body) + except json.JSONDecodeError as e: + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='데이터 에러', msg_content='데이터 처리 장애가 발생했습니다. 요청정보를 정확히 입력했는지 확인해주세요.', data={}) + + 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'] + # 방 사회자 권한 확인 + check_admin_auth_user_result = await room_score.check_admin_auth_user(user_seq=user_seq, room_type=body['room_type'], room_seq=body['room_seq'], db=db) + if check_admin_auth_user_result == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='점수 수정 실패', msg_content='점수 수정 권한이 없습니다.', data={}) + # 방 상태가 진행중 인지 확인 + check_room_status_by_room_seq_room_status_result = await room_score.check_room_status_by_room_seq_room_status(room_seq=body['room_seq'], room_status='RUNNING', db=db) + if check_room_status_by_room_seq_room_status_result['result'] == 'FAIL': + return await response.fail_res(auth_token=auth_token, auth_type='NOMAL', msg_title='점수 조회 실패', msg_content='점수 정보 조회는 진행중 상태만 조회가 가능합니다.', data={}) + # 점수 수정하기 + update_user_score_result = await room_score.update_user_score(target_user_seq=body['target_user_seq'], after_score=body['after_score'], room_type=body['room_type'], room_seq=body['room_seq'], db=db) + if update_user_score_result['result'] == 'OK': + return await response.ok_res(auth_token=auth_token, data={}, db=db) + 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={}) + + except Exception as e: + logger.error(f"request error. URL: /room/score/update/score\nerror message: {e}") + return await response.error_res(auth_token=auth_token, auth_type='NOMAL', msg_title='(점수 수정하기) 에러', msg_content='(점수 수정하기) 처리중 에러가 발생했습니다.', data={}) + +