feat: update position table
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:ui';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:enaklo_pos/core/network/dio_client.dart';
|
||||
@@ -88,4 +89,40 @@ class TableRemoteDataSource {
|
||||
return const Left('Unexpected error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
Future<Either<String, bool>> updatePosition({
|
||||
required String tableId,
|
||||
required Offset position,
|
||||
}) async {
|
||||
try {
|
||||
final authData = await AuthLocalDataSource().getAuthData();
|
||||
final url = '${Variables.baseUrl}/api/v1/tables/$tableId';
|
||||
|
||||
final response = await dio.put(
|
||||
url,
|
||||
data: {
|
||||
"position_x": position.dx.round(),
|
||||
"position_y": position.dy.round(),
|
||||
},
|
||||
options: Options(
|
||||
headers: {
|
||||
'Authorization': 'Bearer ${authData.token}',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
return Right(true);
|
||||
} else {
|
||||
return const Left('Failed to create table');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
log("Dio error: ${e.message}");
|
||||
return Left(e.response?.data['message'] ?? 'Gagal membuat table');
|
||||
} catch (e) {
|
||||
log("Unexpected error: $e");
|
||||
return const Left('Unexpected error occurred');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user