refactor: Clean Architecture 적용 및 코드베이스 전면 리팩토링
## 주요 변경사항 ### 아키텍처 개선 - Clean Architecture 패턴 적용 (Domain, Data, Presentation 레이어 분리) - Use Case 패턴 도입으로 비즈니스 로직 캡슐화 - Repository 패턴으로 데이터 접근 추상화 - 의존성 주입 구조 개선 ### 상태 관리 최적화 - 모든 Controller에서 불필요한 상태 관리 로직 제거 - 페이지네이션 로직 통일 및 간소화 - 에러 처리 로직 개선 (에러 메시지 한글화) - 로딩 상태 관리 최적화 ### Mock 서비스 제거 - MockDataService 완전 제거 - 모든 화면을 실제 API 전용으로 전환 - 불필요한 Mock 관련 코드 정리 ### UI/UX 개선 - Overview 화면 대시보드 기능 강화 - 라이선스 만료 알림 위젯 추가 - 사이드바 네비게이션 개선 - 일관된 UI 컴포넌트 사용 ### 코드 품질 - 중복 코드 제거 및 함수 추출 - 파일별 책임 분리 명확화 - 테스트 코드 업데이트 ## 영향 범위 - 모든 화면의 Controller 리팩토링 - API 통신 레이어 구조 개선 - 에러 처리 및 로깅 시스템 개선 ## 향후 계획 - 단위 테스트 커버리지 확대 - 통합 테스트 시나리오 추가 - 성능 모니터링 도구 통합
This commit is contained in:
7
lib/domain/usecases/company/company_usecases.dart
Normal file
7
lib/domain/usecases/company/company_usecases.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
/// Company 도메인 UseCase 모음
|
||||
export 'get_companies_usecase.dart';
|
||||
export 'create_company_usecase.dart';
|
||||
export 'update_company_usecase.dart';
|
||||
export 'delete_company_usecase.dart';
|
||||
export 'get_company_detail_usecase.dart';
|
||||
export 'toggle_company_status_usecase.dart';
|
||||
84
lib/domain/usecases/company/create_company_usecase.dart
Normal file
84
lib/domain/usecases/company/create_company_usecase.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/company_service.dart';
|
||||
import '../../../models/company_model.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 회사 생성 파라미터
|
||||
class CreateCompanyParams {
|
||||
final Company company;
|
||||
|
||||
const CreateCompanyParams({
|
||||
required this.company,
|
||||
});
|
||||
}
|
||||
|
||||
/// 회사 생성 UseCase
|
||||
class CreateCompanyUseCase extends UseCase<Company, CreateCompanyParams> {
|
||||
final CompanyService _companyService;
|
||||
|
||||
CreateCompanyUseCase(this._companyService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Company>> call(CreateCompanyParams params) async {
|
||||
try {
|
||||
// 유효성 검증
|
||||
final validationResult = _validateCompany(params.company);
|
||||
if (validationResult != null) {
|
||||
return Left(validationResult);
|
||||
}
|
||||
|
||||
final company = await _companyService.createCompany(params.company);
|
||||
return Right(company);
|
||||
} on ServerFailure catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: e.message,
|
||||
originalError: e,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(
|
||||
message: '회사 생성 중 오류가 발생했습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
ValidationFailure? _validateCompany(Company company) {
|
||||
final errors = <String, String>{};
|
||||
|
||||
if (company.name.isEmpty) {
|
||||
errors['name'] = '회사명을 입력해주세요.';
|
||||
}
|
||||
|
||||
if (company.address.isEmpty) {
|
||||
errors['address'] = '주소를 입력해주세요.';
|
||||
}
|
||||
|
||||
if (company.companyTypes.isEmpty) {
|
||||
errors['companyTypes'] = '회사 유형을 선택해주세요.';
|
||||
}
|
||||
|
||||
if (company.contactEmail != null && company.contactEmail!.isNotEmpty) {
|
||||
final emailRegex = RegExp(r'^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+');
|
||||
if (!emailRegex.hasMatch(company.contactEmail!)) {
|
||||
errors['contactEmail'] = '올바른 이메일 형식이 아닙니다.';
|
||||
}
|
||||
}
|
||||
|
||||
if (company.contactPhone != null && company.contactPhone!.isNotEmpty) {
|
||||
final phoneRegex = RegExp(r'^01[0-9]{1}-?[0-9]{4}-?[0-9]{4}$');
|
||||
if (!phoneRegex.hasMatch(company.contactPhone!)) {
|
||||
errors['contactPhone'] = '올바른 전화번호 형식이 아닙니다.';
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.isNotEmpty) {
|
||||
return ValidationFailure(
|
||||
message: '입력값을 확인해주세요.',
|
||||
errors: errors,
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
44
lib/domain/usecases/company/delete_company_usecase.dart
Normal file
44
lib/domain/usecases/company/delete_company_usecase.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/company_service.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 회사 삭제 파라미터
|
||||
class DeleteCompanyParams {
|
||||
final int id;
|
||||
|
||||
const DeleteCompanyParams({
|
||||
required this.id,
|
||||
});
|
||||
}
|
||||
|
||||
/// 회사 삭제 UseCase
|
||||
class DeleteCompanyUseCase extends UseCase<void, DeleteCompanyParams> {
|
||||
final CompanyService _companyService;
|
||||
|
||||
DeleteCompanyUseCase(this._companyService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, void>> call(DeleteCompanyParams params) async {
|
||||
try {
|
||||
await _companyService.deleteCompany(params.id);
|
||||
return const Right(null);
|
||||
} on ServerFailure catch (e) {
|
||||
if (e.message.contains('associated')) {
|
||||
return Left(ValidationFailure(
|
||||
message: '연관된 데이터가 있어 삭제할 수 없습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
return Left(ServerFailure(
|
||||
message: e.message,
|
||||
originalError: e,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(
|
||||
message: '회사 삭제 중 오류가 발생했습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
51
lib/domain/usecases/company/get_companies_usecase.dart
Normal file
51
lib/domain/usecases/company/get_companies_usecase.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/company_service.dart';
|
||||
import '../../../models/company_model.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 회사 목록 조회 파라미터
|
||||
class GetCompaniesParams {
|
||||
final int page;
|
||||
final int perPage;
|
||||
final String? search;
|
||||
final bool? isActive;
|
||||
|
||||
const GetCompaniesParams({
|
||||
this.page = 1,
|
||||
this.perPage = 20,
|
||||
this.search,
|
||||
this.isActive,
|
||||
});
|
||||
}
|
||||
|
||||
/// 회사 목록 조회 UseCase
|
||||
class GetCompaniesUseCase extends UseCase<List<Company>, GetCompaniesParams> {
|
||||
final CompanyService _companyService;
|
||||
|
||||
GetCompaniesUseCase(this._companyService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Company>>> call(GetCompaniesParams params) async {
|
||||
try {
|
||||
final companies = await _companyService.getCompanies(
|
||||
page: params.page,
|
||||
perPage: params.perPage,
|
||||
search: params.search,
|
||||
isActive: params.isActive,
|
||||
);
|
||||
|
||||
return Right(companies);
|
||||
} on ServerFailure catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: e.message,
|
||||
originalError: e,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(
|
||||
message: '회사 목록을 불러오는 중 오류가 발생했습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
55
lib/domain/usecases/company/get_company_detail_usecase.dart
Normal file
55
lib/domain/usecases/company/get_company_detail_usecase.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/company_service.dart';
|
||||
import '../../../models/company_model.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 회사 상세 조회 파라미터
|
||||
class GetCompanyDetailParams {
|
||||
final int id;
|
||||
final bool includeBranches;
|
||||
|
||||
const GetCompanyDetailParams({
|
||||
required this.id,
|
||||
this.includeBranches = false,
|
||||
});
|
||||
}
|
||||
|
||||
/// 회사 상세 조회 UseCase
|
||||
class GetCompanyDetailUseCase extends UseCase<Company, GetCompanyDetailParams> {
|
||||
final CompanyService _companyService;
|
||||
|
||||
GetCompanyDetailUseCase(this._companyService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Company>> call(GetCompanyDetailParams params) async {
|
||||
try {
|
||||
final Company company;
|
||||
|
||||
if (params.includeBranches) {
|
||||
company = await _companyService.getCompanyWithBranches(params.id);
|
||||
} else {
|
||||
company = await _companyService.getCompanyDetail(params.id);
|
||||
}
|
||||
|
||||
return Right(company);
|
||||
} on ServerFailure catch (e) {
|
||||
if (e.message.contains('not found')) {
|
||||
return Left(ValidationFailure(
|
||||
message: '회사를 찾을 수 없습니다.',
|
||||
code: 'NOT_FOUND',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
return Left(ServerFailure(
|
||||
message: e.message,
|
||||
originalError: e,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(
|
||||
message: '회사 정보를 불러오는 중 오류가 발생했습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/company_service.dart';
|
||||
import '../../../models/company_model.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 회사 상태 토글 파라미터
|
||||
class ToggleCompanyStatusParams {
|
||||
final int id;
|
||||
final bool isActive;
|
||||
|
||||
const ToggleCompanyStatusParams({
|
||||
required this.id,
|
||||
required this.isActive,
|
||||
});
|
||||
}
|
||||
|
||||
/// 회사 활성화/비활성화 UseCase
|
||||
class ToggleCompanyStatusUseCase extends UseCase<void, ToggleCompanyStatusParams> {
|
||||
final CompanyService _companyService;
|
||||
|
||||
ToggleCompanyStatusUseCase(this._companyService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, void>> call(ToggleCompanyStatusParams params) async {
|
||||
try {
|
||||
await _companyService.updateCompanyStatus(params.id, params.isActive);
|
||||
return const Right(null);
|
||||
} on ServerFailure catch (e) {
|
||||
if (e.message.contains('equipment')) {
|
||||
return Left(ValidationFailure(
|
||||
message: '활성 장비가 있는 회사는 비활성화할 수 없습니다.',
|
||||
code: 'HAS_ACTIVE_EQUIPMENT',
|
||||
));
|
||||
}
|
||||
return Left(ServerFailure(
|
||||
message: e.message,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '회사 상태 변경 중 오류가 발생했습니다.',
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
86
lib/domain/usecases/company/update_company_usecase.dart
Normal file
86
lib/domain/usecases/company/update_company_usecase.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import '../../../services/company_service.dart';
|
||||
import '../../../models/company_model.dart';
|
||||
import '../../../core/errors/failures.dart';
|
||||
import '../base_usecase.dart';
|
||||
|
||||
/// 회사 수정 파라미터
|
||||
class UpdateCompanyParams {
|
||||
final int id;
|
||||
final Company company;
|
||||
|
||||
const UpdateCompanyParams({
|
||||
required this.id,
|
||||
required this.company,
|
||||
});
|
||||
}
|
||||
|
||||
/// 회사 수정 UseCase
|
||||
class UpdateCompanyUseCase extends UseCase<Company, UpdateCompanyParams> {
|
||||
final CompanyService _companyService;
|
||||
|
||||
UpdateCompanyUseCase(this._companyService);
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Company>> call(UpdateCompanyParams params) async {
|
||||
try {
|
||||
// 유효성 검증
|
||||
final validationResult = _validateCompany(params.company);
|
||||
if (validationResult != null) {
|
||||
return Left(validationResult);
|
||||
}
|
||||
|
||||
final company = await _companyService.updateCompany(params.id, params.company);
|
||||
return Right(company);
|
||||
} on ServerFailure catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: e.message,
|
||||
originalError: e,
|
||||
));
|
||||
} catch (e) {
|
||||
return Left(UnknownFailure(
|
||||
message: '회사 정보 수정 중 오류가 발생했습니다.',
|
||||
originalError: e,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
ValidationFailure? _validateCompany(Company company) {
|
||||
final errors = <String, String>{};
|
||||
|
||||
if (company.name.isEmpty) {
|
||||
errors['name'] = '회사명을 입력해주세요.';
|
||||
}
|
||||
|
||||
if (company.address.isEmpty) {
|
||||
errors['address'] = '주소를 입력해주세요.';
|
||||
}
|
||||
|
||||
if (company.companyTypes.isEmpty) {
|
||||
errors['companyTypes'] = '회사 유형을 선택해주세요.';
|
||||
}
|
||||
|
||||
if (company.contactEmail != null && company.contactEmail!.isNotEmpty) {
|
||||
final emailRegex = RegExp(r'^[a-zA-Z0-9.]+@[a-zA-Z0-9]+\.[a-zA-Z]+');
|
||||
if (!emailRegex.hasMatch(company.contactEmail!)) {
|
||||
errors['contactEmail'] = '올바른 이메일 형식이 아닙니다.';
|
||||
}
|
||||
}
|
||||
|
||||
if (company.contactPhone != null && company.contactPhone!.isNotEmpty) {
|
||||
final phoneRegex = RegExp(r'^01[0-9]{1}-?[0-9]{4}-?[0-9]{4}$');
|
||||
if (!phoneRegex.hasMatch(company.contactPhone!)) {
|
||||
errors['contactPhone'] = '올바른 전화번호 형식이 아닙니다.';
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.isNotEmpty) {
|
||||
return ValidationFailure(
|
||||
message: '입력값을 확인해주세요.',
|
||||
errors: errors,
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user