from fastapi import Request import json from process.logger import logger import jwt import datetime import time from process.certification import cert_process from process.user import manage_user # 성공 응답 async def ok_res(auth_token, data, db): try: user_seq = auth_token['user_seq'] return make_response('OK', auth_token['renew_yn'], 'NOMAL', auth_token['token'], user_seq, '성공', '성공', data) except Exception as e: logger.error(f"ok response error: {e}") return make_response('ERROR', 'N', 'NOMAL', '', 0, '응답 에러', '서버 장애가 발생했습니다.', data) # 실패 응답 async def fail_res(auth_token, auth_type, msg_title, msg_content, data): try: return make_response('FAIL', auth_token['renew_yn'], auth_type, auth_token['token'], auth_token['user_seq'], msg_title, msg_content, data) except Exception as e: logger.error(f"ok response error: {e}") return make_response('ERROR', 'N', 'NOMAL', '', 0, '응답 에러', '서버 장애가 발생했습니다.', data) # 에러 응답 async def error_res(auth_token, auth_type, msg_title, msg_content, data): try: return make_response('ERROR', auth_token['renew_yn'], auth_type, auth_token['token'], auth_token['user_seq'], msg_title, msg_content, data) except Exception as e: logger.error(f"ok response error: {e}") return make_response('ERROR', 'N', 'NOMAL', '', 0, '응답 에러', '서버 장애가 발생했습니다.', data) # 응답 패턴 def make_response(result, renew_yn, auth_type, token, user_seq, msg_title, msg_content, data): return { "result": result, # OK, FAIL, ERROR "auth": { "renew_yn": renew_yn, "type": auth_type, "token": token, "user_seq": user_seq, }, "response_info": { "msg_type": result, # OK, FAIL, ERROR "msg_title": msg_title, "msg_content": msg_content, }, "data": data, } # # 기존 응답 방식 # { # "result": "FAIL", # "msg": fail_msg, # "auth": { # "auth-token": { # "renew_yn": 'Y', # "token": '토큰값' # } # }, # "data": {} # } # # 새로운 응답 방식 # { # "result": "FAIL", # OK, FAIL, ERROR # "data": { # "auth": { # "renew_yn": 'Y', # "type": 'ADMIN', # "token": '토큰값' # }, # "response_info": { # "msg_type": 'FAIL', # OK, FAIL, ERROR # "msg_title": '제목', # "msg_content": '내용', # }, # "data": '데이터', # } # }