-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: notion parser #557
feat: notion parser #557
Conversation
📝 WalkthroughWalkthrough이 풀 리퀘스트는 Notion 데이터 처리를 위한 여러 계층에서 수정 및 신규 기능을 도입합니다. NotionApi의 getGroups 메서드가 반환형과 파라미터 타입이 변경되었고, 이를 활용하는 RestNotionRepository와 NotionRepository 인터페이스가 추가되었습니다. 또한, 데이터 호출 및 에러 처리를 위한 NotionBloc과, Flutter 기반 NotionPageBuilder를 통해 Notion 페이지의 블록 구조 UI를 렌더링하는 기능이 구현되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant UI as 사용자
participant Bloc as NotionBloc
participant Repo as NotionRepository (RestNotionRepository)
participant API as NotionApi
participant Parser as notionParser
UI->>Bloc: _Load 이벤트 발생
Bloc->>Repo: getGroups(pageId) 호출
Repo->>API: getGroups(pageId) 호출
API-->>Repo: Raw String 반환
Repo->>Parser: notionParser(raw) 호출
Parser-->>Repo: JSON Map 반환
Repo-->>Bloc: 파싱된 데이터 전달
Bloc->>UI: 상태 변경 (done / error) 전파
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (7)
lib/app/modules/groups/domain/repository/notion_repository.dart (1)
1-3
: 인터페이스 문서화 및 타입 안전성 개선 필요다음 개선사항을 고려해주세요:
- 인터페이스와 메서드에 대한 문서화 주석 추가
Map<String, dynamic>
대신 명확한 응답 타입 정의예시:
/// Notion API와의 상호작용을 위한 리포지토리 인터페이스 abstract class NotionRepository { /// 주어진 페이지 ID에 해당하는 그룹 정보를 조회합니다. /// /// [pageId] - Notion 페이지 ID /// Returns: 그룹 정보를 포함하는 [NotionResponse] Future<NotionResponse> getGroups(String pageId); }lib/app/modules/groups/presentation/blocs/notion_bloc.dart (1)
24-26
: 에러 메시지를 더 구체적으로 처리하세요.에러 상태에서 단순히
e.toString()
을 사용하는 것은 사용자에게 불친절할 수 있습니다. 에러 유형에 따라 적절한 메시지를 표시하는 것이 좋습니다.- emit(NotionState.error(e.toString())); + final errorMessage = e is NetworkException + ? '네트워크 연결을 확인해주세요' + : '페이지를 불러오는 중 오류가 발생했습니다'; + emit(NotionState.error(errorMessage));lib/app/modules/groups/presentation/utils/notion_parser.dart (1)
25-31
: 타입 안전성을 개선하세요.타입 캐스팅 시 안전성을 높일 수 있습니다.
- final String type = blockValue["type"] ?? ""; + final type = blockValue["type"] as String? ?? "";lib/app/modules/groups/presentation/pages/notion_page.dart (1)
33-35
: 사용자 친화적인 에러 메시지를 추가하세요.페이지 블록을 찾지 못했을 때 더 자세한 안내 메시지를 제공하면 좋겠습니다.
- return const Center(child: Text('No page block found')); + return const Center( + child: Text( + '페이지를 찾을 수 없습니다.\n다시 시도하시거나 페이지 ID를 확인해주세요.', + textAlign: TextAlign.center, + ), + );lib/app/modules/groups/presentation/pages/notion_page_builder.dart (3)
242-247
: 이미지 로딩 에러 처리를 개선하세요.이미지 로딩 실패 시 더 자세한 피드백을 제공하면 좋겠습니다.
child: Image.network( imageUrl, fit: BoxFit.cover, - errorBuilder: (context, error, stack) => - const Text('Failed to load image'), + errorBuilder: (context, error, stack) => Column( + children: [ + const Icon(Icons.broken_image, size: 48, color: Colors.grey), + const SizedBox(height: 8), + Text('이미지를 불러올 수 없습니다\n$imageUrl', + textAlign: TextAlign.center, + style: TextStyle(color: Colors.grey)), + ], + ),
506-522
: 색상 처리 로직을 개선하세요.색상 매핑이 제한적입니다. 더 많은 색상을 지원하고 Material 색상 시스템을 활용하면 좋겠습니다.
Color? _resolveColor(String colorName) { - switch (colorName) { - case 'red': - return Colors.red; - case 'blue': - return Colors.blue; - case 'green': - return Colors.green; - case 'yellow': - return Colors.yellow; - case 'pink': - return Colors.pink; - case 'gray': - return Colors.grey; - } - return null; + final colorMap = { + 'red': Colors.red, + 'blue': Colors.blue, + 'green': Colors.green, + 'yellow': Colors.yellow, + 'pink': Colors.pink, + 'gray': Colors.grey, + 'purple': Colors.purple, + 'orange': Colors.orange, + 'brown': Colors.brown, + 'default': Colors.black, + }; + return colorMap[colorName] ?? colorMap['default'];
112-113
: TODO 주석을 해결하세요.하위 페이지 네비게이션 기능이 구현되지 않았습니다.
네비게이션 로직 구현을 도와드릴까요?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
lib/app/modules/groups/data/data_sources/remote/notion_api.dart
(1 hunks)lib/app/modules/groups/data/repositories/rest_notion_repository.dart
(1 hunks)lib/app/modules/groups/domain/repository/notion_repository.dart
(1 hunks)lib/app/modules/groups/presentation/blocs/notion_bloc.dart
(1 hunks)lib/app/modules/groups/presentation/pages/notion_page.dart
(1 hunks)lib/app/modules/groups/presentation/pages/notion_page_builder.dart
(1 hunks)lib/app/modules/groups/presentation/pages/notion_parser_page.dart
(1 hunks)lib/app/modules/groups/presentation/utils/notion_parser.dart
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build iOS App and Test
- GitHub Check: Build Android App and Test
🔇 Additional comments (3)
lib/app/modules/groups/presentation/pages/notion_parser_page.dart (1)
9-19
: 🏁 Script executed:#!/bin/bash # 위젯 테스트 파일 확인 fd "notion_parser_page_test.dart" "test"Length of output: 130
lib/app/modules/groups/presentation/blocs/notion_bloc.dart (1)
12-14
: 이벤트 핸들링 로직이 잘 구현되어 있습니다.BLoC 패턴을 올바르게 사용하여 상태 관리를 구현했습니다.
lib/app/modules/groups/presentation/utils/notion_parser.dart (1)
18-23
: null 체크 로직이 잘 구현되어 있습니다.블록 정보가 없는 경우를 적절히 처리하고 있습니다.
lib/app/modules/groups/data/repositories/rest_notion_repository.dart
Outdated
Show resolved
Hide resolved
3313f76
to
06e6a25
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (6)
lib/app/modules/groups/presentation/pages/notion_page.dart (2)
41-41
: 에러 상태 처리를 개선하세요.현재 에러 메시지만 표시하고 있습니다. 사용자가 다시 시도할 수 있는 버튼을 추가하는 것이 좋습니다.
- error: (msg) => Center(child: Text('Error: $msg')), + error: (msg) => Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text('Error: $msg'), + const SizedBox(height: 8), + ElevatedButton( + onPressed: () => context.read<NotionBloc>().add( + const NotionEvent.load( + pageId: AppConfig.notionPageId, + ), + ), + child: const Text('다시 시도'), + ), + ], + ), + ),
17-20
: 로그인 버튼의 상태 처리를 개선하세요.로그인 중일 때 버튼의 로딩 상태를 표시하고 중복 클릭을 방지하는 것이 좋습니다.
- ElevatedButton( - onPressed: () => - context.read<GroupAuthBloc>().add(GroupAuthEvent.login()), - child: Text('Login')), + BlocBuilder<GroupAuthBloc, GroupAuthState>( + builder: (context, state) { + return ElevatedButton( + onPressed: state.isLoading + ? null + : () => context.read<GroupAuthBloc>().add(GroupAuthEvent.login()), + child: state.isLoading + ? const SizedBox( + width: 16, + height: 16, + child: CircularProgressIndicator(strokeWidth: 2), + ) + : const Text('Login'), + ); + }, + ),lib/app/modules/groups/presentation/pages/notion_page_builder.dart (4)
112-113
: TODO 주석의 내비게이션 구현이 필요합니다.하위 페이지 클릭 시 새로운 페이지로 이동하는 기능이 구현되어 있지 않습니다.
내비게이션 구현을 위한 코드를 생성해드릴까요?
245-246
: 이미지 로드 실패 처리를 개선하세요.현재는 단순한 텍스트만 표시됩니다. 이미지 로드 실패 시 플레이스홀더 이미지를 표시하고 재시도 버튼을 제공하는 것이 좋습니다.
- const Text('Failed to load image'), + Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.broken_image, size: 48, color: Colors.grey), + const SizedBox(height: 8), + const Text('이미지를 불러올 수 없습니다'), + const SizedBox(height: 8), + ElevatedButton( + onPressed: () { + // 이미지 다시 로드 + (context as Element).markNeedsBuild(); + }, + child: const Text('다시 시도'), + ), + ], + ),
506-522
: 색상 처리 기능을 확장하세요.현재는 제한된 기본 색상만 지원합니다. 더 많은 색상 옵션과 사용자 정의 색상을 지원하도록 개선하는 것이 좋습니다.
Color? _resolveColor(String colorName) { + // 헥스 코드 처리 + if (colorName.startsWith('#')) { + try { + final value = int.parse(colorName.substring(1), radix: 16); + return Color(value); + } catch (e) { + debugPrint('Invalid hex color: $colorName'); + } + } + switch (colorName) { case 'red': return Colors.red; case 'blue': return Colors.blue; case 'green': return Colors.green; case 'yellow': return Colors.yellow; case 'pink': return Colors.pink; case 'gray': return Colors.grey; + case 'purple': + return Colors.purple; + case 'orange': + return Colors.orange; + case 'brown': + return Colors.brown; } return null; }
524-538
: 성능 최적화가 필요한 부분이 있습니다.
_extractPlainText
메서드에서 문자열 연산이 반복적으로 발생합니다._parseNotionStyle
메서드에서 스타일 병합이 자주 발생합니다.이러한 작업들을 최적화하면 성능을 개선할 수 있습니다.
스타일 캐싱을 위한 맵을 추가하고 문자열 연산을 최적화하세요:
+ // 스타일 캐시 + final Map<String, TextStyle> _styleCache = {}; TextStyle _parseNotionStyle(dynamic styleDirectives) { + // 캐시 키 생성 + final cacheKey = styleDirectives?.toString() ?? ''; + if (_styleCache.containsKey(cacheKey)) { + return _styleCache[cacheKey]!; + } var style = const TextStyle(); // ... 기존 스타일 파싱 로직 ... + // 결과 캐싱 + _styleCache[cacheKey] = style; return style; } String _extractPlainText(dynamic titleProperty) { if (titleProperty is List && titleProperty.isNotEmpty) { - final buffer = StringBuffer(); + // 미리 크기 계산하여 한 번에 조인 + final texts = <String>[]; for (final piece in titleProperty) { if (piece is List && piece.isNotEmpty) { final textSegment = piece[0]; if (textSegment is String) { - buffer.write(textSegment); + texts.add(textSegment); } } } - return buffer.toString(); + return texts.join(); } return ''; }Also applies to: 458-504
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
lib/app/modules/groups/data/data_sources/remote/notion_api.dart
(1 hunks)lib/app/modules/groups/data/repositories/rest_notion_repository.dart
(1 hunks)lib/app/modules/groups/domain/repository/notion_repository.dart
(1 hunks)lib/app/modules/groups/presentation/blocs/notion_bloc.dart
(1 hunks)lib/app/modules/groups/presentation/pages/notion_page.dart
(1 hunks)lib/app/modules/groups/presentation/pages/notion_page_builder.dart
(1 hunks)lib/app/modules/groups/presentation/pages/notion_parser_page.dart
(1 hunks)lib/app/modules/groups/presentation/utils/notion_parser.dart
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
- lib/app/modules/groups/domain/repository/notion_repository.dart
- lib/app/modules/groups/data/data_sources/remote/notion_api.dart
- lib/app/modules/groups/presentation/pages/notion_parser_page.dart
- lib/app/modules/groups/presentation/utils/notion_parser.dart
- lib/app/modules/groups/presentation/blocs/notion_bloc.dart
- lib/app/modules/groups/data/repositories/rest_notion_repository.dart
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build iOS App and Test
- GitHub Check: Build Android App and Test
🔇 Additional comments (1)
lib/app/modules/groups/presentation/pages/notion_page.dart (1)
51-56
: 하드코딩된 pageId를 설정으로 분리하세요.페이지 ID가 코드에 직접 하드코딩되어 있습니다. 이를 설정 파일이나 환경 변수로 분리하는 것이 좋습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
lib/app/modules/groups/data/repositories/rest_notion_repository.dart (2)
16-17
: 변수 이름을 더 명확하게 개선하세요
parse
라는 변수명은 동사형태로, 명사형태의 이름이 더 적절합니다.다음과 같이 수정하세요:
- final Map<String, dynamic> parse = await notionParser(raw); - return parse; + final Map<String, dynamic> parsedData = await notionParser(raw); + return parsedData;
12-21
: 타입 안전성과 문서화 개선 제안현재 구현의 개선 가능한 부분:
Map<String, dynamic>
대신 명확한 모델 클래스를 사용하여 타입 안전성 확보- 메소드에 대한 문서화 주석 추가
다음과 같이 개선하세요:
/// Notion API를 통해 그룹 정보를 조회합니다. /// /// [pageId] Notion 페이지 ID /// /// throws [NotionException] API 호출 실패 시 @override Future<GroupData> getGroups(String pageId) async { try { final raw = await _api.getGroups(pageId); final parsedData = await notionParser(raw); return GroupData.fromJson(parsedData); } catch (e, stackTrace) { _logger.error('Failed to fetch groups', e, stackTrace); throw NotionException('그룹 정보를 가져오는데 실패했습니다', e); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/app/modules/groups/data/repositories/rest_notion_repository.dart
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build Android App and Test
- GitHub Check: Build iOS App and Test
🔇 Additional comments (2)
lib/app/modules/groups/data/repositories/rest_notion_repository.dart (2)
1-10
: LGTM! 의존성 주입과 리포지토리 패턴이 잘 구현되어 있습니다.클래스 구조와 의존성 주입이 모범 사례를 따르고 있습니다.
18-20
: 예외 처리 개선 필요이전 리뷰에서 지적된 예외 처리 문제가 아직 해결되지 않았습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일단 중간 리뷰 입니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
lib/app/modules/groups/data/repositories/rest_notion_repository.dart (1)
12-23
:⚠️ Potential issue예외 처리 로직 개선 필요
현재 구현의 문제점이 이전 리뷰와 동일하게 남아있습니다:
Exception(e)
는 원인 예외의 컨텍스트를 잃어버립니다- 오류 로깅이 누락되었습니다
다음과 같이 개선하세요:
@override Future<Map<String, dynamic>> getGroups(String pageId) async { try { final raw = await _api.getGroups(pageId); return notionParser(raw); } catch (e, stackTrace) { _logger.error('노션 그룹 정보 조회 실패', e, stackTrace); throw NotionException('그룹 정보를 가져오는데 실패했습니다', e); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/app/modules/groups/data/repositories/rest_notion_repository.dart
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build Android App and Test
- GitHub Check: Build iOS App and Test
lib/app/modules/groups/data/repositories/rest_notion_repository.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
6fea95e
Summary by CodeRabbit