Skip to content

Commit

Permalink
chore: Refactor RouterService.cs to improve routing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Jun 17, 2024
1 parent b2df95d commit 62caebc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Stars.Services/Router/RouterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ public async Task<object> RouteAsync(IResource route, int recursivity, IRouter p
// Execute the function for the item and return;
return await onItemFunction.Invoke(itemNode, prevRouter, state, ct);
}
// If route is a Collection
if (route is ICollection collectionNode)
{
// Execute the function for the collection and return;
return await onCollectionFunction.Invoke(collectionNode, prevRouter, state, ct);
}
// Ask the router manager if there is another router available for this route
router = await routersManager.GetRouterAsync(route);
// Definitively impossible to Route
Expand All @@ -88,8 +82,8 @@ public async Task<object> RouteAsync(IResource route, int recursivity, IRouter p
// If route is a Collection
if (newRoute is ICollection)
{
// Execute the function for the collection and return;
return await onCollectionFunction.Invoke(newRoute as ICollection, prevRouter, state, ct);
// Execute the function for the collection
await onCollectionFunction.Invoke(newRoute as ICollection, prevRouter, state, ct);
}

catalogNode = newRoute as ICatalog;
Expand All @@ -103,6 +97,12 @@ public async Task<object> RouteAsync(IResource route, int recursivity, IRouter p
}
else
{
// If route is a Collection
if (catalogNode is ICollection)
{
// Execute the function for the collection
await onCollectionFunction.Invoke(catalogNode as ICollection, router, state, ct);
}
// If the resource is a catalog, we keep the previous router
router = prevRouter;
}
Expand Down

0 comments on commit 62caebc

Please sign in to comment.