handleApi method

Future<void> handleApi({
  1. required String featureName,
  2. required String featurePath,
  3. required String pageName,
  4. required String pathPage,
  5. required String apiName,
  6. required dynamic body,
  7. required dynamic response,
  8. required String? method,
  9. required String pathUrl,
  10. required List<String> paramPath,
  11. required String? header,
  12. required bool isBodyList,
  13. required bool isResponseList,
  14. required String? cacheStrategy,
  15. required int? ttl,
  16. required bool? keepExpiredCache,
  17. required String? appsName,
})

Implementation

Future<void> handleApi({
  required String featureName,
  required String featurePath,
  required String pageName,
  required String pathPage,
  required String apiName,
  required dynamic body,
  required dynamic response,
  required String? method,
  required String pathUrl,
  required List<String> paramPath,
  required String? header,
  required bool isBodyList,
  required bool isResponseList,
  required String? cacheStrategy,
  required int? ttl,
  required bool? keepExpiredCache,
  required String? appsName,
}) async {
  if (body != null) {
    createDataModelBody(
      pathPage,
      pageName,
      apiName,
      body,
      (method ?? '').toLowerCase().contains('multipart'),
      paramPath,
    );
  }

  if (response != null) {
    createDataModelResponse(pathPage, pageName, apiName, response);
    createDomainEntity(pathPage, pageName, apiName, response);
    appendMapper(pathPage, apiName, response);
  }

  final argBody = isBodyList ? '--body-list' : '--no-body-list';
  final argResponse =
      isResponseList ? '--response-list' : '--no-response-list';

  final argCacheStrategy = cacheStrategy == null
      ? ''
      : '--cache-strategy=$cacheStrategy${ttl == null ? '' : ' --ttl=$ttl'}${keepExpiredCache == null ? '' : ' --keep-expired-cache=$keepExpiredCache'}';

  final argAppsName = appsName != null ? '-a "$appsName"' : '';

  if (isApi) {
    await 'morpheme api $apiName -f $featureName -p $pageName  --json2dart --method=$method --path=$pathUrl ${header != null ? '--header=$header' : ''} $argBody $argResponse $argCacheStrategy $argAppsName'
        .run;
  }
}