createDomainUseCase method

void createDomainUseCase(
  1. String pathPage,
  2. String pageName,
  3. String apiName,
  4. bool bodyList,
  5. bool responseList,
)

Implementation

void createDomainUseCase(
  String pathPage,
  String pageName,
  String apiName,
  bool bodyList,
  bool responseList,
) {
  final pageClassName = pageName.pascalCase;
  final apiClassName = apiName.pascalCase;
  final apiMethodName = apiName.camelCase;

  final path = join(pathPage, 'domain', 'usecases');
  DirectoryHelper.createDir(path);

  final bodyClass = getBodyClass(apiClassName, bodyList);
  final entityClass = getEntityClass(apiClassName, responseList);

  join(path, '${apiName}_use_case.dart')
      .write('''import 'package:core/core.dart';

import '../../data/models/body/${apiName}_body.dart';
import '../entities/${apiName}_entity.dart';
import '../repositories/${pageName}_repository.dart';

class ${apiClassName}UseCase implements UseCase<$entityClass, $bodyClass> {
${apiClassName}UseCase({
  required this.repository,
});

final ${pageClassName}Repository repository;

@override
Future<Either<MorphemeFailure, $entityClass>> call($bodyClass body,{Map<String, String>? headers,}) {
  return repository.$apiMethodName(body, headers: headers);
}
}''');

  StatusHelper.generated(join(path, '${apiName}_use_case.dart'));
}