createDataSourceAndDataSourceImpl method
Future<void>
createDataSourceAndDataSourceImpl(- {required String featureName,
- required String requestModelName,
- required String apiName,
- required String apiMethodName}
)
Implementation
Future<void> createDataSourceAndDataSourceImpl(
{required String featureName,
required String requestModelName,
required String apiName,
required String apiMethodName}) async {
String featureNameString = featureName.toLowerCase();
String pascalCaseApiName = Utility.toPascalCase(input: apiName);
String name = Utility.getPubspecInfo() ?? kWhitespaces;
String dataSourceDestinationPath =
PathHandler().getDataSourcePath(featureName: featureName);
if (Utility.doesFileExist(filePath: dataSourceDestinationPath)) {
final importDataSourceStatements = [PathHandler().getApiResponseImport()];
List<String> dataSourceAppendLinesDataSource = [];
if (requestModelName.isNotEmpty) {
importDataSourceStatements.add(PathHandler()
.getRequestModelImport(featureName: featureName, apiName: apiName));
dataSourceAppendLinesDataSource.add(CodeHandler()
.getDataSourceStatementWithRequestModel(
pascalCaseApiName: pascalCaseApiName,
requestModelName: requestModelName));
} else {
dataSourceAppendLinesDataSource = [
CodeHandler().getDataSourceStatementWithoutRequestModel(
pascalCaseApiName: pascalCaseApiName)
];
}
await fileUpdate(dataSourceDestinationPath, importDataSourceStatements,
dataSourceAppendLinesDataSource);
Utility.successPrinter(text: '$kApiCodeUpdate $kDataSource $kFile');
}
/// update data_source_impl.dart to add imports statement and function method
String destinationPathDataSourceImpl =
PathHandler().getDataSourceImplPath(featureName: featureName);
if (Utility.doesFileExist(filePath: destinationPathDataSourceImpl)) {
final importDataSourceImplStatements = [
PathHandler().getApiResponsePath(),
PathHandler().getApiConstantPath(featureName: featureName)
];
List<String> dataSourceAppendLinesDataSourceImpl = [];
if (requestModelName.isNotEmpty) {
importDataSourceImplStatements.add(PathHandler()
.getRequestModelImport(featureName: featureName, apiName: apiName));
if (apiMethodName == kGet) {
dataSourceAppendLinesDataSourceImpl = CodeHandler()
.getDataSourceImplStatementForGetMethodWithRequestModel(
pascalCaseApiName: pascalCaseApiName,
requestModelName: requestModelName,
apiMethodName: apiMethodName,
apiName: apiName);
} else if (apiMethodName == kPost) {
dataSourceAppendLinesDataSourceImpl = CodeHandler()
.getDataSourceImplStatementForPostMethodWithRequestModel(
pascalCaseApiName: pascalCaseApiName,
requestModelName: requestModelName,
apiMethodName: apiMethodName,
apiName: apiName);
}
} else {
if (apiMethodName == kGet) {
dataSourceAppendLinesDataSourceImpl = CodeHandler()
.getDataSourceImplStatementForGetMethodWithoutRequestModel(
pascalCaseApiName: pascalCaseApiName,
apiMethodName: apiMethodName,
apiName: apiName);
} else if (apiMethodName == kPost) {
dataSourceAppendLinesDataSourceImpl = CodeHandler()
.getDataSourceImplStatementForPostMethodWithoutRequestModel(
pascalCaseApiName: pascalCaseApiName,
apiMethodName: apiMethodName,
apiName: apiName);
}
}
await fileUpdate(destinationPathDataSourceImpl,
importDataSourceImplStatements, dataSourceAppendLinesDataSourceImpl);
Utility.successPrinter(text: '$kApiCodeUpdate $kDataSourceImpl $kFile');
}
}