isMyPath method

bool isMyPath()

Implementation

bool isMyPath() {
  String? myPathTemplate = routingEntity.pathTemplate;
  HttpMethod myMethod = routingEntity.method;
  // this will check if the request path is my path or not
  // this will deal with links like that "/users/<user_id>/getInfo" => this is the path template
  //                                     "/users/159875655/getInfo" => this is the path itself
  // this should make sure that the template and the actual path are the same so this RoutingEntity function will be executed on it
  myPathTemplate ??= askedPath;
  bool allMethod = myMethod == HttpMethods.all;
  myMethod = allMethod ? askedMethod : myMethod;

  // checking if the method is mine
  if (myMethod != askedMethod) {
    return false;
  }

  // checking if the path is mine
  List<String> actualLinkParts = askedPath.split('/');
  List<String> templateParts = myPathTemplate.split('/');
  // check for the last part if it contains an * to return true

  if ((actualLinkParts.length != templateParts.length) &&
      !templateParts.last.contains('*')) {
    // if they don't contain the same amount of parts for each link then not the intended path
    return false;
  }
  for (var i = 0; i < actualLinkParts.length; i++) {
    String tempPart = templateParts[i];
    if (tempPart.contains('*')) {
      return true;
    }
    String pathPart = actualLinkParts[i];
    bool isPlaceHolder = _isPlaceHolder(tempPart);
    if (!isPlaceHolder && tempPart != pathPart) {
      return false;
    }
  }

  return true;
}