Skip to content

Commit

Permalink
refactor: ♻️ some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Jul 18, 2023
1 parent 21a10f5 commit ea5f0c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="all" Condition="$(MSBuildProjectExtension) == '.csproj'"/>
<PackageReference Include="AsyncFixer" PrivateAssets="all" Condition="$(MSBuildProjectExtension) == '.csproj'"/>
<PackageReference Include="AsyncAwaitBestPractices" PrivateAssets="all" Condition="$(MSBuildProjectExtension) == '.csproj'"/>
<PackageReference Include="StackExchange.Redis.Analyzer" PrivateAssets="all" Condition="$(MSBuildProjectExtension) == '.csproj'"/>
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<PackageVersion Include="SmartanAlyzers.ExceptionAnalyzer" Version="1.0.10" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.354" />
<PackageVersion Include="AsyncAwaitBestPractices" Version="6.0.6" />
<PackageVersion Include="StackExchange.Redis.Analyzer" Version="1.3.3" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="MassTransit" Version="8.0.14" />
Expand Down
5 changes: 4 additions & 1 deletion src/Vertical.Slice.Template.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.AspNetCore": "Warning",
"System": "Warning"
"System": "Warning",
"MassTransit": "Debug",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning",
"Microsoft.EntityFrameworkCore": "Warning"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Globalization;
using System.Net.Http.Json;
using AutoMapper;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Options;
using Vertical.Slice.Template.Shared.Clients.Users.Dtos;
using Vertical.Slice.Template.Shared.Core.Paging;
Expand Down Expand Up @@ -30,9 +32,16 @@ IOptions<UsersHttpClientOptions> userHttpClientOptions
CancellationToken cancellationToken = default
)
{
// https://stackoverflow.com/a/67877742/581476
var qb = new QueryBuilder
{
{ "limit", pageRequest.PageSize.ToString(CultureInfo.InvariantCulture) },
{ "skip", pageRequest.PageNumber.ToString(CultureInfo.InvariantCulture) },
};

// https://github.com/App-vNext/Polly#handing-return-values-and-policytresult
var httpResponse = await _httpClient.GetAsync(
$"{_userHttpClientOptions.UsersEndpoint}?limit={pageRequest.PageSize}&skip={pageRequest.PageNumber}",
$"{_userHttpClientOptions.UsersEndpoint}?{qb.ToQueryString().Value}",
cancellationToken
);

Expand All @@ -48,7 +57,7 @@ IOptions<UsersHttpClientOptions> userHttpClientOptions
throw new Exception("users page list cannot be null");

var mod = usersListPage.Total % usersListPage.Limit;
var totalPageCount = usersListPage.Total / usersListPage.Limit + (mod == 0 ? 0 : 1);
var totalPageCount = (usersListPage.Total / usersListPage.Limit) + (mod == 0 ? 0 : 1);

var items = _mapper.Map<IEnumerable<User>>(usersListPage.Users);

Expand Down

0 comments on commit ea5f0c6

Please sign in to comment.