feat: current outlet
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user