createRepoAndRepoImpl method
Future<void>
createRepoAndRepoImpl(- {required String featureName,
- required String requestModelName,
- required String responseModelName,
- required String apiName,
- required String apiMethodName}
)
Implementation
Future<void> createRepoAndRepoImpl(
{required String featureName,
required String requestModelName,
required String responseModelName,
required String apiName,
required String apiMethodName}) async {
String featureNameString = featureName.toLowerCase();
String pascalCaseApiName = Utility.toPascalCase(input: apiName);
String name = Utility.getPubspecInfo() ?? '';
/// update repo.dart to add imports statement and function signature
String destinationPathRepo =
PathHandler().getRepoPath(featureName: featureName);
if (Utility.doesFileExist(filePath: destinationPathRepo)) {
final importRepoStatements = [
PathHandler().getFailureImport(featureName: featureName),
PathHandler().getSuccessImport(featureName: featureName),
PathHandler().getDartzImport(featureName: featureName)
];
List<String> repoAppendLines = [];
if (requestModelName.isNotEmpty) {
importRepoStatements.add(PathHandler()
.getRequestModelImport(featureName: featureName, apiName: apiName));
repoAppendLines = [
CodeHandler().getRepoStatementWithRequestModel(
requestModelName: requestModelName,
pascalCaseApiName: pascalCaseApiName),
];
} else {
repoAppendLines = [
CodeHandler().getRepoStatementWithoutRequestModel(
pascalCaseApiName: pascalCaseApiName),
];
}
await fileUpdate(
destinationPathRepo, importRepoStatements, repoAppendLines);
Utility.successPrinter(text: '$kApiCodeUpdate $kRepo $kFile');
}
/// update repoImpl.dart to add imports statement and function signature
String destinationPathRepoImpl =
PathHandler().getRepoImplPath(featureName: featureName);
if (Utility.doesFileExist(filePath: destinationPathRepoImpl)) {
List<String> importRepoImplStatements = [
PathHandler().getDartzImport(featureName: featureName),
PathHandler().getApiResponsePath(),
PathHandler().getFailureImport(featureName: featureName),
PathHandler().getSuccessImport(featureName: featureName),
];
if (responseModelName.isNotEmpty) {
importRepoImplStatements.add(PathHandler()
.getRepoImplResponseModelImport(
featureName: featureName,
responseModelName: responseModelName));
}
List<String> repoImplAppendLines = [];
if (requestModelName.isNotEmpty) {
importRepoImplStatements.add(PathHandler()
.getRequestModelImport(featureName: featureName, apiName: apiName));
repoImplAppendLines = CodeHandler()
.getRepoImplStatementWithRequestModel(
pascalCaseApiName: pascalCaseApiName,
requestModelName: requestModelName);
} else {
repoImplAppendLines = CodeHandler()
.getRepoImplStatementWithoutRequestModel(
pascalCaseApiName: pascalCaseApiName);
}
if (responseModelName.isNotEmpty) {
repoImplAppendLines.add(CodeHandler().getRepoStatementWithResponseModel(
responseModelName: responseModelName));
} else {
repoImplAppendLines
.add(CodeHandler().getRepoStatementWithoutResponseModel());
}
await fileUpdate(destinationPathRepoImpl, importRepoImplStatements,
repoImplAppendLines);
Utility.successPrinter(text: '$kApiCodeUpdate $kRepoImpl $kFile');
}
/// update mockRepoImpl.dart to add imports statement and function signature
String destinationPathMockRepoImpl =
PathHandler().getMockRepoImplPath(featureName: featureName);
if (Utility.doesFileExist(filePath: destinationPathMockRepoImpl)) {
List<String> importMockRepoImplStatements = [
PathHandler().getDartzImport(featureName: featureName),
PathHandler().getApiResponsePath(),
PathHandler().getFailureImport(featureName: featureName),
PathHandler().getSuccessImport(featureName: featureName),
PathHandler().getMockApiConstantImport(featureName: featureName),
];
if (responseModelName.isNotEmpty) {
importMockRepoImplStatements.add(PathHandler().getResponseModelImport(
featureName: featureName, responseModelName: responseModelName));
}
List<String> mockRepoImplAppendLines = [];
if (requestModelName.isNotEmpty) {
importMockRepoImplStatements.add(PathHandler()
.getRequestModelImport(featureName: featureName, apiName: apiName));
mockRepoImplAppendLines = CodeHandler()
.getMockRepoImplStatementWithRequestModel(
pascalCaseApiName: pascalCaseApiName,
requestModelName: requestModelName,
apiName: apiName);
} else {
mockRepoImplAppendLines = CodeHandler()
.getMockRepoImplStatementWithoutRequestModel(
pascalCaseApiName: pascalCaseApiName, apiName: apiName);
}
if (responseModelName.isNotEmpty) {
mockRepoImplAppendLines.add(CodeHandler()
.getMockRepoStatementWithResponseModel(
responseModelName: responseModelName));
} else {
mockRepoImplAppendLines
.add(CodeHandler().getMockRepoStatementWithoutResponseModel());
}
await fileUpdate(destinationPathMockRepoImpl,
importMockRepoImplStatements, mockRepoImplAppendLines);
Utility.successPrinter(text: '$kApiCodeUpdate $kMockRepoImpl $kFile');
}
}