setupRequestData static method

RequestModel setupRequestData()

Implementation

static RequestModel setupRequestData() {
  RequestModel requestModel = RequestModel();

  while (requestModel.featureName.isEmpty) {
    stdout.write("Enter your feature name : ");
    requestModel.featureName = (stdin.readLineSync() ?? "")
        .trim()
        .checkIfEmptyAndNullAndShowMessage(
            "😢 Feature name cannot be empty !!");
  }

  while (requestModel.modelName.isEmpty) {
    stdout.write(
        "Enter your model name [ thunder will add 'model' keyword by default ] : ");
    requestModel.modelName = (stdin.readLineSync() ?? "")
        .trim()
        .checkIfEmptyAndNullAndShowMessage(
            "😢 Model Name name cannot be empty !!")
        .replaceAll("model", "");
  }

  while (requestModel.requestType == null) {
    stdout.write("Enter type of request [ get / post / put / delete ] : ");
    requestModel.requestType = getRequestType(stdin.readLineSync() ?? "");
  }

  while (requestModel.url.isEmpty) {
    stdout.write("Enter your full url : ");
    requestModel.url = (stdin.readLineSync() ?? "")
        .trim()
        .checkIfEmptyAndNullAndShowMessage(" Url cannot be empty !!");
  }

  stdout.write("Enter your request body : ");
  String bodyString = stdin.readLineSync() ?? "";
  requestModel.body = bodyString.isEmpty ? {} : jsonDecode(bodyString);

  stdout.write("Enter your request headers : ");
  String headersString = stdin.readLineSync() ?? "";
  requestModel.headers =
      headersString.isEmpty ? {} : jsonDecode(headersString);

  stdout.write("Enter your request params : ");
  String paramsString = stdin.readLineSync() ?? "";
  requestModel.params = paramsString.isEmpty ? {} : jsonDecode(paramsString);

  print(
      "Thunder is creating your model file . please wait for seconds 🔃\n\n\n");
  return requestModel;
}