From dd3523eb72808a7364ee975ebe9ba09ec52353a3 Mon Sep 17 00:00:00 2001 From: happybell80 Date: Mon, 18 Aug 2025 14:00:07 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20resolve=5Fusername=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0=20=EB=82=B4=EC=9A=A9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Auth 서버 API 통합 구현 내용 기록 - 5단계 우선순위 사용자 식별 시스템 문서화 - 기존 계획과의 연계성 명시 --- ...18_happybell80_대화히스토리구현.md | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/troubleshooting/250818_happybell80_대화히스토리구현.md b/troubleshooting/250818_happybell80_대화히스토리구현.md index aa8023c..d66d645 100644 --- a/troubleshooting/250818_happybell80_대화히스토리구현.md +++ b/troubleshooting/250818_happybell80_대화히스토리구현.md @@ -183,6 +183,42 @@ results = collection.query( ) ``` +## 오후 2시 00분 - resolve_username 함수 개선 + +### 기존 계획과의 연계 +- 250812_slack_user_mapping_구현.md에 이미 Auth 서버 API 구현됨 +- `/api/slack/mapping/{slack_user_id}` 엔드포인트 활용 가능 +- 프론트엔드 연동 부분만 누락되어 있었음 + +### 통합 사용자 식별 시스템 구현 +```python +async def resolve_username(user_id: str) -> str: + """모든 형태의 user_id를 username으로 해석""" + + # 1. Slack ID (U로 시작) -> Auth 서버 API 호출 + if user_id.startswith('U') and len(user_id) > 8: + response = await client.get(f"{AUTH_SERVER_URL}/api/slack/mapping/{user_id}") + if response.status_code == 200: + return response.json()['username'] + + # 2. 이메일 (@포함) -> @ 앞부분 추출 + if '@' in user_id: + username = user_id.split('@')[0] + if user_id in USER_MAPPING: # 알려진 이메일 확인 + return USER_MAPPING[user_id] + return username + + # 3. 로컬 매핑 테이블 + # 4. "_user" 접미사 제거 + # 5. 원본 반환 +``` + +### 개선 효과 +- Slack, 이메일, username 모든 형태 지원 +- Auth 서버와 통합하여 중앙 관리 +- 5단계 우선순위로 안정적 해석 +- 비동기 처리로 성능 유지 + ## 교훈 (추가) ### 5. **User ID 체계 통일 필수**