Skip to content

Commit

Permalink
- Checkpoint: Core Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
NinjaRocks committed Nov 2, 2024
1 parent d8d26ff commit e0c9f2e
Show file tree
Hide file tree
Showing 66 changed files with 1,552 additions and 265 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
`ApiAggregator` is a .net utility to help combine multiple api requests to return a single aggregated response. The framework allows conditionally including a subset of configured apis to return responses.

#### Extends `Schemio` for APIs
ApiAggregator uses `Schemio` to extend support for apis to configure hierarchical graph of `query`/`transformer` pairs to return aggregated data in a single response.
ApiAggregator uses `Schemio` to extend support for apis to configure hierarchical graph of `api`/`transformer` pairs to return aggregated data in a single response.
> You can read on [Schemio](https://github.com/CodeShayk/Schemio) for more details on the core functionality.
Please see appendix for schemio implementation in ApiAggregator.

Expand Down
22 changes: 22 additions & 0 deletions src/ApiAggregator/ApiAggregate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace ApiAggregator.Net
{
/// <summary>
/// Implement the api aggregate with web apis and result transformers to map data to aggregated contract.
/// </summary>
/// <typeparam name="TContract">Aggregated Contract</typeparam>
public abstract class ApiAggregate<TContract> : IApiAggregate<TContract> where TContract : IContract
{
public IEnumerable<Mapping<TContract, IApiResult>> Mappings { get; }

public ApiAggregate()
{
Mappings = Construct();
}

/// <summary>
/// Implement to configure mappings with Apis & result transformers.
/// </summary>
/// <returns>Entity Schema mappings</returns>
public abstract IEnumerable<Mapping<TContract, IApiResult>> Construct();
}
}
1 change: 0 additions & 1 deletion src/ApiAggregator/ApiAggregator.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageReference Include="Schemio.Core" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/ApiAggregator/ApiComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ApiAggregator.Net
{
internal class ApiComparer : IEqualityComparer<IWebApi>
{
#region IApi

public bool Equals(IWebApi x, IWebApi y) => x.GetType() == y.GetType();

Check warning on line 7 in src/ApiAggregator/ApiComparer.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'x' of 'bool ApiComparer.Equals(IWebApi x, IWebApi y)' doesn't match implicitly implemented member 'bool IEqualityComparer<IWebApi>.Equals(IWebApi? x, IWebApi? y)' (possibly because of nullability attributes).

Check warning on line 7 in src/ApiAggregator/ApiComparer.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'y' of 'bool ApiComparer.Equals(IWebApi x, IWebApi y)' doesn't match implicitly implemented member 'bool IEqualityComparer<IWebApi>.Equals(IWebApi? x, IWebApi? y)' (possibly because of nullability attributes).

public int GetHashCode(IWebApi obj) => obj.GetType().GetHashCode();

#endregion IApi
}
}
60 changes: 60 additions & 0 deletions src/ApiAggregator/ApiList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace ApiAggregator.Net
{
internal class ApiList : IApiList
{
private readonly List<IWebApi> apiList;

public ApiList()
{
apiList = new List<IWebApi>();
}

public IEnumerable<IWebApi> Apis
{ get { return apiList; } }

public ApiList(IEnumerable<IWebApi> collection)
{
apiList = new List<IWebApi>(collection);
}

public int ApiNestingDepth { get; set; }

public IApiList GetByType<T>() where T : class
{
var apis = apiList.Where(q => q as T != null);
return new ApiList(apis);
}

public List<T> As<T>() => apiList.Cast<T>().ToList();

public List<NestedApiList> GetChildrenApis()
{
var childrenApis = apiList
.Select(x => new NestedApiList { ParentApiResultType = x.ResultType, Apis = x.Children })
.Where(x => x.Apis != null && x.Apis.Any())
.ToList();

return childrenApis
.Select(x =>
{
var distinctList = childrenApis
.Where(d => d.ParentApiResultType == x.ParentApiResultType)
.SelectMany(q => q.Apis)
.Distinct(new ApiComparer())
.ToList();

return new NestedApiList { ParentApiResultType = x.ParentApiResultType, Apis = distinctList };
})
.ToList();
}

public new int Count() => apiList.Count;

Check warning on line 51 in src/ApiAggregator/ApiList.cs

View workflow job for this annotation

GitHub Actions / build

The member 'ApiList.Count()' does not hide an accessible member. The new keyword is not required.

public bool IsEmpty() => !apiList.Any();

public void AddRange(IEnumerable<IWebApi> collection)
{
apiList.AddRange(collection);
}
}
}
18 changes: 18 additions & 0 deletions src/ApiAggregator/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// In SDK-style projects such as this one, several assembly attributes that were historically
// defined in this file are now automatically added during build and populated with
// values defined in project properties. For details of which attributes are included
// and how to customise this process see: https://aka.ms/assembly-info-properties

// Setting ComVisible to false makes the types in this assembly not visible to COM
// components. If you need to access a type in this assembly from COM, set the ComVisible
// attribute to true on that type.

[assembly: ComVisible(false)]
[assembly: InternalsVisibleTo("ApiAggregator.Net.Tests")]

// The following GUID is for the ID of the typelib if this project is exposed to COM.

[assembly: Guid("5188e472-36fc-4e3c-8a49-17d5e32c9ee8")]
157 changes: 0 additions & 157 deletions src/ApiAggregator/BaseWebQuery.cs

This file was deleted.

5 changes: 5 additions & 0 deletions src/ApiAggregator/CacheResultAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace ApiAggregator.Net
{
public class CacheResultAttribute : Attribute
{ }
}
9 changes: 9 additions & 0 deletions src/ApiAggregator/CollectionResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ApiAggregator.Net
{
public class CollectionResult<T> : List<T>, IApiResult
{
public CollectionResult(IEnumerable<T> list) : base(list)
{
}
}
}
13 changes: 0 additions & 13 deletions src/ApiAggregator/ColonSeparatedMatcher.cs

This file was deleted.

Loading

0 comments on commit e0c9f2e

Please sign in to comment.