updateDataSource method
Future<void>
updateDataSource(
)
Implementation
Future<void> updateDataSource() async {
final dsFile = await FileUtils.findFile(
path.join(featurePath, 'data', 'data_source'),
'${naming.featureLower}_remote_data_source.dart',
);
if (dsFile == null) {
print('⚠️ RemoteDataSource file not found – skipping');
return;
}
if (await FileUtils.containsPattern(dsFile, naming.actionCamel)) {
print('⚠️ Method already in DataSource – skipping');
return;
}
final abstractSig =
' Future<Either<Failure, ${naming.responseClass}>> ${naming.actionCamel}(${naming.requestClass} params);';
final implMethod = '''
@override
Future<Either<Failure, ${naming.responseClass}>> ${naming.actionCamel}(${naming.requestClass} params) async {
try {
final response = await DioHelper.getData(
endPoint: 'TODO_ADD_ENDPOINT',
query: params.toJson(),
);
return response.fold(
(failure) => Left(failure),
(data) => Right(${naming.responseClass}.fromJson(data['data'])),
);
} on DioException catch (e) {
return Left(ServerFailure(DioHelper.handleError(e)));
} catch (e) {
return Left(ServerFailure(e.toString()));
}
}
''';
await _insertMethods(dsFile, abstractSig, implMethod);
print('✅ Methods added to DataSource : $dsFile');
}