completed migrating data scope from user to workspace

This commit is contained in:
2026-06-22 22:10:38 +02:00
parent 62c7f53de0
commit ae2705363a
37 changed files with 918 additions and 221 deletions

View File

@@ -36,6 +36,7 @@ class BatchScreenModel {
int batchItemsTotalElements = 0;
String batchItemsSearchQuery = '';
String? batchItemsStatusFilter;
String? batchItemsRecipientAccount;
bool batchItemsIsLoadingMore = false;
// Provider products cache: providerId -> list of products
@@ -196,7 +197,7 @@ class BatchController extends ChangeNotifier {
}
final raw = await http.get(
'/public/group-batches?${buildQueryParameters(params)}',
'/group-batches?${buildQueryParameters(params)}',
);
final response = _unwrap(raw);
final pageableModel = PageableModel.fromJson(
@@ -268,8 +269,7 @@ class BatchController extends ChangeNotifier {
String batchId, {
int page = 0,
int size = 20,
String? search,
String? status,
Map<String, String>? filters,
}) async {
if (page == 0) {
model.isLoading = true;
@@ -287,16 +287,12 @@ class BatchController extends ChangeNotifier {
'size': size.toString(),
'sort': 'createdAt,desc',
};
if (search != null && search.isNotEmpty) {
params['recipientName'] = search;
params['recipientPhone'] = search;
}
if (status != null && status.isNotEmpty) {
params['status'] = status;
if (filters != null) {
params.addAll(filters);
}
final raw = await http.get(
'/public/group-batches/items?${buildQueryParameters(params)}',
'/group-batches/items?${buildQueryParameters(params)}',
);
final response = _unwrap(raw);
final pageableModel = PageableModel.fromJson(
@@ -337,10 +333,20 @@ class BatchController extends ChangeNotifier {
String batchId, {
String? search,
String? status,
String? account,
}) async {
model.batchItemsSearchQuery = search ?? '';
model.batchItemsStatusFilter = status;
await listBatchItems(batchId, page: 0, search: search, status: status);
model.batchItemsRecipientAccount = account;
await listBatchItems(
batchId,
page: 0,
filters: _buildBatchItemFilters(
search: search,
status: status,
account: account,
),
);
}
Future<void> loadNextBatchItemsPage(String batchId) async {
@@ -351,22 +357,44 @@ class BatchController extends ChangeNotifier {
await listBatchItems(
batchId,
page: model.batchItemsCurrentPage + 1,
search: model.batchItemsSearchQuery.isNotEmpty
? model.batchItemsSearchQuery
: null,
status: model.batchItemsStatusFilter,
filters: _buildBatchItemFilters(
search: model.batchItemsSearchQuery.isNotEmpty
? model.batchItemsSearchQuery
: null,
status: model.batchItemsStatusFilter,
account: model.batchItemsRecipientAccount,
),
);
}
/// Builds the filters map for batch items queries from individual params.
Map<String, String>? _buildBatchItemFilters({
String? search,
String? status,
String? account,
}) {
final filters = <String, String>{};
if (search != null && search.isNotEmpty) {
filters['recipientName'] = search;
}
if (status != null && status.isNotEmpty) {
filters['status'] = status;
}
if (account != null && account.isNotEmpty) {
filters['recipientAccount'] = account;
}
return filters.isEmpty ? null : filters;
}
Future<ApiResponse<GroupBatch>> getBatch(
String batchId,
String userId,
String workspaceId,
) async {
model.isActing = true;
if (!_disposed) notifyListeners();
try {
final raw = await http.get(
'/public/group-batches/$batchId?userId=$userId',
'/group-batches/$batchId?workspaceId=$workspaceId',
);
final response = _unwrap(raw);
final batch = GroupBatch.fromJson(response as Map<String, dynamic>);
@@ -386,7 +414,7 @@ class BatchController extends ChangeNotifier {
model.isActing = true;
if (!_disposed) notifyListeners();
try {
final raw = await http.post('/public/group-batches', req.toJson());
final raw = await http.post('/group-batches', req.toJson());
final response = _unwrap(raw);
final batch = GroupBatch.fromJson(response as Map<String, dynamic>);
model.currentBatch = batch;
@@ -409,7 +437,7 @@ class BatchController extends ChangeNotifier {
if (!_disposed) notifyListeners();
try {
final raw = await http.put(
'/public/group-batches/${request.id}',
'/group-batches/${request.id}',
request.toJson(),
);
final response = _unwrap(raw);
@@ -440,7 +468,7 @@ class BatchController extends ChangeNotifier {
if (!_disposed) notifyListeners();
try {
final raw = await http.put(
'/public/group-batches/$batchId/items',
'/group-batches/$batchId/items',
updateList.toJson(),
);
final response = _unwrap(raw);
@@ -463,16 +491,21 @@ class BatchController extends ChangeNotifier {
Future<ApiResponse<GroupBatch>> confirmBatch(
String batchId,
String userId,
String workspaceId,
String authType,
) async {
model.isActing = true;
if (!_disposed) notifyListeners();
try {
final key =
'batch-$batchId-confirm-${DateTime.now().millisecondsSinceEpoch}';
final body = BatchActionRequest(userId: userId, idempotencyKey: key);
final body = BatchActionRequest(
workspaceId: workspaceId,
authType: authType,
idempotencyKey: key,
);
final raw = await http.post(
'/public/group-batches/$batchId/confirm',
'/group-batches/$batchId/confirm',
body.toJson(),
);
final response = _unwrap(raw);
@@ -491,16 +524,19 @@ class BatchController extends ChangeNotifier {
Future<ApiResponse<TransactionModel>> requestBatch(
String batchId,
String userId,
String workspaceId,
) async {
model.isActing = true;
if (!_disposed) notifyListeners();
try {
final key =
'batch-$batchId-request-${DateTime.now().millisecondsSinceEpoch}';
final body = BatchActionRequest(userId: userId, idempotencyKey: key);
final body = BatchActionRequest(
workspaceId: workspaceId,
idempotencyKey: key,
);
final raw = await http.post(
'/public/group-batches/$batchId/request',
'/group-batches/$batchId/request',
body.toJson(),
);
final response = _unwrap(raw);
@@ -519,13 +555,13 @@ class BatchController extends ChangeNotifier {
Future<ApiResponse<Map<String, dynamic>>> downloadBatchReport(
String batchId,
String userId,
String workspaceId,
) async {
model.isActing = true;
if (!_disposed) notifyListeners();
try {
final raw = await http.get(
'/public/group-batches/$batchId/report?userId=$userId',
'/group-batches/$batchId/report?workspaceId=$workspaceId',
);
final response = _unwrap(raw);
model.isActing = false;
@@ -542,16 +578,19 @@ class BatchController extends ChangeNotifier {
Future<ApiResponse<TransactionModel>> pollBatch(
String batchId,
String userId,
String workspaceId,
) async {
model.isActing = true;
if (!_disposed) notifyListeners();
try {
final key =
'batch-$batchId-poll-${DateTime.now().millisecondsSinceEpoch}';
final body = BatchActionRequest(userId: userId, idempotencyKey: key);
final body = BatchActionRequest(
workspaceId: workspaceId,
idempotencyKey: key,
);
final raw = await http.post(
'/public/group-batches/$batchId/poll',
'/group-batches/$batchId/poll',
body.toJson(),
);
final response = _unwrap(raw);
@@ -578,10 +617,10 @@ class BatchController extends ChangeNotifier {
Future<void> deleteBatch({
required String batchId,
required String userId,
required String workspaceId,
}) async {
try {
await http.delete('/public/group-batches/$batchId?userId=$userId');
await http.delete('/group-batches/$batchId?workspaceId=$workspaceId');
model.batches.removeWhere((b) => b.id == batchId);
model.selectedBatchIds.remove(batchId);
model.currentBatch = null;
@@ -595,7 +634,7 @@ class BatchController extends ChangeNotifier {
Future<void> deleteSelectedBatches({
required String groupId,
required String userId,
required String workspaceId,
}) async {
final idsToDelete = List<String>.from(model.selectedBatchIds);
model.selectMode = false;
@@ -603,7 +642,7 @@ class BatchController extends ChangeNotifier {
if (!_disposed) notifyListeners();
for (final id in idsToDelete) {
await deleteBatch(batchId: id, userId: userId);
await deleteBatch(batchId: id, workspaceId: workspaceId);
}
// Refresh after deletion

View File

@@ -53,7 +53,7 @@ class GroupController extends ChangeNotifier {
}
Future<ApiResponse<PageableModel>> listGroups({
required String userId,
required String workspaceId,
int page = 0,
int size = 20,
String? name,
@@ -69,7 +69,7 @@ class GroupController extends ChangeNotifier {
try {
final params = <String, String>{
'userId': userId,
'workspaceId': workspaceId,
'page': page.toString(),
'size': size.toString(),
};
@@ -78,7 +78,7 @@ class GroupController extends ChangeNotifier {
}
final raw = await http.get(
'/public/recipient-groups?${buildQueryParameters(params)}',
'/recipient-groups?${buildQueryParameters(params)}',
);
final response = _unwrap(raw);
final pageableModel = PageableModel.fromJson(
@@ -115,17 +115,17 @@ class GroupController extends ChangeNotifier {
}
}
Future<void> searchGroups({required String userId, String? name}) async {
Future<void> searchGroups({required String workspaceId, String? name}) async {
model.searchQuery = name ?? '';
await listGroups(userId: userId, page: 0, name: name);
await listGroups(workspaceId: workspaceId, page: 0, name: name);
}
Future<void> loadNextPage({required String userId}) async {
Future<void> loadNextPage({required String workspaceId}) async {
if (model.isLoadingMore || model.currentPage + 1 >= model.totalPages) {
return;
}
await listGroups(
userId: userId,
workspaceId: workspaceId,
page: model.currentPage + 1,
name: model.searchQuery.isNotEmpty ? model.searchQuery : null,
);
@@ -138,7 +138,7 @@ class GroupController extends ChangeNotifier {
if (!_disposed) notifyListeners();
try {
final raw = await http.get(
'/public/recipient-groups/members?recipientGroupId=$groupId',
'/recipient-groups/members?recipientGroupId=$groupId',
);
final response = _unwrap(raw);
final List<dynamic> content;
@@ -172,7 +172,7 @@ class GroupController extends ChangeNotifier {
model.isLoading = true;
if (!_disposed) notifyListeners();
try {
final raw = await http.post('/public/recipient-groups', req.toJson());
final raw = await http.post('/recipient-groups', req.toJson());
final response = _unwrap(raw);
final group = RecipientGroup.fromJson(response as Map<String, dynamic>);
model.groups = [group, ...model.groups];
@@ -190,11 +190,11 @@ class GroupController extends ChangeNotifier {
Future<void> deleteGroup({
required String groupId,
required String userId,
required String workspaceId,
}) async {
try {
await http.delete(
'/public/recipient-groups/delete/$groupId?userId=$userId',
'/recipient-groups/delete/$groupId?workspaceId=$workspaceId',
);
model.groups.removeWhere((g) => g.id == groupId);
model.selectedGroupIds.remove(groupId);
@@ -226,11 +226,11 @@ class GroupController extends ChangeNotifier {
Future<void> removeMember({
required String groupId,
required String recipientId,
required String userId,
required String workspaceId,
}) async {
try {
await http.delete(
'/public/recipient-groups/$groupId/members/$recipientId?userId=$userId',
'/recipient-groups/$groupId/members/$recipientId?workspaceId=$workspaceId',
);
model.members.removeWhere((m) => m.id == recipientId);
if (!_disposed) notifyListeners();
@@ -241,19 +241,20 @@ class GroupController extends ChangeNotifier {
}
}
Future<void> deleteSelectedGroups({required String userId}) async {
Future<void> deleteSelectedGroups({required String workspaceId}) async {
final idsToDelete = List<String>.from(model.selectedGroupIds);
model.selectMode = false;
model.selectedGroupIds.clear();
if (!_disposed) notifyListeners();
for (final id in idsToDelete) {
await deleteGroup(groupId: id, userId: userId);
await deleteGroup(groupId: id, workspaceId: workspaceId);
}
}
Future<ApiResponse<CreateGroupFromFileResponse>> createGroupFromFile({
required String groupName,
required String workspaceId,
required String userId,
String? description,
required String currency,
@@ -266,6 +267,7 @@ class GroupController extends ChangeNotifier {
try {
final fields = <String, String>{
'groupName': groupName,
'workspaceId': workspaceId,
'userId': userId,
'currency': currency,
};
@@ -274,7 +276,7 @@ class GroupController extends ChangeNotifier {
}
final raw = await http.multipartPost(
'/public/recipient-groups/create-from-file',
'/recipient-groups/create-from-file',
fields,
'file',
fileBytes,