outlet list
This commit is contained in:
@@ -36,4 +36,39 @@ class OutletRemoteDataProvider {
|
||||
return DC.error(OutletFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<DC<OutletFailure, List<OutletDto>>> fetchList({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
String? search,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
try {
|
||||
final Map<String, dynamic> params = {
|
||||
'page': page,
|
||||
'limit': limit,
|
||||
'search': search ?? 'null',
|
||||
'is_active': isActive != null ? isActive.toString() : 'null',
|
||||
};
|
||||
|
||||
final response = await _apiClient.get(
|
||||
'${ApiPath.outlet}/list',
|
||||
params: params,
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.data['data'] == null) {
|
||||
return DC.error(OutletFailure.empty());
|
||||
}
|
||||
|
||||
final dto = (response.data['data']['outlets'] as List)
|
||||
.map((item) => OutletDto.fromJson(item))
|
||||
.toList();
|
||||
|
||||
return DC.data(dto);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('fetchOutletListError', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(OutletFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,4 +33,32 @@ class OutletRepository implements IOutletRepository {
|
||||
return left(const OutletFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<OutletFailure, List<Outlet>>> getList({
|
||||
int page = 1,
|
||||
int limit = 10,
|
||||
String? search,
|
||||
bool? isActive,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _dataProvider.fetchList(
|
||||
page: page,
|
||||
limit: limit,
|
||||
search: search,
|
||||
isActive: isActive,
|
||||
);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
final outlets = result.data!.map((e) => e.toDomain()).toList();
|
||||
|
||||
return right(outlets);
|
||||
} catch (e, s) {
|
||||
log('getOutletListError', name: _logName, error: e, stackTrace: s);
|
||||
return left(const OutletFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user