결재 템플릿 단계 적용 구현
- ApprovalTemplate 엔티티·DTO·원격 리포지토리 추가 - ApprovalController에 템플릿 로딩/적용 상태와 assignSteps 호출 연동 - ApprovalPage 단계 탭에 템플릿 선택 UI 및 적용 확인 다이얼로그 구현 - 템플릿 적용 단위 테스트와 IMPLEMENTATION_TASKS 현황 갱신
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
|
||||
import '../../domain/entities/group_permission.dart';
|
||||
|
||||
class GroupPermissionDto {
|
||||
GroupPermissionDto({
|
||||
this.id,
|
||||
required this.group,
|
||||
required this.menu,
|
||||
this.canCreate = false,
|
||||
this.canRead = true,
|
||||
this.canUpdate = false,
|
||||
this.canDelete = false,
|
||||
this.isActive = true,
|
||||
this.isDeleted = false,
|
||||
this.note,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
final int? id;
|
||||
final GroupPermissionGroupDto group;
|
||||
final GroupPermissionMenuDto menu;
|
||||
final bool canCreate;
|
||||
final bool canRead;
|
||||
final bool canUpdate;
|
||||
final bool canDelete;
|
||||
final bool isActive;
|
||||
final bool isDeleted;
|
||||
final String? note;
|
||||
final DateTime? createdAt;
|
||||
final DateTime? updatedAt;
|
||||
|
||||
factory GroupPermissionDto.fromJson(Map<String, dynamic> json) {
|
||||
return GroupPermissionDto(
|
||||
id: json['id'] as int?,
|
||||
group: GroupPermissionGroupDto.fromJson(
|
||||
(json['group'] as Map<String, dynamic>? ?? const {}),
|
||||
),
|
||||
menu: GroupPermissionMenuDto.fromJson(
|
||||
(json['menu'] as Map<String, dynamic>? ?? const {}),
|
||||
),
|
||||
canCreate: (json['can_create'] as bool?) ?? false,
|
||||
canRead: (json['can_read'] as bool?) ?? true,
|
||||
canUpdate: (json['can_update'] as bool?) ?? false,
|
||||
canDelete: (json['can_delete'] as bool?) ?? false,
|
||||
isActive: (json['is_active'] as bool?) ?? true,
|
||||
isDeleted: (json['is_deleted'] as bool?) ?? false,
|
||||
note: json['note'] as String?,
|
||||
createdAt: _parseDate(json['created_at']),
|
||||
updatedAt: _parseDate(json['updated_at']),
|
||||
);
|
||||
}
|
||||
|
||||
GroupPermission toEntity() => GroupPermission(
|
||||
id: id,
|
||||
group: group.toEntity(),
|
||||
menu: menu.toEntity(),
|
||||
canCreate: canCreate,
|
||||
canRead: canRead,
|
||||
canUpdate: canUpdate,
|
||||
canDelete: canDelete,
|
||||
isActive: isActive,
|
||||
isDeleted: isDeleted,
|
||||
note: note,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
);
|
||||
|
||||
static PaginatedResult<GroupPermission> parsePaginated(
|
||||
Map<String, dynamic>? json,
|
||||
) {
|
||||
final items = (json?['items'] as List<dynamic>? ?? [])
|
||||
.whereType<Map<String, dynamic>>()
|
||||
.map(GroupPermissionDto.fromJson)
|
||||
.map((dto) => dto.toEntity())
|
||||
.toList();
|
||||
return PaginatedResult<GroupPermission>(
|
||||
items: items,
|
||||
page: json?['page'] as int? ?? 1,
|
||||
pageSize: json?['page_size'] as int? ?? items.length,
|
||||
total: json?['total'] as int? ?? items.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GroupPermissionGroupDto {
|
||||
GroupPermissionGroupDto({required this.id, required this.groupName});
|
||||
|
||||
final int id;
|
||||
final String groupName;
|
||||
|
||||
factory GroupPermissionGroupDto.fromJson(Map<String, dynamic> json) {
|
||||
return GroupPermissionGroupDto(
|
||||
id: json['id'] as int? ?? json['group_id'] as int,
|
||||
groupName:
|
||||
json['group_name'] as String? ?? json['name'] as String? ?? '-',
|
||||
);
|
||||
}
|
||||
|
||||
GroupPermissionGroup toEntity() =>
|
||||
GroupPermissionGroup(id: id, groupName: groupName);
|
||||
}
|
||||
|
||||
class GroupPermissionMenuDto {
|
||||
GroupPermissionMenuDto({required this.id, required this.menuName});
|
||||
|
||||
final int id;
|
||||
final String menuName;
|
||||
|
||||
factory GroupPermissionMenuDto.fromJson(Map<String, dynamic> json) {
|
||||
return GroupPermissionMenuDto(
|
||||
id: json['id'] as int? ?? json['menu_id'] as int,
|
||||
menuName: json['menu_name'] as String? ?? json['name'] as String? ?? '-',
|
||||
);
|
||||
}
|
||||
|
||||
GroupPermissionMenu toEntity() =>
|
||||
GroupPermissionMenu(id: id, menuName: menuName);
|
||||
}
|
||||
|
||||
DateTime? _parseDate(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is DateTime) return value;
|
||||
if (value is String) return DateTime.tryParse(value);
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:superport_v2/core/common/models/paginated_result.dart';
|
||||
import 'package:superport_v2/core/network/api_client.dart';
|
||||
|
||||
import '../../domain/entities/group_permission.dart';
|
||||
import '../../domain/repositories/group_permission_repository.dart';
|
||||
import '../dtos/group_permission_dto.dart';
|
||||
|
||||
class GroupPermissionRepositoryRemote implements GroupPermissionRepository {
|
||||
GroupPermissionRepositoryRemote({required ApiClient apiClient})
|
||||
: _api = apiClient;
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
static const _basePath = '/group-menu-permissions';
|
||||
|
||||
@override
|
||||
Future<PaginatedResult<GroupPermission>> list({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
int? groupId,
|
||||
int? menuId,
|
||||
bool? isActive,
|
||||
bool includeDeleted = false,
|
||||
}) async {
|
||||
final response = await _api.get<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
query: {
|
||||
'page': page,
|
||||
'page_size': pageSize,
|
||||
if (groupId != null) 'group_id': groupId,
|
||||
if (menuId != null) 'menu_id': menuId,
|
||||
if (isActive != null) 'is_active': isActive,
|
||||
if (includeDeleted) 'include_deleted': true,
|
||||
'include': 'group,menu',
|
||||
},
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
return GroupPermissionDto.parsePaginated(response.data ?? const {});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GroupPermission> create(GroupPermissionInput input) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
_basePath,
|
||||
data: input.toPayload(),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return GroupPermissionDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GroupPermission> update(int id, GroupPermissionInput input) async {
|
||||
final response = await _api.patch<Map<String, dynamic>>(
|
||||
'$_basePath/$id',
|
||||
data: input.toPayload(),
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return GroupPermissionDto.fromJson(data).toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(int id) async {
|
||||
await _api.delete<void>('$_basePath/$id');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GroupPermission> restore(int id) async {
|
||||
final response = await _api.post<Map<String, dynamic>>(
|
||||
'$_basePath/$id/restore',
|
||||
options: Options(responseType: ResponseType.json),
|
||||
);
|
||||
final data = (response.data?['data'] as Map<String, dynamic>?) ?? {};
|
||||
return GroupPermissionDto.fromJson(data).toEntity();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user