- Replace dart:js with package:js in health_check_service_web.dart\n- Implement showHealthCheckNotification in web/index.html\n- Pin js dependency to ^0.6.7 for flutter_secure_storage_web compatibility auth: harden AuthInterceptor + tests - Allow overrideAuthRepository injection for testing\n- Normalize imports to package: paths\n- Add unit test covering token attach, 401→refresh→retry, and failure path\n- Add integration test skeleton gated by env vars ui/data: map User.companyName to list column - Add companyName to domain User\n- Map UserDto.company?.name\n- Render companyName in user_list cleanup: remove legacy equipment table + unused code; minor warnings - Remove _buildFlexibleTable and unused helpers\n- Remove unused zipcode details and cache retry constant\n- Fix null-aware and non-null assertions\n- Address child-last warnings in administrator dialog docs: update AGENTS.md session context
110 lines
3.7 KiB
Dart
110 lines
3.7 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import '../../../core/errors/failures.dart';
|
|
import '../../../core/utils/hierarchy_validator.dart';
|
|
import '../../repositories/company_repository.dart';
|
|
import '../base_usecase.dart';
|
|
import '../../../data/models/company/company_dto.dart';
|
|
import '../../../models/company_model.dart';
|
|
|
|
/// 회사 삭제 가능 여부 검증 파라미터
|
|
class ValidateCompanyDeletionParams {
|
|
final int companyId;
|
|
|
|
const ValidateCompanyDeletionParams({
|
|
required this.companyId,
|
|
});
|
|
}
|
|
|
|
/// 회사 삭제 가능 여부 검증 결과
|
|
class CompanyDeletionValidationResult {
|
|
final bool canDelete;
|
|
final String message;
|
|
final List<String> blockers;
|
|
|
|
const CompanyDeletionValidationResult({
|
|
required this.canDelete,
|
|
required this.message,
|
|
this.blockers = const [],
|
|
});
|
|
}
|
|
|
|
/// 회사 삭제 가능 여부 검증 UseCase
|
|
class ValidateCompanyDeletionUseCase extends UseCase<CompanyDeletionValidationResult, ValidateCompanyDeletionParams> {
|
|
// 레포지토리 기반으로 마이그레이션
|
|
final CompanyRepository _companyRepository;
|
|
|
|
ValidateCompanyDeletionUseCase(this._companyRepository);
|
|
|
|
@override
|
|
Future<Either<Failure, CompanyDeletionValidationResult>> call(ValidateCompanyDeletionParams params) async {
|
|
try {
|
|
final blockers = <String>[];
|
|
|
|
// 1. 전체 회사(계층 구성용) 조회
|
|
final companiesEither = await _companyRepository.getCompanyHierarchy(includeInactive: true);
|
|
|
|
// CompanyDto 리스트로 변환 (검증용)
|
|
final companyResponses = companiesEither.getOrElse(() => <Company>[]).map((company) => CompanyDto(
|
|
id: company.id ?? 0,
|
|
name: company.name,
|
|
address: company.address.toString(),
|
|
contactName: company.contactName ?? '',
|
|
contactPhone: company.contactPhone ?? '',
|
|
contactEmail: company.contactEmail ?? '',
|
|
isActive: true,
|
|
parentCompanyId: company.parentCompanyId,
|
|
registeredAt: DateTime.now(),
|
|
)).toList();
|
|
|
|
// HierarchyValidator를 사용한 삭제 가능 여부 검증
|
|
final deletionValidation = HierarchyValidator.validateDeletion(
|
|
companyId: params.companyId,
|
|
allCompanies: companyResponses,
|
|
);
|
|
|
|
if (!deletionValidation.isValid) {
|
|
blockers.add(deletionValidation.message);
|
|
blockers.addAll(deletionValidation.errors);
|
|
}
|
|
|
|
// 2. 연결된 사용자 존재 여부 확인
|
|
// TODO: CompanyService에 hasLinkedUsers 메서드 추가 후 활성화
|
|
// final hasUsers = await _companyService.hasLinkedUsers(params.companyId);
|
|
// if (hasUsers) {
|
|
// blockers.add('이 회사에 연결된 사용자가 존재합니다.');
|
|
// }
|
|
|
|
// 3. 연결된 장비 존재 여부 확인
|
|
// TODO: CompanyService에 hasLinkedEquipment 메서드 추가 후 활성화
|
|
// final hasEquipment = await _companyService.hasLinkedEquipment(params.companyId);
|
|
// if (hasEquipment) {
|
|
// blockers.add('이 회사에 연결된 장비가 존재합니다.');
|
|
// }
|
|
|
|
// 결과 생성
|
|
if (blockers.isEmpty) {
|
|
return const Right(CompanyDeletionValidationResult(
|
|
canDelete: true,
|
|
message: '이 회사를 삭제할 수 있습니다.',
|
|
));
|
|
} else {
|
|
return Right(CompanyDeletionValidationResult(
|
|
canDelete: false,
|
|
message: '이 회사를 삭제할 수 없습니다.',
|
|
blockers: blockers,
|
|
));
|
|
}
|
|
} on ServerFailure catch (e) {
|
|
return Left(ServerFailure(
|
|
message: e.message,
|
|
originalError: e,
|
|
));
|
|
} catch (e) {
|
|
return Left(UnknownFailure(
|
|
message: '회사 삭제 가능 여부 검증 중 오류가 발생했습니다.',
|
|
originalError: e,
|
|
));
|
|
}
|
|
}
|
|
}
|