feat: SMS 스캔 화면 리팩토링 및 MVC 패턴 적용
- SMS 스캔 화면을 컨트롤러/서비스/위젯으로 분리 - 코드 가독성 및 유지보수성 향상 - 새로운 다국어 지원 키 추가 - Git 커밋 가이드라인 문서화
This commit is contained in:
79
lib/services/sms_scan/subscription_converter.dart
Normal file
79
lib/services/sms_scan/subscription_converter.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
import '../../models/subscription.dart';
|
||||
import '../../models/subscription_model.dart';
|
||||
|
||||
class SubscriptionConverter {
|
||||
// SubscriptionModel 리스트를 Subscription 리스트로 변환
|
||||
List<Subscription> convertModelsToSubscriptions(List<SubscriptionModel> models) {
|
||||
final result = <Subscription>[];
|
||||
|
||||
for (var model in models) {
|
||||
try {
|
||||
final subscription = _convertSingle(model);
|
||||
result.add(subscription);
|
||||
|
||||
print('모델 변환 성공: ${model.serviceName}, 카테고리ID: ${model.categoryId}, URL: ${model.websiteUrl}, 통화: ${model.currency}');
|
||||
} catch (e) {
|
||||
print('모델 변환 중 오류 발생: $e');
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 단일 모델 변환
|
||||
Subscription _convertSingle(SubscriptionModel model) {
|
||||
return Subscription(
|
||||
id: model.id,
|
||||
serviceName: model.serviceName,
|
||||
monthlyCost: model.monthlyCost,
|
||||
billingCycle: _denormalizeBillingCycle(model.billingCycle), // 영어 -> 한국어
|
||||
nextBillingDate: model.nextBillingDate,
|
||||
category: model.categoryId, // categoryId를 category로 매핑
|
||||
repeatCount: model.repeatCount > 0 ? model.repeatCount : 1,
|
||||
lastPaymentDate: model.lastPaymentDate,
|
||||
websiteUrl: model.websiteUrl,
|
||||
currency: model.currency,
|
||||
);
|
||||
}
|
||||
|
||||
// billingCycle 역정규화 (영어 -> 한국어)
|
||||
String _denormalizeBillingCycle(String cycle) {
|
||||
switch (cycle.toLowerCase()) {
|
||||
case 'monthly':
|
||||
return '월간';
|
||||
case 'yearly':
|
||||
case 'annually':
|
||||
return '연간';
|
||||
case 'weekly':
|
||||
return '주간';
|
||||
case 'daily':
|
||||
return '일간';
|
||||
case 'quarterly':
|
||||
return '분기별';
|
||||
case 'semi-annually':
|
||||
return '반기별';
|
||||
default:
|
||||
return cycle; // 알 수 없는 형식은 그대로 반환
|
||||
}
|
||||
}
|
||||
|
||||
// billingCycle 정규화 (한국어 -> 영어)
|
||||
String normalizeBillingCycle(String cycle) {
|
||||
switch (cycle) {
|
||||
case '월간':
|
||||
return 'monthly';
|
||||
case '연간':
|
||||
return 'yearly';
|
||||
case '주간':
|
||||
return 'weekly';
|
||||
case '일간':
|
||||
return 'daily';
|
||||
case '분기별':
|
||||
return 'quarterly';
|
||||
case '반기별':
|
||||
return 'semi-annually';
|
||||
default:
|
||||
return 'monthly'; // 기본값
|
||||
}
|
||||
}
|
||||
}
|
||||
60
lib/services/sms_scan/subscription_filter.dart
Normal file
60
lib/services/sms_scan/subscription_filter.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import '../../models/subscription.dart';
|
||||
import '../../models/subscription_model.dart';
|
||||
|
||||
class SubscriptionFilter {
|
||||
// 중복 구독 필터링 (서비스명과 금액이 같으면 중복으로 간주)
|
||||
List<Subscription> filterDuplicates(
|
||||
List<Subscription> scanned, List<SubscriptionModel> existing) {
|
||||
print('_filterDuplicates: 스캔된 구독 ${scanned.length}개, 기존 구독 ${existing.length}개');
|
||||
|
||||
// 중복되지 않은 구독만 필터링
|
||||
return scanned.where((scannedSub) {
|
||||
// 기존 구독 중에 같은 서비스명과 월 비용을 가진 것이 있는지 확인
|
||||
final isDuplicate = existing.any((existingSub) {
|
||||
final isSameName = existingSub.serviceName.toLowerCase() ==
|
||||
scannedSub.serviceName.toLowerCase();
|
||||
final isSameCost = existingSub.monthlyCost == scannedSub.monthlyCost;
|
||||
|
||||
if (isSameName && isSameCost) {
|
||||
print('중복 발견: ${scannedSub.serviceName} (${scannedSub.monthlyCost}원)');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return !isDuplicate;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// 반복 횟수 기반 필터링
|
||||
List<Subscription> filterByRepeatCount(List<Subscription> subscriptions, int minCount) {
|
||||
return subscriptions.where((sub) => sub.repeatCount >= minCount).toList();
|
||||
}
|
||||
|
||||
// 날짜 기반 필터링 (선택적)
|
||||
List<Subscription> filterByDateRange(
|
||||
List<Subscription> subscriptions, DateTime startDate, DateTime endDate) {
|
||||
return subscriptions.where((sub) {
|
||||
return sub.nextBillingDate.isAfter(startDate) &&
|
||||
sub.nextBillingDate.isBefore(endDate);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// 금액 기반 필터링 (선택적)
|
||||
List<Subscription> filterByPriceRange(
|
||||
List<Subscription> subscriptions, double minPrice, double maxPrice) {
|
||||
return subscriptions
|
||||
.where((sub) => sub.monthlyCost >= minPrice && sub.monthlyCost <= maxPrice)
|
||||
.toList();
|
||||
}
|
||||
|
||||
// 카테고리 기반 필터링 (선택적)
|
||||
List<Subscription> filterByCategories(
|
||||
List<Subscription> subscriptions, List<String> categoryIds) {
|
||||
if (categoryIds.isEmpty) return subscriptions;
|
||||
|
||||
return subscriptions.where((sub) {
|
||||
return sub.category != null && categoryIds.contains(sub.category);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user