Skip to content

Commit e0c9f2e

Browse files
committed
- Checkpoint: Core Implementation
1 parent d8d26ff commit e0c9f2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1552
-265
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
`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.
1111

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

src/ApiAggregator/ApiAggregate.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace ApiAggregator.Net
2+
{
3+
/// <summary>
4+
/// Implement the api aggregate with web apis and result transformers to map data to aggregated contract.
5+
/// </summary>
6+
/// <typeparam name="TContract">Aggregated Contract</typeparam>
7+
public abstract class ApiAggregate<TContract> : IApiAggregate<TContract> where TContract : IContract
8+
{
9+
public IEnumerable<Mapping<TContract, IApiResult>> Mappings { get; }
10+
11+
public ApiAggregate()
12+
{
13+
Mappings = Construct();
14+
}
15+
16+
/// <summary>
17+
/// Implement to configure mappings with Apis & result transformers.
18+
/// </summary>
19+
/// <returns>Entity Schema mappings</returns>
20+
public abstract IEnumerable<Mapping<TContract, IApiResult>> Construct();
21+
}
22+
}

src/ApiAggregator/ApiAggregator.Net.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
<ItemGroup>
3838
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.1" />
39-
<PackageReference Include="Schemio.Core" Version="1.0.0" />
4039
</ItemGroup>
4140

4241
<ItemGroup>

src/ApiAggregator/ApiComparer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace ApiAggregator.Net
2+
{
3+
internal class ApiComparer : IEqualityComparer<IWebApi>
4+
{
5+
#region IApi
6+
7+
public bool Equals(IWebApi x, IWebApi y) => x.GetType() == y.GetType();
8+
9+
public int GetHashCode(IWebApi obj) => obj.GetType().GetHashCode();
10+
11+
#endregion IApi
12+
}
13+
}

src/ApiAggregator/ApiList.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace ApiAggregator.Net
2+
{
3+
internal class ApiList : IApiList
4+
{
5+
private readonly List<IWebApi> apiList;
6+
7+
public ApiList()
8+
{
9+
apiList = new List<IWebApi>();
10+
}
11+
12+
public IEnumerable<IWebApi> Apis
13+
{ get { return apiList; } }
14+
15+
public ApiList(IEnumerable<IWebApi> collection)
16+
{
17+
apiList = new List<IWebApi>(collection);
18+
}
19+
20+
public int ApiNestingDepth { get; set; }
21+
22+
public IApiList GetByType<T>() where T : class
23+
{
24+
var apis = apiList.Where(q => q as T != null);
25+
return new ApiList(apis);
26+
}
27+
28+
public List<T> As<T>() => apiList.Cast<T>().ToList();
29+
30+
public List<NestedApiList> GetChildrenApis()
31+
{
32+
var childrenApis = apiList
33+
.Select(x => new NestedApiList { ParentApiResultType = x.ResultType, Apis = x.Children })
34+
.Where(x => x.Apis != null && x.Apis.Any())
35+
.ToList();
36+
37+
return childrenApis
38+
.Select(x =>
39+
{
40+
var distinctList = childrenApis
41+
.Where(d => d.ParentApiResultType == x.ParentApiResultType)
42+
.SelectMany(q => q.Apis)
43+
.Distinct(new ApiComparer())
44+
.ToList();
45+
46+
return new NestedApiList { ParentApiResultType = x.ParentApiResultType, Apis = distinctList };
47+
})
48+
.ToList();
49+
}
50+
51+
public new int Count() => apiList.Count;
52+
53+
public bool IsEmpty() => !apiList.Any();
54+
55+
public void AddRange(IEnumerable<IWebApi> collection)
56+
{
57+
apiList.AddRange(collection);
58+
}
59+
}
60+
}

src/ApiAggregator/AssemblyInfo.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Runtime.InteropServices;
3+
4+
// In SDK-style projects such as this one, several assembly attributes that were historically
5+
// defined in this file are now automatically added during build and populated with
6+
// values defined in project properties. For details of which attributes are included
7+
// and how to customise this process see: https://aka.ms/assembly-info-properties
8+
9+
// Setting ComVisible to false makes the types in this assembly not visible to COM
10+
// components. If you need to access a type in this assembly from COM, set the ComVisible
11+
// attribute to true on that type.
12+
13+
[assembly: ComVisible(false)]
14+
[assembly: InternalsVisibleTo("ApiAggregator.Net.Tests")]
15+
16+
// The following GUID is for the ID of the typelib if this project is exposed to COM.
17+
18+
[assembly: Guid("5188e472-36fc-4e3c-8a49-17d5e32c9ee8")]

src/ApiAggregator/BaseWebQuery.cs

Lines changed: 0 additions & 157 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace ApiAggregator.Net
2+
{
3+
public class CacheResultAttribute : Attribute
4+
{ }
5+
}

src/ApiAggregator/CollectionResult.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace ApiAggregator.Net
2+
{
3+
public class CollectionResult<T> : List<T>, IApiResult
4+
{
5+
public CollectionResult(IEnumerable<T> list) : base(list)
6+
{
7+
}
8+
}
9+
}

src/ApiAggregator/ColonSeparatedMatcher.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)