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'; // 기본값
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user