feat: 사용자 관리 API 연동 구현

- UserRemoteDataSource: 사용자 CRUD, 상태 변경, 비밀번호 변경, 중복 확인 API 구현
- UserService: DTO-Model 변환 로직 및 역할/전화번호 매핑 처리
- UserListController: ChangeNotifier 패턴 적용, 페이지네이션, 검색, 필터링 기능 추가
- UserFormController: API 연동, username 중복 확인 기능 추가
- user_form.dart: username/password 필드 추가 및 실시간 검증
- user_list_redesign.dart: Provider 패턴 적용, 무한 스크롤 구현
- equipment_out_form_controller.dart: 구문 오류 수정
- API 통합 진행률: 85% (사용자 관리 100% 완료)
This commit is contained in:
JiWoong Sul
2025-07-24 19:37:58 +09:00
parent 7f491afa4f
commit 553f605e8b
15 changed files with 3808 additions and 543 deletions

View File

@@ -1,4 +1,5 @@
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
import 'package:superport/core/errors/exceptions.dart';
import 'package:superport/core/errors/failures.dart';
import 'package:superport/data/datasources/remote/company_remote_datasource.dart';
@@ -8,8 +9,11 @@ import 'package:superport/data/models/company/branch_dto.dart';
import 'package:superport/models/company_model.dart';
import 'package:superport/models/address_model.dart';
@lazySingleton
class CompanyService {
final CompanyRemoteDataSource _remoteDataSource = GetIt.instance<CompanyRemoteDataSource>();
final CompanyRemoteDataSource _remoteDataSource;
CompanyService(this._remoteDataSource);
// 회사 목록 조회
Future<List<Company>> getCompanies({
@@ -19,15 +23,15 @@ class CompanyService {
bool? isActive,
}) async {
try {
final dtoList = await _remoteDataSource.getCompanies(
final response = await _remoteDataSource.getCompanies(
page: page,
perPage: perPage,
search: search,
isActive: isActive,
);
return dtoList.map((dto) => _convertListDtoToCompany(dto)).toList();
} on ServerException catch (e) {
return response.items.map((dto) => _convertListDtoToCompany(dto)).toList();
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to fetch company list: $e');
@@ -50,7 +54,7 @@ class CompanyService {
final response = await _remoteDataSource.createCompany(request);
return _convertResponseToCompany(response);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to create company: $e');
@@ -62,7 +66,7 @@ class CompanyService {
try {
final response = await _remoteDataSource.getCompanyDetail(id);
return _convertResponseToCompany(response);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to fetch company detail: $e');
@@ -77,7 +81,7 @@ class CompanyService {
final branches = response.branches.map((dto) => _convertBranchDtoToBranch(dto)).toList();
return company.copyWith(branches: branches);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to fetch company with branches: $e');
@@ -100,7 +104,7 @@ class CompanyService {
final response = await _remoteDataSource.updateCompany(id, request);
return _convertResponseToCompany(response);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to update company: $e');
@@ -111,7 +115,7 @@ class CompanyService {
Future<void> deleteCompany(int id) async {
try {
await _remoteDataSource.deleteCompany(id);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to delete company: $e');
@@ -126,7 +130,7 @@ class CompanyService {
'id': dto.id,
'name': dto.name,
}).toList();
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to fetch company names: $e');
@@ -147,7 +151,7 @@ class CompanyService {
final response = await _remoteDataSource.createBranch(companyId, request);
return _convertBranchResponseToBranch(response);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to create branch: $e');
@@ -158,7 +162,7 @@ class CompanyService {
try {
final response = await _remoteDataSource.getBranchDetail(companyId, branchId);
return _convertBranchResponseToBranch(response);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to fetch branch detail: $e');
@@ -178,7 +182,7 @@ class CompanyService {
final response = await _remoteDataSource.updateBranch(companyId, branchId, request);
return _convertBranchResponseToBranch(response);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to update branch: $e');
@@ -188,7 +192,7 @@ class CompanyService {
Future<void> deleteBranch(int companyId, int branchId) async {
try {
await _remoteDataSource.deleteBranch(companyId, branchId);
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to delete branch: $e');
@@ -199,13 +203,58 @@ class CompanyService {
try {
final dtoList = await _remoteDataSource.getCompanyBranches(companyId);
return dtoList.map((dto) => _convertBranchDtoToBranch(dto)).toList();
} on ServerException catch (e) {
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to fetch company branches: $e');
}
}
// 회사-지점 전체 정보 조회
Future<List<CompanyWithBranches>> getCompaniesWithBranches() async {
try {
return await _remoteDataSource.getCompaniesWithBranches();
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to fetch companies with branches: $e');
}
}
// 회사명 중복 확인
Future<bool> checkDuplicateCompany(String name) async {
try {
return await _remoteDataSource.checkDuplicateCompany(name);
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to check duplicate: $e');
}
}
// 회사 검색
Future<List<Company>> searchCompanies(String query) async {
try {
final dtoList = await _remoteDataSource.searchCompanies(query);
return dtoList.map((dto) => _convertListDtoToCompany(dto)).toList();
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to search companies: $e');
}
}
// 회사 활성 상태 변경
Future<void> updateCompanyStatus(int id, bool isActive) async {
try {
await _remoteDataSource.updateCompanyStatus(id, isActive);
} on ApiException catch (e) {
throw Failure(message: e.message);
} catch (e) {
throw Failure(message: 'Failed to update company status: $e');
}
}
// 변환 헬퍼 메서드들
Company _convertListDtoToCompany(CompanyListDto dto) {
return Company(