## 주요 변경사항 ### 🏗️ Architecture - Repository 패턴 전면 도입 (인터페이스/구현체 분리) - Domain Layer에 Repository 인터페이스 정의 - Data Layer에 Repository 구현체 배치 - UseCase 의존성을 Service에서 Repository로 전환 ### 📦 Dependency Injection - GetIt 기반 DI Container 재구성 (lib/injection_container.dart) - Repository 인터페이스와 구현체 등록 - Service와 Repository 공존 (마이그레이션 기간) ### 🔄 Migration Status 완료: - License 모듈 (6개 UseCase) - Warehouse Location 모듈 (5개 UseCase) 진행중: - Auth 모듈 (2/5 UseCase) - Company 모듈 (1/6 UseCase) 대기: - User 모듈 (7개 UseCase) - Equipment 모듈 (4개 UseCase) ### 🎯 Controller 통합 - 중복 Controller 제거 (with_usecase 버전) - 단일 Controller로 통합 - UseCase 패턴 직접 적용 ### 🧹 코드 정리 - 임시 파일 제거 (test_*.md, task.md) - Node.js 아티팩트 제거 (package.json) - 불필요한 테스트 파일 정리 ### ✅ 테스트 개선 - Real API 중심 테스트 구조 - Mock 제거, 실제 API 엔드포인트 사용 - 통합 테스트 프레임워크 강화 ## 기술적 영향 - 의존성 역전 원칙 적용 - 레이어 간 결합도 감소 - 테스트 용이성 향상 - 확장성 및 유지보수성 개선 ## 다음 단계 1. User/Equipment 모듈 Repository 마이그레이션 2. Service Layer 점진적 제거 3. 캐싱 전략 구현 4. 성능 최적화
94 lines
2.9 KiB
Dart
94 lines
2.9 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import 'package:dio/dio.dart';
|
|
import '../../repositories/auth_repository.dart';
|
|
import '../../../data/models/auth/login_request.dart';
|
|
import '../../../data/models/auth/login_response.dart';
|
|
import '../../../core/errors/failures.dart';
|
|
import '../base_usecase.dart';
|
|
|
|
/// 로그인 UseCase 파라미터
|
|
class LoginParams {
|
|
final String email;
|
|
final String password;
|
|
|
|
const LoginParams({
|
|
required this.email,
|
|
required this.password,
|
|
});
|
|
}
|
|
|
|
/// 로그인 UseCase
|
|
/// 사용자 인증을 처리하고 토큰을 저장
|
|
class LoginUseCase extends UseCase<LoginResponse, LoginParams> {
|
|
final AuthRepository _authRepository;
|
|
|
|
LoginUseCase(this._authRepository);
|
|
|
|
@override
|
|
Future<Either<Failure, LoginResponse>> call(LoginParams params) async {
|
|
try {
|
|
// 이메일 유효성 검증
|
|
if (!_isValidEmail(params.email)) {
|
|
return Left(ValidationFailure(
|
|
message: '올바른 이메일 형식이 아닙니다.',
|
|
errors: {'email': '올바른 이메일 형식이 아닙니다.'},
|
|
));
|
|
}
|
|
|
|
// 비밀번호 유효성 검증
|
|
if (params.password.isEmpty) {
|
|
return Left(ValidationFailure(
|
|
message: '비밀번호를 입력해주세요.',
|
|
errors: {'password': '비밀번호를 입력해주세요.'},
|
|
));
|
|
}
|
|
|
|
// 로그인 요청
|
|
final loginRequest = LoginRequest(
|
|
email: params.email,
|
|
password: params.password,
|
|
);
|
|
|
|
return await _authRepository.login(loginRequest);
|
|
} on DioException catch (e) {
|
|
if (e.response?.statusCode == 401) {
|
|
return Left(AuthFailure(
|
|
message: '이메일 또는 비밀번호가 올바르지 않습니다.',
|
|
code: 'INVALID_CREDENTIALS',
|
|
originalError: e,
|
|
));
|
|
} else if (e.type == DioExceptionType.connectionTimeout ||
|
|
e.type == DioExceptionType.receiveTimeout) {
|
|
return Left(NetworkFailure(
|
|
message: '네트워크 연결 시간이 초과되었습니다.',
|
|
code: 'TIMEOUT',
|
|
originalError: e,
|
|
));
|
|
} else if (e.type == DioExceptionType.connectionError) {
|
|
return Left(NetworkFailure(
|
|
message: '서버에 연결할 수 없습니다.',
|
|
code: 'CONNECTION_ERROR',
|
|
originalError: e,
|
|
));
|
|
} else {
|
|
return Left(ServerFailure(
|
|
message: e.response?.data['message'] ?? '서버 오류가 발생했습니다.',
|
|
code: e.response?.statusCode?.toString(),
|
|
originalError: e,
|
|
));
|
|
}
|
|
} catch (e) {
|
|
return Left(UnknownFailure(
|
|
message: '알 수 없는 오류가 발생했습니다.',
|
|
originalError: e,
|
|
));
|
|
}
|
|
}
|
|
|
|
bool _isValidEmail(String email) {
|
|
final emailRegex = RegExp(
|
|
r'^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+',
|
|
);
|
|
return emailRegex.hasMatch(email);
|
|
}
|
|
} |