사용하지 않는 파일 정리 전 백업 (Phase 10 완료 후 상태)
This commit is contained in:
@@ -327,41 +327,27 @@ class CompanyRepositoryImpl implements CompanyRepository {
|
||||
name: dto.company.name,
|
||||
address: Address.fromFullAddress(dto.company.address ?? ''),
|
||||
contactName: dto.company.contactName,
|
||||
contactPosition: dto.company.contactPosition,
|
||||
contactPosition: null, // 백엔드에서 미지원
|
||||
contactPhone: dto.company.contactPhone,
|
||||
contactEmail: dto.company.contactEmail,
|
||||
companyTypes: _parseCompanyTypes(dto.company.companyTypes),
|
||||
companyTypes: [], // 백엔드에서 미지원
|
||||
remark: dto.company.remark,
|
||||
branches: [], // TODO: 계층형 구조로 변경됨. children은 자회사를 의미하므로 branches는 빈 리스트로 설정
|
||||
);
|
||||
}
|
||||
|
||||
Company _mapResponseToDomain(CompanyResponse response) {
|
||||
Company _mapResponseToDomain(CompanyDto response) {
|
||||
return Company(
|
||||
id: response.id,
|
||||
name: response.name,
|
||||
address: Address.fromFullAddress(response.address ?? ''),
|
||||
contactName: response.contactName,
|
||||
contactPosition: response.contactPosition,
|
||||
contactPosition: null, // 백엔드에서 미지원
|
||||
contactPhone: response.contactPhone,
|
||||
contactEmail: response.contactEmail,
|
||||
companyTypes: _parseCompanyTypes(response.companyTypes),
|
||||
companyTypes: [], // 백엔드에서 미지원
|
||||
remark: response.remark,
|
||||
branches: [], // CompanyResponse에서는 지점 정보 따로 조회
|
||||
);
|
||||
}
|
||||
|
||||
Branch _mapBranchDtoToDomain(BranchListDto dto) {
|
||||
return Branch(
|
||||
id: dto.id,
|
||||
companyId: dto.companyId,
|
||||
name: dto.branchName,
|
||||
address: Address.fromFullAddress(dto.address ?? ''),
|
||||
contactName: dto.managerName,
|
||||
contactPosition: null, // BranchListDto에 없음
|
||||
contactPhone: dto.phone,
|
||||
contactEmail: null, // BranchListDto에 없음
|
||||
remark: null, // BranchListDto에 없음
|
||||
branches: [], // CompanyDto에서는 지점 정보 따로 조회
|
||||
);
|
||||
}
|
||||
|
||||
@@ -395,40 +381,27 @@ class CompanyRepositoryImpl implements CompanyRepository {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// CompanyType enum을 API 문자열로 변환
|
||||
String _mapCompanyTypeToApiString(CompanyType type) {
|
||||
switch (type) {
|
||||
case CompanyType.partner:
|
||||
return 'partner';
|
||||
case CompanyType.customer:
|
||||
return 'customer';
|
||||
}
|
||||
}
|
||||
|
||||
CreateCompanyRequest _mapDomainToCreateRequest(Company company) {
|
||||
return CreateCompanyRequest(
|
||||
CompanyRequestDto _mapDomainToCreateRequest(Company company) {
|
||||
return CompanyRequestDto(
|
||||
name: company.name,
|
||||
address: company.address.toString(),
|
||||
contactName: company.contactName ?? '',
|
||||
contactPosition: company.contactPosition ?? '',
|
||||
contactPhone: company.contactPhone ?? '',
|
||||
contactEmail: company.contactEmail ?? '',
|
||||
companyTypes: company.companyTypes.map((type) => _mapCompanyTypeToApiString(type)).toList(),
|
||||
remark: company.remark,
|
||||
);
|
||||
}
|
||||
|
||||
UpdateCompanyRequest _mapDomainToUpdateRequest(Company company) {
|
||||
return UpdateCompanyRequest(
|
||||
CompanyUpdateRequestDto _mapDomainToUpdateRequest(Company company) {
|
||||
return CompanyUpdateRequestDto(
|
||||
name: company.name,
|
||||
address: company.address.toString(),
|
||||
contactName: company.contactName,
|
||||
contactPosition: company.contactPosition,
|
||||
contactPhone: company.contactPhone,
|
||||
contactEmail: company.contactEmail,
|
||||
companyTypes: company.companyTypes.map((type) => _mapCompanyTypeToApiString(type)).toList(),
|
||||
remark: company.remark,
|
||||
isActive: null, // UpdateCompanyRequest에서 필요한 경우 추가
|
||||
isActive: null, // CompanyUpdateRequestDto에서 필요한 경우 추가
|
||||
);
|
||||
}
|
||||
|
||||
@@ -453,4 +426,178 @@ class CompanyRepositoryImpl implements CompanyRepository {
|
||||
remark: branch.remark,
|
||||
);
|
||||
}
|
||||
|
||||
// 계층 구조 관련 메서드 구현
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Company>>> getCompanyHierarchy({
|
||||
bool includeInactive = false,
|
||||
}) async {
|
||||
try {
|
||||
// 모든 회사 조회
|
||||
final result = await remoteDataSource.getCompanies(
|
||||
page: 1,
|
||||
perPage: 1000, // 전체 회사 조회를 위한 큰 수
|
||||
isActive: includeInactive ? null : true,
|
||||
);
|
||||
|
||||
// DTO를 도메인 모델로 변환
|
||||
final companies = result.items.map((dto) => _mapDtoToDomain(dto)).toList();
|
||||
|
||||
// 계층 구조로 재구성 (클라이언트에서 처리)
|
||||
// 실제 API가 계층 구조를 반환하면 이 부분 수정 필요
|
||||
|
||||
return Right(companies);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '회사 계층 구조 조회 중 오류가 발생했습니다: ${e.toString()}',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Company>>> getChildrenCompanies(
|
||||
int companyId, {
|
||||
bool recursive = false,
|
||||
}) async {
|
||||
try {
|
||||
// API에서 자식 회사 조회
|
||||
// 현재는 getCompanyWithChildren 사용
|
||||
final result = await remoteDataSource.getCompanyWithChildren(companyId);
|
||||
|
||||
final children = <Company>[];
|
||||
for (final childDto in result.children) {
|
||||
final child = _mapResponseToDomain(childDto);
|
||||
children.add(child);
|
||||
|
||||
// 재귀적으로 모든 자손 포함
|
||||
if (recursive && childDto.id != null && childDto.id != companyId) {
|
||||
final grandChildrenResult = await getChildrenCompanies(childDto.id!, recursive: true);
|
||||
grandChildrenResult.fold(
|
||||
(failure) {}, // 에러 무시하고 진행
|
||||
(grandChildren) => children.addAll(grandChildren),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return Right(children);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '자식 회사 조회 중 오류가 발생했습니다: ${e.toString()}',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Company>>> getAncestorPath(int companyId) async {
|
||||
try {
|
||||
final path = <Company>[];
|
||||
int? currentId = companyId;
|
||||
|
||||
while (currentId != null) {
|
||||
final companyResult = await getCompanyById(currentId);
|
||||
|
||||
final company = companyResult.fold(
|
||||
(failure) => null,
|
||||
(company) => company,
|
||||
);
|
||||
|
||||
if (company == null) break;
|
||||
|
||||
path.insert(0, company); // 루트부터 시작하도록 앞에 삽입
|
||||
|
||||
// parent_company_id를 찾기 위해 API 호출 필요
|
||||
// 현재 CompanyDto에 parentCompanyId가 있으므로 사용
|
||||
final detailResult = await remoteDataSource.getCompanyWithChildren(currentId);
|
||||
currentId = detailResult.company.parentCompanyId;
|
||||
}
|
||||
|
||||
return Right(path);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '부모 경로 조회 중 오류가 발생했습니다: ${e.toString()}',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, Company>> updateParentCompany(
|
||||
int companyId,
|
||||
int? newParentId,
|
||||
) async {
|
||||
try {
|
||||
// 먼저 현재 회사 정보 조회
|
||||
final currentResult = await getCompanyById(companyId);
|
||||
|
||||
return currentResult.fold(
|
||||
(failure) => Left(failure),
|
||||
(company) async {
|
||||
// 부모 회사 ID만 업데이트
|
||||
final updateRequest = CompanyUpdateRequestDto(
|
||||
parentCompanyId: newParentId,
|
||||
);
|
||||
|
||||
final result = await remoteDataSource.updateCompany(companyId, updateRequest);
|
||||
final updatedCompany = _mapResponseToDomain(result);
|
||||
return Right(updatedCompany);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '부모 회사 변경 중 오류가 발생했습니다: ${e.toString()}',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> hasChildrenCompanies(int companyId) async {
|
||||
try {
|
||||
final childrenResult = await getChildrenCompanies(companyId, recursive: false);
|
||||
|
||||
return childrenResult.fold(
|
||||
(failure) => Left(failure),
|
||||
(children) => Right(children.isNotEmpty),
|
||||
);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '자식 회사 존재 여부 확인 중 오류가 발생했습니다: ${e.toString()}',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, bool>> validateHierarchyChange(
|
||||
int companyId,
|
||||
int? newParentId,
|
||||
) async {
|
||||
try {
|
||||
if (newParentId == null) {
|
||||
// 루트로 변경하는 경우는 항상 유효
|
||||
return const Right(true);
|
||||
}
|
||||
|
||||
// 자기 자신을 부모로 설정하려는 경우
|
||||
if (companyId == newParentId) {
|
||||
return const Right(false);
|
||||
}
|
||||
|
||||
// 자손을 부모로 설정하려는 경우 검증
|
||||
final descendantsResult = await getChildrenCompanies(companyId, recursive: true);
|
||||
|
||||
return descendantsResult.fold(
|
||||
(failure) => Left(failure),
|
||||
(descendants) {
|
||||
final descendantIds = descendants.map((c) => c.id).toList();
|
||||
if (descendantIds.contains(newParentId)) {
|
||||
return const Right(false);
|
||||
}
|
||||
return const Right(true);
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
return Left(ServerFailure(
|
||||
message: '계층 구조 유효성 검증 중 오류가 발생했습니다: ${e.toString()}',
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user