- 전체 371개 파일 중 82개 미사용 파일 식별 - Phase 1: 33개 파일 삭제 예정 (100% 안전) - Phase 2: 30개 파일 삭제 검토 예정 - Phase 3: 19개 파일 수동 검토 예정 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
161 lines
4.6 KiB
Dart
161 lines
4.6 KiB
Dart
import 'package:injectable/injectable.dart';
|
|
import 'package:superport/core/constants/app_constants.dart';
|
|
import 'package:superport/data/datasources/remote/administrator_remote_datasource.dart';
|
|
import 'package:superport/data/models/administrator_dto.dart';
|
|
|
|
/// 관리자 서비스 (백엔드 Administrator 테이블)
|
|
/// HTTP API 호출을 담당하는 서비스 레이어
|
|
@lazySingleton
|
|
class AdministratorService {
|
|
final AdministratorRemoteDataSource _remoteDataSource;
|
|
|
|
AdministratorService(this._remoteDataSource);
|
|
|
|
/// 관리자 목록 조회 (페이지네이션 지원)
|
|
Future<AdministratorListResponse> getAdministrators({
|
|
int page = 1,
|
|
int pageSize = AppConstants.adminPageSize,
|
|
String? search,
|
|
}) async {
|
|
try {
|
|
return await _remoteDataSource.getAdministrators(
|
|
page: page,
|
|
pageSize: pageSize,
|
|
search: search,
|
|
);
|
|
} catch (e) {
|
|
throw Exception('관리자 목록 조회 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 특정 관리자 조회
|
|
Future<AdministratorDto> getAdministrator(int id) async {
|
|
try {
|
|
return await _remoteDataSource.getAdministrator(id);
|
|
} catch (e) {
|
|
throw Exception('관리자 조회 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 관리자 계정 생성
|
|
Future<AdministratorDto> createAdministrator({
|
|
required String name,
|
|
required String phone,
|
|
required String mobile,
|
|
required String email,
|
|
required String password,
|
|
}) async {
|
|
try {
|
|
final request = AdministratorRequestDto(
|
|
name: name,
|
|
phone: phone,
|
|
mobile: mobile,
|
|
email: email,
|
|
passwd: password,
|
|
);
|
|
|
|
return await _remoteDataSource.createAdministrator(request);
|
|
} catch (e) {
|
|
throw Exception('관리자 계정 생성 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 관리자 정보 수정
|
|
Future<AdministratorDto> updateAdministrator(
|
|
int id, {
|
|
String? name,
|
|
String? phone,
|
|
String? mobile,
|
|
String? email,
|
|
String? password,
|
|
}) async {
|
|
try {
|
|
final request = AdministratorUpdateRequestDto(
|
|
name: name,
|
|
phone: phone,
|
|
mobile: mobile,
|
|
email: email,
|
|
passwd: password,
|
|
);
|
|
|
|
return await _remoteDataSource.updateAdministrator(id, request);
|
|
} catch (e) {
|
|
throw Exception('관리자 정보 수정 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 관리자 계정 삭제
|
|
Future<void> deleteAdministrator(int id) async {
|
|
try {
|
|
await _remoteDataSource.deleteAdministrator(id);
|
|
} catch (e) {
|
|
throw Exception('관리자 계정 삭제 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 이메일 중복 확인
|
|
Future<bool> checkEmailAvailability(String email, {int? excludeId}) async {
|
|
try {
|
|
return await _remoteDataSource.checkEmailAvailability(
|
|
email,
|
|
excludeId: excludeId,
|
|
);
|
|
} catch (e) {
|
|
// 에러 발생 시 안전하게 false 반환 (사용 불가로 처리)
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// 이메일 중복 여부 확인 (편의 메서드)
|
|
Future<bool> isDuplicateEmail(String email, {int? excludeId}) async {
|
|
try {
|
|
final isAvailable = await checkEmailAvailability(email, excludeId: excludeId);
|
|
return !isAvailable; // 사용 가능하면 중복이 아님
|
|
} catch (e) {
|
|
// 에러 발생 시 안전하게 중복으로 처리
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/// 관리자 인증 (로그인)
|
|
Future<AdministratorDto> authenticateAdministrator(
|
|
String email,
|
|
String password,
|
|
) async {
|
|
try {
|
|
return await _remoteDataSource.authenticateAdministrator(email, password);
|
|
} catch (e) {
|
|
throw Exception('관리자 인증 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 관리자 전체 수 조회 (통계용)
|
|
Future<int> getAdministratorCount() async {
|
|
try {
|
|
final response = await getAdministrators(page: 1, pageSize: 1);
|
|
return response.totalCount;
|
|
} catch (e) {
|
|
throw Exception('관리자 수 조회 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
|
|
/// 이메일로 관리자 검색 (단일 결과 기대)
|
|
Future<AdministratorDto?> findAdministratorByEmail(String email) async {
|
|
try {
|
|
final response = await getAdministrators(search: email, pageSize: AppConstants.adminPageSize);
|
|
|
|
// 정확히 일치하는 이메일 찾기
|
|
final exactMatch = response.items.where((admin) =>
|
|
admin.email.toLowerCase() == email.toLowerCase()).firstOrNull;
|
|
|
|
return exactMatch;
|
|
} catch (e) {
|
|
throw Exception('이메일로 관리자 검색 실패: ${e.toString()}');
|
|
}
|
|
}
|
|
}
|
|
|
|
/// List 확장 메서드 (firstOrNull이 없는 Dart 버전 대응)
|
|
extension ListExtension<T> on List<T> {
|
|
T? get firstOrNull => isEmpty ? null : first;
|
|
} |