feat: current outlet

This commit is contained in:
efrilm
2025-08-04 13:15:03 +07:00
parent cd071db0cb
commit c07ef29054
12 changed files with 1639 additions and 16 deletions
@@ -40,4 +40,42 @@ class OutletRemoteDataSource {
return const Left('Unexpected error occurred');
}
}
Future<Either<String, OutletDetailResponse>> currentOutlet() async {
try {
final authData = await AuthLocalDataSource().getAuthData();
if (authData.user?.outletId == null) {
return const Left('Kamu belum memiliki bergabung dengan outlet');
}
final url =
'${Variables.baseUrl}/api/v1/outlets/detail/${authData.user?.outletId}';
final response = await dio.get(
url,
queryParameters: {
'organization_id': authData.user?.organizationId,
},
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
},
),
);
if (response.statusCode == 200) {
return Right(OutletDetailResponse.fromMap(response.data));
} else {
return const Left('Failed to get outlets');
}
} on DioException catch (e) {
log("Dio error: ${e.message}");
return Left(e.response?.data['message'] ?? 'Gagal mengambil outlet');
} catch (e) {
log("Unexpected error: $e");
return const Left('Unexpected error occurred');
}
}
}