added batch file upload logic
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/models/api_response.dart';
|
||||
import 'package:qpay/models/pageable_model.dart';
|
||||
import 'package:qpay/screens/groups/models/create_group_from_file_response.dart';
|
||||
import 'package:qpay/screens/groups/models/recipient_group_model.dart';
|
||||
|
||||
class GroupScreenModel {
|
||||
@@ -80,8 +81,9 @@ class GroupController extends ChangeNotifier {
|
||||
'/public/recipient-groups?${buildQueryParameters(params)}',
|
||||
);
|
||||
final response = _unwrap(raw);
|
||||
final pageableModel =
|
||||
PageableModel.fromJson(response as Map<String, dynamic>);
|
||||
final pageableModel = PageableModel.fromJson(
|
||||
response as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
final newGroups = pageableModel.content
|
||||
.map((e) => RecipientGroup.fromJson(e as Map<String, dynamic>))
|
||||
@@ -113,10 +115,7 @@ class GroupController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> searchGroups({
|
||||
required String userId,
|
||||
String? name,
|
||||
}) async {
|
||||
Future<void> searchGroups({required String userId, String? name}) async {
|
||||
model.searchQuery = name ?? '';
|
||||
await listGroups(userId: userId, page: 0, name: name);
|
||||
}
|
||||
@@ -252,4 +251,50 @@ class GroupController extends ChangeNotifier {
|
||||
await deleteGroup(groupId: id, userId: userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<CreateGroupFromFileResponse>> createGroupFromFile({
|
||||
required String groupName,
|
||||
required String userId,
|
||||
String? description,
|
||||
required String currency,
|
||||
required List<int> fileBytes,
|
||||
required String fileName,
|
||||
}) async {
|
||||
model.isLoading = true;
|
||||
if (!_disposed) notifyListeners();
|
||||
|
||||
try {
|
||||
final fields = <String, String>{
|
||||
'groupName': groupName,
|
||||
'userId': userId,
|
||||
'currency': currency,
|
||||
};
|
||||
if (description != null && description.isNotEmpty) {
|
||||
fields['description'] = description;
|
||||
}
|
||||
|
||||
final raw = await http.multipartPost(
|
||||
'/public/recipient-groups/create-from-file',
|
||||
fields,
|
||||
'file',
|
||||
fileBytes,
|
||||
fileName,
|
||||
);
|
||||
final response = _unwrap(raw);
|
||||
final result = CreateGroupFromFileResponse.fromJson(
|
||||
response as Map<String, dynamic>,
|
||||
);
|
||||
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
|
||||
return ApiResponse.success(result);
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
model.errorMessage = e.toString();
|
||||
model.isLoading = false;
|
||||
if (!_disposed) notifyListeners();
|
||||
return ApiResponse.failure('Failed to create group from file');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user