Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed Aug 3, 2022
2 parents 86d7caa + 66bfc8e commit 8b58ec0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to **LightQuery** are documented here.

## v2.2.1:
- Added an optional parameter to the LightQuery client for Angular to supply custom query parameters when calling `getAll()`

## v2.2.0:
- Added a dedicated target for .NET 6 for the Entity Framework Core projects
- Added tests for .NET 6
Expand Down
8 changes: 4 additions & 4 deletions build/.build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace></RootNamespace>
<IsPackable>False</IsPackable>
Expand All @@ -12,11 +12,11 @@

<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.10.3]" />
<PackageReference Include="Nuke.Common" Version="6.1.1" />
<PackageReference Include="Nuke.WebDocu" Version="4.0.0" />
<PackageReference Include="Nuke.Common" Version="6.1.2" />
<PackageReference Include="Nuke.WebDocu" Version="4.0.1" />
<PackageReference Include="Nuke.GitHub" Version="3.0.0" />
<PackageReference Include="ReportGenerator" Version="5.1.9" />
<PackageReference Include="docfx.console" Version="2.59.2">
<PackageReference Include="docfx.console" Version="2.59.3">
<ExcludeAssets>build</ExcludeAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; native; contentfiles; analyzers</IncludeAssets>
Expand Down
3 changes: 3 additions & 0 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void SendTeamsMessage(string title, string message, bool isError)
DotNetBuild(x => x
.SetConfiguration(Configuration)
.EnableNoRestore()
.SetProcessArgumentConfigurator(a => a.Add("-nodereuse:false"))
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetAssemblyVersion($"{GitVersion.Major}.{GitVersion.Minor}.{GitVersion.Patch}.0")
.SetInformationalVersion(GitVersion.InformationalVersion));
Expand Down Expand Up @@ -173,7 +174,9 @@ void SendTeamsMessage(string title, string message, bool isError)
.SetLoggers($"xunit;LogFilePath={OutputDirectory / projectName}_testresults-{targetFramework}.xml")
.SetCoverletOutput($"{OutputDirectory / projectName}_coverage.xml")
.SetProcessArgumentConfigurator(a => a
.Add("-nodereuse:false")
.Add($"/p:Include=[LightQuery*]*")
.Add($"/p:Exclude=[*Test*]*")
.Add($"/p:ExcludeByAttribute=\\\"Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute\\\"")
// This part is required to ensure that xUnit isn't using app domains or shadow copying, since coverlet
// needs to modify the dlls to collect coverage. See here for more information:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,36 @@ describe('PaginationBaseService', () => {
expect(returnedResult[1].id).toBe(2);
}));

it('makes multiple requests when calling getAll with addition params', async(async () => {
let service = getService();
service.baseUrl = '/users';
await delay(1);
const getAllPromise = service.getAll({ userName: 'Alice' }).toPromise();

await delay(1);
let httpMock = getHttpMock();
let req = httpMock.expectOne('/users?page=1&pageSize=500&userName=Alice');
expect(req.request.method).toBe('GET');
const response: PaginationResult<User> = {
page: 1,
pageSize: 1,
totalCount: 1,
data: [{ id: 1, userName: 'Alice' }],
};
req.flush(response);

await delay(1);
req = httpMock.expectOne('/users?page=2&pageSize=500&userName=Alice');
expect(req.request.method).toBe('GET');
req.flush(response);

const returnedResult = await getAllPromise;
expect(returnedResult.length).toBe(1);

expect(returnedResult[0].id).toBe(1);
expect(returnedResult[0].userName).toBe('Alice');
}));

it('does not emit result on error response', async(async () => {
let hasReceivedResponse = false;
let service = getService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,20 @@ export abstract class PaginationBaseService<T> {
return url;
}

getAll(): Observable<T[]> {
getAll(additionalQueryParams?: { [name: string]: string }): Observable<T[]> {
if (!this.baseUrl) {
return of(null);
}
let hasMore = true;
let currentPage = 1;
const listResultAll: T[] = [];
const listResultAllSource = new Subject<T[]>();
let addFilter = '';
if (additionalQueryParams) {
addFilter = Object.keys(additionalQueryParams)
.map((name) => `&${name}=${additionalQueryParams[name]}`)
.join('');
}

const getData = () => {
if (!hasMore) {
Expand All @@ -176,7 +182,7 @@ export abstract class PaginationBaseService<T> {
return;
}

const url = this.buildUrlAll(currentPage++);
const url = this.buildUrlAll(currentPage++) + addFilter;
this.http.get<PaginationResult<T>>(url).subscribe((c) => {
if (c.page !== currentPage - 1) {
hasMore = false;
Expand Down

0 comments on commit 8b58ec0

Please sign in to comment.