transfer table
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
@@ -21,12 +22,19 @@ class TableRemoteDataProvider {
|
||||
Future<DC<TableFailure, ListTableDto>> fetchTables({
|
||||
int page = 1,
|
||||
int limit = 50,
|
||||
String? status,
|
||||
}) async {
|
||||
try {
|
||||
Map<String, dynamic> queryParameters = {'page': page, 'limit': limit};
|
||||
|
||||
if (status != null) {
|
||||
queryParameters['status'] = status;
|
||||
}
|
||||
|
||||
final response = await _apiClient.get(
|
||||
ApiPath.tables,
|
||||
headers: getAuthorizationHeader(),
|
||||
params: {'page': page, 'limit': limit},
|
||||
params: queryParameters,
|
||||
);
|
||||
|
||||
if (response.data['data'] == null) {
|
||||
@@ -103,4 +111,26 @@ class TableRemoteDataProvider {
|
||||
return DC.error(TableFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<TableFailure, Unit>> transferTable({
|
||||
required String fromTableId,
|
||||
required String toTableId,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
'${ApiPath.tables}/transfer',
|
||||
data: {'from_table': fromTableId, 'to_table': toTableId},
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
return DC.error(TableFailure.unexpectedError());
|
||||
}
|
||||
|
||||
return DC.data(unit);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('transferTableError', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(TableFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,13 @@ class TableRepository implements ITableRepository {
|
||||
Future<Either<TableFailure, ListTable>> fetchTables({
|
||||
int page = 1,
|
||||
int limit = 50,
|
||||
String? status,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _remoteDataProvider.fetchTables(
|
||||
page: page,
|
||||
limit: limit,
|
||||
status: status,
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
@@ -90,4 +92,26 @@ class TableRepository implements ITableRepository {
|
||||
return left(const TableFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<TableFailure, Unit>> transferTable({
|
||||
required String fromTableId,
|
||||
required String toTableId,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _remoteDataProvider.transferTable(
|
||||
fromTableId: fromTableId,
|
||||
toTableId: toTableId,
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
return right(unit);
|
||||
} catch (e) {
|
||||
log('transferTableError', name: _logName, error: e);
|
||||
return left(const TableFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user