update position table, set selected table
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/api/api_client.dart';
|
||||
@@ -42,4 +43,32 @@ class TableRemoteDataProvider {
|
||||
return DC.error(TableFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<TableFailure, TableDto>> updatePosition({
|
||||
required String id,
|
||||
required Offset position,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.put(
|
||||
'${ApiPath.tables}/$id',
|
||||
data: {
|
||||
'position_x': position.dx.round(),
|
||||
'position_y': position.dy.round(),
|
||||
},
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
return DC.error(TableFailure.unexpectedError());
|
||||
}
|
||||
|
||||
final table = TableDto.fromJson(
|
||||
response.data['data'] as Map<String, dynamic>,
|
||||
);
|
||||
return DC.data(table);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('updatePositionTableError', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(TableFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
@@ -36,4 +37,28 @@ class TableRepository implements ITableRepository {
|
||||
return left(const TableFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<TableFailure, Table>> updatePosition({
|
||||
required String id,
|
||||
required Offset position,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _remoteDataProvider.updatePosition(
|
||||
id: id,
|
||||
position: position,
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
final table = result.data!.toDomain();
|
||||
|
||||
return right(table);
|
||||
} catch (e) {
|
||||
log('updatePositionTableError', name: _logName, error: e);
|
||||
return left(const TableFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user