결재 API 계약 보완 및 테스트 정리

This commit is contained in:
JiWoong Sul
2025-10-16 18:53:22 +09:00
parent 9e2244f260
commit efed3c1a6f
44 changed files with 1969 additions and 293 deletions

View File

@@ -57,6 +57,7 @@ class ApprovalController extends ChangeNotifier {
bool _isLoadingList = false;
bool _isLoadingDetail = false;
bool _isLoadingActions = false;
bool _isSubmitting = false;
bool _isPerformingAction = false;
int? _processingStepId;
bool _isLoadingTemplates = false;
@@ -72,6 +73,7 @@ class ApprovalController extends ChangeNotifier {
List<ApprovalAction> _actions = const [];
List<ApprovalTemplate> _templates = const [];
final Map<String, LookupItem> _statusLookup = {};
List<LookupItem> _statusOptions = const [];
final Map<String, String> _statusCodeAliases = Map.fromEntries(
_defaultStatusCodes.entries.map(
(entry) => MapEntry(entry.value, entry.value),
@@ -83,6 +85,7 @@ class ApprovalController extends ChangeNotifier {
bool get isLoadingList => _isLoadingList;
bool get isLoadingDetail => _isLoadingDetail;
bool get isLoadingActions => _isLoadingActions;
bool get isSubmitting => _isSubmitting;
bool get isPerformingAction => _isPerformingAction;
int? get processingStepId => _processingStepId;
String? get errorMessage => _errorMessage;
@@ -107,6 +110,35 @@ class ApprovalController extends ChangeNotifier {
return reason;
}
List<LookupItem> get approvalStatusOptions => _statusOptions;
int? get defaultApprovalStatusId {
if (_statusOptions.isEmpty) {
return null;
}
final defaultItem = _statusOptions.firstWhere(
(item) => item.isDefault,
orElse: () => _statusOptions.first,
);
return defaultItem.id;
}
LookupItem? approvalStatusById(int? id) {
if (id == null) {
return null;
}
final lookup = _statusLookup[id.toString()];
if (lookup != null) {
return lookup;
}
for (final item in _statusOptions) {
if (item.id == id) {
return item;
}
}
return null;
}
Map<String, LookupItem> get statusLookup => _statusLookup;
/// 필터 조건과 페이지 정보를 기반으로 결재 목록을 조회한다.
@@ -174,6 +206,7 @@ class ApprovalController extends ChangeNotifier {
}
try {
final items = await repository.fetchApprovalStatuses();
_statusOptions = List.unmodifiable(items);
_statusLookup
..clear()
..addEntries(
@@ -311,6 +344,53 @@ class ApprovalController extends ChangeNotifier {
notifyListeners();
}
/// 결재를 생성하고 목록/상세 상태를 최신화한다.
Future<Approval?> createApproval(ApprovalCreateInput input) async {
_setSubmitting(true);
_errorMessage = null;
try {
final created = await _repository.create(input);
await fetch(page: 1);
_selected = created;
if (created.id != null) {
await _loadProceedStatus(created.id!);
}
notifyListeners();
return created;
} catch (error) {
final failure = Failure.from(error);
_errorMessage = failure.describe();
notifyListeners();
return null;
} finally {
_setSubmitting(false);
}
}
/// 결재 기본 정보를 수정하고 현재 페이지를 유지한다.
Future<Approval?> updateApproval(ApprovalUpdateInput input) async {
_setSubmitting(true);
_errorMessage = null;
try {
final updated = await _repository.update(input);
final currentPage = _result?.page ?? 1;
await fetch(page: currentPage);
_selected = updated;
if (updated.id != null) {
await _loadProceedStatus(updated.id!);
}
notifyListeners();
return updated;
} catch (error) {
final failure = Failure.from(error);
_errorMessage = failure.describe();
notifyListeners();
return null;
} finally {
_setSubmitting(false);
}
}
/// 결재 단계에 대해 승인/반려/코멘트 등 지정된 행위를 수행한다.
///
/// - 유효한 단계 ID와 액션이 존재해야 하며, 실행 중에는 중복 호출을 방지한다.
@@ -477,6 +557,14 @@ class ApprovalController extends ChangeNotifier {
notifyListeners();
}
void _setSubmitting(bool value) {
if (_isSubmitting == value) {
return;
}
_isSubmitting = value;
notifyListeners();
}
/// 액션 타입과 동일한 코드(또는 별칭)를 가진 결재 행위를 찾는다.
ApprovalAction? _findActionByType(ApprovalStepActionType type) {
final aliases = _actionAliases[type] ?? [type.code];