결재 단계 목록 화면과 테스트 도입
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/approval_step_record.dart';
|
||||
import '../../domain/repositories/approval_step_repository.dart';
|
||||
|
||||
class ApprovalStepController extends ChangeNotifier {
|
||||
ApprovalStepController({required ApprovalStepRepository repository})
|
||||
: _repository = repository;
|
||||
|
||||
final ApprovalStepRepository _repository;
|
||||
|
||||
PaginatedResult<ApprovalStepRecord>? _result;
|
||||
bool _isLoading = false;
|
||||
String _query = '';
|
||||
int? _statusId;
|
||||
String? _errorMessage;
|
||||
bool _isLoadingDetail = false;
|
||||
ApprovalStepRecord? _selected;
|
||||
|
||||
PaginatedResult<ApprovalStepRecord>? get result => _result;
|
||||
bool get isLoading => _isLoading;
|
||||
String get query => _query;
|
||||
int? get statusId => _statusId;
|
||||
String? get errorMessage => _errorMessage;
|
||||
bool get isLoadingDetail => _isLoadingDetail;
|
||||
ApprovalStepRecord? get selected => _selected;
|
||||
|
||||
Future<void> fetch({int page = 1}) async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
final sanitizedQuery = _query.trim();
|
||||
final response = await _repository.list(
|
||||
page: page,
|
||||
pageSize: _result?.pageSize ?? 20,
|
||||
query: sanitizedQuery.isEmpty ? null : sanitizedQuery,
|
||||
statusId: _statusId,
|
||||
);
|
||||
_result = response;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuery(String value) {
|
||||
_query = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateStatusId(int? value) {
|
||||
_statusId = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<ApprovalStepRecord?> fetchDetail(int id) async {
|
||||
_isLoadingDetail = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
final detail = await _repository.fetchDetail(id);
|
||||
_selected = detail;
|
||||
return detail;
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
return null;
|
||||
} finally {
|
||||
_isLoadingDetail = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void clearSelection() {
|
||||
_selected = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clearError() {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool get hasActiveFilters => _query.trim().isNotEmpty || _statusId != null;
|
||||
|
||||
void resetFilters() {
|
||||
_query = '';
|
||||
_statusId = null;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user