- 전체 371개 파일 중 82개 미사용 파일 식별 - Phase 1: 33개 파일 삭제 예정 (100% 안전) - Phase 2: 30개 파일 삭제 검토 예정 - Phase 3: 19개 파일 수동 검토 예정 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
194 lines
5.7 KiB
Dart
194 lines
5.7 KiB
Dart
import 'package:injectable/injectable.dart';
|
|
import 'package:superport/core/constants/app_constants.dart';
|
|
import 'package:superport/data/datasources/remote/user_remote_datasource.dart';
|
|
import 'package:superport/data/models/common/paginated_response.dart';
|
|
import 'package:superport/data/models/user/user_dto.dart';
|
|
import 'package:superport/models/user_model.dart';
|
|
|
|
@lazySingleton
|
|
class UserService {
|
|
final UserRemoteDataSource _userRemoteDataSource;
|
|
|
|
UserService(this._userRemoteDataSource);
|
|
|
|
/// 사용자 목록 조회 (레거시 메서드 - 사용 중단됨)
|
|
Future<PaginatedResponse<User>> getUsers({
|
|
int page = 1,
|
|
int perPage = AppConstants.userPageSize,
|
|
bool? isActive,
|
|
int? companyId,
|
|
String? role,
|
|
bool includeInactive = false,
|
|
}) async {
|
|
try {
|
|
final response = await _userRemoteDataSource.getUsers(
|
|
page: page,
|
|
perPage: perPage,
|
|
isActive: isActive,
|
|
role: role,
|
|
);
|
|
|
|
return PaginatedResponse<User>(
|
|
items: response.items.map((dto) => _userDtoToModel(dto)).toList(),
|
|
page: response.currentPage,
|
|
size: response.pageSize ?? AppConstants.userPageSize,
|
|
totalElements: response.totalCount,
|
|
totalPages: response.totalPages,
|
|
first: response.currentPage == 1,
|
|
last: response.currentPage >= response.totalPages,
|
|
);
|
|
} catch (e) {
|
|
throw Exception('사용자 목록 조회 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 특정 사용자 조회
|
|
Future<User> getUser(int id) async {
|
|
try {
|
|
final dto = await _userRemoteDataSource.getUser(id);
|
|
return _userDtoToModel(dto);
|
|
} catch (e) {
|
|
throw Exception('사용자 조회 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 사용자 생성
|
|
Future<User> createUser({
|
|
required String username,
|
|
required String email,
|
|
required String password,
|
|
required String name,
|
|
required String role,
|
|
required int companyId,
|
|
int? branchId,
|
|
String? phone,
|
|
String? position,
|
|
}) async {
|
|
try {
|
|
final request = UserRequestDto(
|
|
name: name,
|
|
email: email,
|
|
phone: phone,
|
|
companiesId: companyId,
|
|
);
|
|
|
|
final dto = await _userRemoteDataSource.createUser(request);
|
|
return _userDtoToModel(dto);
|
|
} catch (e) {
|
|
throw Exception('사용자 생성 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 사용자 정보 수정
|
|
Future<User> updateUser(
|
|
int id, {
|
|
String? name,
|
|
String? email,
|
|
String? password,
|
|
String? phone,
|
|
int? companyId,
|
|
int? branchId,
|
|
String? role,
|
|
String? position,
|
|
}) async {
|
|
try {
|
|
final request = UserUpdateRequestDto(
|
|
name: name,
|
|
email: email,
|
|
phone: phone,
|
|
companiesId: companyId,
|
|
);
|
|
|
|
final dto = await _userRemoteDataSource.updateUser(id, request);
|
|
return _userDtoToModel(dto);
|
|
} catch (e) {
|
|
throw Exception('사용자 수정 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 사용자 삭제
|
|
Future<void> deleteUser(int id) async {
|
|
try {
|
|
await _userRemoteDataSource.deleteUser(id);
|
|
} catch (e) {
|
|
throw Exception('사용자 삭제 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 사용자 상태 변경 - 레거시 메서드 비활성화
|
|
Future<User> changeUserStatus(int id, bool isActive) async {
|
|
throw UnimplementedError('레거시 메서드 - UserRepository 사용');
|
|
}
|
|
|
|
/// 비밀번호 변경 - 레거시 메서드 비활성화
|
|
Future<void> changePassword(
|
|
int id,
|
|
String currentPassword,
|
|
String newPassword,
|
|
) async {
|
|
throw UnimplementedError('레거시 메서드 - UserRepository 사용');
|
|
}
|
|
|
|
/// 관리자가 사용자 비밀번호 재설정 - 레거시 메서드 비활성화
|
|
Future<bool> resetPassword({
|
|
required int userId,
|
|
required String newPassword,
|
|
}) async {
|
|
throw UnimplementedError('레거시 메서드 - UserRepository 사용');
|
|
}
|
|
|
|
/// 사용자 상태 토글 (활성화/비활성화)
|
|
Future<User> toggleUserStatus(int userId) async {
|
|
try {
|
|
// 현재 사용자 정보 조회
|
|
final currentUser = await getUser(userId);
|
|
|
|
// 상태 반전
|
|
final newStatus = !currentUser.isActive;
|
|
|
|
// 상태 변경 실행
|
|
return await changeUserStatus(userId, newStatus);
|
|
} catch (e) {
|
|
throw Exception('사용자 상태 토글 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 사용자명 중복 확인 - 레거시 메서드 비활성화
|
|
Future<bool> checkDuplicateUsername(String username) async {
|
|
throw UnimplementedError('레거시 메서드 - UserRepository 사용');
|
|
}
|
|
|
|
/// 사용자 검색 - 레거시 메서드 비활성화
|
|
Future<List<User>> searchUsers({
|
|
required String query,
|
|
int? companyId,
|
|
String? status,
|
|
String? permissionLevel,
|
|
int page = 1,
|
|
int perPage = AppConstants.userPageSize,
|
|
}) async {
|
|
throw UnimplementedError('레거시 메서드 - UserRepository 사용');
|
|
}
|
|
|
|
/// DTO를 Model로 변환 (새로운 User 모델 구조 대응)
|
|
User _userDtoToModel(UserDto dto) {
|
|
return User(
|
|
id: dto.id ?? 0,
|
|
username: dto.name, // UserDto에는 username이 없으므로 name 사용
|
|
email: dto.email ?? '',
|
|
name: dto.name,
|
|
phone: dto.phone,
|
|
role: UserRole.staff, // UserDto에는 role이 없으므로 기본값
|
|
isActive: true, // UserDto에는 isActive가 없으므로 기본값
|
|
createdAt: DateTime.now(), // UserDto에는 createdAt이 없으므로 현재 시간
|
|
updatedAt: DateTime.now(), // UserDto에는 updatedAt이 없으므로 현재 시간
|
|
);
|
|
}
|
|
|
|
|
|
/// 전화번호 목록에서 첫 번째 전화번호 추출
|
|
String? getPhoneForApi(List<Map<String, String>> phoneNumbers) {
|
|
if (phoneNumbers.isEmpty) return null;
|
|
return phoneNumbers.first['number'];
|
|
}
|
|
} |