feat: update position table

This commit is contained in:
efrilm
2025-08-04 00:09:51 +07:00
parent 6afd62b617
commit 6302ea0282
7 changed files with 251 additions and 26 deletions
@@ -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');
}
}
}