diff --git a/fastapi/app/db/crud_room_score.py b/fastapi/app/db/crud_room_score.py index 03041de..30d3160 100644 --- a/fastapi/app/db/crud_room_score.py +++ b/fastapi/app/db/crud_room_score.py @@ -125,6 +125,25 @@ async def check_auth_user(user_seq, room_type, room_seq, db): return db.execute(query).fetchall() +# 참가자 정보 가져오기 +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} + """) + return db.execute(query).fetchall() + + diff --git a/fastapi/app/process/room/room_score.py b/fastapi/app/process/room/room_score.py index ef6c692..f8904fc 100644 --- a/fastapi/app/process/room/room_score.py +++ b/fastapi/app/process/room/room_score.py @@ -57,7 +57,7 @@ async def insert_creater_user(data, db): # 방 참여자 조회 권한 확인 async def check_auth_user(user_seq, room_type, room_seq, db): - db_result_ori = crud_room_score.check_auth_user(user_seq=user_seq, room_type=room_type, room_seq=room_seq, db=db) + db_result_ori = await crud_room_score.check_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) @@ -74,11 +74,31 @@ async def check_auth_user(user_seq, room_type, room_seq, db): # 참가자 정보 가져오기 -async def participant_user_list(user_seq_list, room_type, room_seq, db): - db_result_ori = crud_room_score.participant_user_list(user_seq_list=user_seq_list, room_type=room_type, room_seq=room_seq, db=db) +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: - db_result.append(db_data) + if room_type == 'private': + db_result.append({ + "user_seq": db_data[0], + "participant_type": db_data[1], + "nickname": db_data[2], + "score": db_data[3], + "profile_img": db_data[4], + "department": db_data[5], + "introduce_myself": db_data[6] + }) + elif room_type == 'team': + db_result.append({ + "user_seq": db_data[0], + "participant_type": db_data[1], + "nickname": db_data[2], + "team_name": db_data[3], + "score": db_data[4], + "profile_img": db_data[5], + "department": db_data[6], + "introduce_myself": db_data[7] + }) if len(db_result) == 0: return { @@ -86,7 +106,8 @@ async def participant_user_list(user_seq_list, room_type, room_seq, db): } else: return { - "result": "OK" + "result": "OK", + "data": db_result } diff --git a/fastapi/app/router/room_score_api.py b/fastapi/app/router/room_score_api.py index 42eb27b..fc5a22d 100644 --- a/fastapi/app/router/room_score_api.py +++ b/fastapi/app/router/room_score_api.py @@ -109,11 +109,14 @@ async def get_waiting_private_room_info(request: Request, body: bytes = Depends( if user_seq_result["result"] == 'OK': user_seq = user_seq_result['data']['user_seq'] # 방 참여자 조회 권한 확인 - check_auth_user_result = room_score.check_auth_user(user_seq=user_seq, room_type='private', room_seq=body['room_seq'], db=db) - if check_auth_user_result != 'OK': + check_auth_user_result = await room_score.check_auth_user(user_seq=user_seq, room_type='private', 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 = room_score.participant_user_list(user_seq_list=body['user_seq_list'], room_type='private', room_seq=body['room_seq'], db=db) + participant_user_list_result = await room_score.participant_user_list(room_type='private', 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={})