createDomainRepository method
void
createDomainRepository()
Implementation
void createDomainRepository(
String pathPage,
String pageName,
String apiName,
bool bodyList,
bool responseList,
) {
final apiClassName = apiName.pascalCase;
final apiMethodName = apiName.camelCase;
final path = join(pathPage, 'domain', 'repositories');
DirectoryHelper.createDir(path);
final bodyClass = getBodyClass(apiClassName, bodyList);
final entityClass = getEntityClass(apiClassName, responseList);
if (!exists(join(path, '${pageName}_repository.dart'))) {
join(path, '${pageName}_repository.dart')
.write('''import 'package:core/core.dart';
import '../../data/models/body/${apiName}_body.dart';
import '../entities/${apiName}_entity.dart';
abstract class ${pageName.pascalCase}Repository {
Future<Either<MorphemeFailure, $entityClass>> $apiMethodName($bodyClass body,{Map<String, String>? headers,});
}''');
} else {
String data =
File(join(path, '${pageName}_repository.dart')).readAsStringSync();
data = data.replaceAll(
RegExp(r"import\s?'package:core\/core.dart';\n?\n?", multiLine: true),
'''import 'package:core/core.dart';
import '../../data/models/body/${apiName}_body.dart';
import '../entities/${apiName}_entity.dart';''');
data = data.replaceAll(RegExp(r'}$', multiLine: true),
''' Future<Either<MorphemeFailure, $entityClass>> $apiMethodName($bodyClass body,{Map<String, String>? headers,});
}''');
join(path, '${pageName}_repository.dart').write(data);
}
StatusHelper.generated(join(path, '${pageName}_repository.dart'));
}