- 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
86 lines
2.4 KiB
Dart
86 lines
2.4 KiB
Dart
import 'package:dartz/dartz.dart';
|
|
import '../../repositories/company_repository.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 CompanyRepository _companyRepository;
|
|
|
|
CreateCompanyUseCase(this._companyRepository);
|
|
|
|
@override
|
|
Future<Either<Failure, Company>> call(CreateCompanyParams params) async {
|
|
try {
|
|
// 유효성 검증
|
|
final validationResult = _validateCompany(params.company);
|
|
if (validationResult != null) {
|
|
return Left(validationResult);
|
|
}
|
|
|
|
final result = await _companyRepository.createCompany(params.company);
|
|
return result;
|
|
} 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;
|
|
}
|
|
}
|