completed migrating data scope from user to workspace
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user