Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v 0.12.0 #196

Merged
merged 21 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
15a54ab
Add common and database project to same repository
SSchulze1989 Apr 13, 2024
bfc621c
update workflows
SSchulze1989 Apr 13, 2024
c359f6d
fix missing Test configurations
SSchulze1989 Apr 13, 2024
d5bebf4
Merge pull request #191 from SSchulze1989/feature/include-dependend-r…
SSchulze1989 Apr 14, 2024
cb44fab
Fix location dependency on auth checks
SSchulze1989 May 22, 2024
6017866
Model changes for override option on dropweeks
SSchulze1989 May 15, 2024
7464499
Refactoring: Implement IRequestHandler on handler base directly
SSchulze1989 Apr 27, 2024
02eb793
Implement handler for fetching dropweek overrides
SSchulze1989 May 15, 2024
f9c8f0f
Consider dropweek overrides while calculating standings
SSchulze1989 May 29, 2024
777a029
Merge pull request #193 from SSchulze1989/feature/select-drop-weeks
SSchulze1989 May 29, 2024
04f786c
Update actions to upload packages to Nuget directly
SSchulze1989 May 29, 2024
3ed430a
Update package license and readme information
SSchulze1989 May 29, 2024
5f169f8
Fix location dependency for login token generation
SSchulze1989 Jun 7, 2024
5835217
Add handling for modifying raw result rows
SSchulze1989 Jul 10, 2024
eac4d33
Add client endpoint for modifying results
SSchulze1989 Jul 10, 2024
669485b
Add endpoint for getting raw event results
SSchulze1989 Jul 11, 2024
931be28
Add default jsonOptions during service intialization
SSchulze1989 Jul 12, 2024
49a662b
remove custom TimeSpan json converter and use default
SSchulze1989 Jul 12, 2024
4ff587e
Add missing properties to raw result row
SSchulze1989 Jul 12, 2024
9f18339
Merge pull request #195 from SSchulze1989/feature/modify-raw-results
SSchulze1989 Jul 12, 2024
dee0ecf
bump version to 0.12.0
SSchulze1989 Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .github/workflows/dotnet_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
env:
BUILD_CONFIG: Debug
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
TEST_USER: root
TEST_PASSWORD: TestPass123
TEST_DATABASE: TestDatabase
DB_TEST_PROJECT: test/DbIntegrationTests

runs-on: ubuntu-latest

Expand All @@ -21,6 +25,15 @@ jobs:
with:
dotnet-version: 6.0.x
source-url: https://nuget.pkg.github.com/SSchulze1989/index.json
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
# Required if "mysql user" is empty, default is empty. The root superuser password
mysql root password: $TEST_PASSWORD
# MYSQL_DATABASE - name for the default database that is created
mysql database: $TEST_DATABASE
- name: Set secrets
run: dotnet user-secrets set "ConnectionStrings:ModelDb" "server=localhost;database=$TEST_DATABASE;user=$TEST_USER;password=$TEST_PASSWORD" --project $DB_TEST_PROJECT
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/dotnet_main_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
env:
BUILD_CONFIG: Release
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
TEST_USER: root
TEST_PASSWORD: TestPass123
TEST_DATABASE: TestDatabase
DB_TEST_PROJECT: test/DbIntegrationTests

runs-on: ubuntu-latest

Expand All @@ -19,6 +23,15 @@ jobs:
with:
dotnet-version: 6.0.x
source-url: https://nuget.pkg.github.com/SSchulze1989/index.json
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
# Required if "mysql user" is empty, default is empty. The root superuser password
mysql root password: $TEST_PASSWORD
# MYSQL_DATABASE - name for the default database that is created
mysql database: $TEST_DATABASE
- name: Set secrets
run: dotnet user-secrets set "ConnectionStrings:ModelDb" "server=localhost;database=$TEST_DATABASE;user=$TEST_USER;password=$TEST_PASSWORD" --project $DB_TEST_PROJECT
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/dotnet_main_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
env:
BUILD_CONFIG: Release
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
TEST_USER: root
TEST_PASSWORD: TestPass123
TEST_DATABASE: TestDatabase
DB_TEST_PROJECT: test/DbIntegrationTests

runs-on: ubuntu-latest

Expand All @@ -19,6 +23,15 @@ jobs:
with:
dotnet-version: 6.0.x
source-url: https://nuget.pkg.github.com/SSchulze1989/index.json
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
# Required if "mysql user" is empty, default is empty. The root superuser password
mysql root password: $TEST_PASSWORD
# MYSQL_DATABASE - name for the default database that is created
mysql database: $TEST_DATABASE
- name: Set secrets
run: dotnet user-secrets set "ConnectionStrings:ModelDb" "server=localhost;database=$TEST_DATABASE;user=$TEST_USER;password=$TEST_PASSWORD" --project $DB_TEST_PROJECT
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
19 changes: 16 additions & 3 deletions .github/workflows/dotnet_tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ jobs:
publish:
env:
BUILD_CONFIG: Release
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
NUGET_AUTH_TOKEN: ${{secrets.NUGET_TOKEN}}
TEST_USER: root
TEST_PASSWORD: TestPass123
TEST_DATABASE: TestDatabase
DB_TEST_PROJECT: test/DbIntegrationTests

runs-on: ubuntu-latest

Expand All @@ -19,12 +23,21 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
source-url: https://nuget.pkg.github.com/SSchulze1989/index.json
source-url: https://api.nuget.org/v3/index.json
- name: Setup MySQL
uses: mirromutth/[email protected]
with:
# Required if "mysql user" is empty, default is empty. The root superuser password
mysql root password: $TEST_PASSWORD
# MYSQL_DATABASE - name for the default database that is created
mysql database: $TEST_DATABASE
- name: Set secrets
run: dotnet user-secrets set "ConnectionStrings:ModelDb" "server=localhost;database=$TEST_DATABASE;user=$TEST_USER;password=$TEST_PASSWORD" --project $DB_TEST_PROJECT
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c $BUILD_CONFIG --no-restore
- name: Test
run: dotnet test -c $BUILD_CONFIG --no-build --verbosity normal
- name: Publish
run: dotnet nuget push **\*.nupkg --skip-duplicate
run: dotnet nuget push **\*.nupkg --skip-duplicate -k ${NUGET_AUTH_TOKEN}
32 changes: 31 additions & 1 deletion iRLeagueApiCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueApiCore.Services",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueApiCore.Services.Tests", "test\iRLeagueApiCore.Services.Tests\iRLeagueApiCore.Services.Tests.csproj", "{DB449DBD-703D-45F0-B935-6876F81516D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iRLeagueApiCore.Mocking", "test\iRLeagueApiCore.Mocking\iRLeagueApiCore.Mocking\iRLeagueApiCore.Mocking.csproj", "{84F0108C-30A3-4CF1-9F03-EC4DDC979E7B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueApiCore.Mocking", "test\iRLeagueApiCore.Mocking\iRLeagueApiCore.Mocking\iRLeagueApiCore.Mocking.csproj", "{84F0108C-30A3-4CF1-9F03-EC4DDC979E7B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueApiCore.Common", "src\iRLeagueApiCore.Common\iRLeagueApiCore.Common.csproj", "{E9639AF9-8C03-4B30-AA3B-B85873D0C406}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueDatabaseCore", "src\iRLeagueDatabaseCore\iRLeagueDatabaseCore.csproj", "{374D9358-C654-4882-AE9F-89DDB135A69D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iRLeagueDatabaseCore.Migrations", "src\iRLeagueDatabaseCore.Migrations\iRLeagueDatabaseCore.Migrations.csproj", "{C335B0B3-B0AE-45EF-B620-87E9EBE257D3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbIntegrationTests", "test\DbIntegrationTests\DbIntegrationTests.csproj", "{CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "test\UnitTests\UnitTests.csproj", "{FB4E0FC3-97A9-4456-93DB-F8335175FA47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -59,6 +69,26 @@ Global
{84F0108C-30A3-4CF1-9F03-EC4DDC979E7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84F0108C-30A3-4CF1-9F03-EC4DDC979E7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84F0108C-30A3-4CF1-9F03-EC4DDC979E7B}.Release|Any CPU.Build.0 = Release|Any CPU
{E9639AF9-8C03-4B30-AA3B-B85873D0C406}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9639AF9-8C03-4B30-AA3B-B85873D0C406}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9639AF9-8C03-4B30-AA3B-B85873D0C406}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9639AF9-8C03-4B30-AA3B-B85873D0C406}.Release|Any CPU.Build.0 = Release|Any CPU
{374D9358-C654-4882-AE9F-89DDB135A69D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{374D9358-C654-4882-AE9F-89DDB135A69D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{374D9358-C654-4882-AE9F-89DDB135A69D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{374D9358-C654-4882-AE9F-89DDB135A69D}.Release|Any CPU.Build.0 = Release|Any CPU
{C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C335B0B3-B0AE-45EF-B620-87E9EBE257D3}.Release|Any CPU.Build.0 = Release|Any CPU
{CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBE19DF1-F112-4BCB-9DC4-BE33D971CCCC}.Release|Any CPU.Build.0 = Release|Any CPU
{FB4E0FC3-97A9-4456-93DB-F8335175FA47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB4E0FC3-97A9-4456-93DB-F8335175FA47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB4E0FC3-97A9-4456-93DB-F8335175FA47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB4E0FC3-97A9-4456-93DB-F8335175FA47}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Empty file added src/README.md
Empty file.
17 changes: 17 additions & 0 deletions src/iRLeagueApiCore.Client/Endpoints/PutEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using iRLeagueApiCore.Client.Http;
using iRLeagueApiCore.Client.QueryBuilder;
using iRLeagueApiCore.Client.Results;

namespace iRLeagueApiCore.Client.Endpoints;

internal class PutEndpoint<TResult, TModel> : EndpointBase, IPutEndpoint<TResult, TModel> where TModel : notnull
{
public PutEndpoint(HttpClientWrapper httpClientWrapper, RouteBuilder routeBuilder) :
base(httpClientWrapper, routeBuilder)
{ }

async Task<ClientActionResult<TResult>> IPutEndpoint<TResult, TModel>.Put(TModel model, CancellationToken cancellationToken)
{
return await HttpClientWrapper.PutAsClientActionResult<TResult>(QueryUrl, model, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface IEventResultsEndpoint : IGetAllEndpoint<EventResultModel>, IDel
IPostEndpoint<bool, ParseSimSessionResult> Upload();
IPostEndpoint<bool> Calculate();
IFetchResultsEndpoint Fetch();
IGetEndpoint<RawEventResultModel> Raw();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using iRLeagueApiCore.Common.Models;

namespace iRLeagueApiCore.Client.Endpoints.Results;
public interface IRawResultsEndpoint
{
public IGetEndpoint<RawEventResultModel> EventResult(long eventId);
public IPutEndpoint<RawResultRowModel, RawResultRowModel> ModifyResultRow(long resultRowId, bool triggerCalculation = false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace iRLeagueApiCore.Client.Endpoints.Results;
public interface IResultsEndpoint : IWithIdEndpoint<IResultByIdEndpoint>
{
public IGetEndpoint<IEnumerable<EventResultModel>> Latest();
public IPutEndpoint<RawResultRowModel, RawResultRowModel> ModifyResultRow(long resultRowId, bool triggerCalculation = false);
}
13 changes: 13 additions & 0 deletions src/iRLeagueApiCore.Client/Endpoints/Results/RawResultsEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using iRLeagueApiCore.Client.Http;
using iRLeagueApiCore.Client.QueryBuilder;
using iRLeagueApiCore.Common.Models;

namespace iRLeagueApiCore.Client.Endpoints.Results;

internal sealed class RawResultsEndpoint : GetEndpoint<RawEventResultModel>
{
public RawResultsEndpoint(HttpClientWrapper httpClient, RouteBuilder routeBuilder) : base(httpClient, routeBuilder)
{
RouteBuilder.AddEndpoint("Raw");
}
}
14 changes: 14 additions & 0 deletions src/iRLeagueApiCore.Client/Endpoints/Results/ResultsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ public ResultsEndpoint(HttpClientWrapper httpClientWrapper, RouteBuilder routeBu
RouteBuilder.AddEndpoint("Results");
}

public IGetEndpoint<RawEventResultModel> Raw()
{
return new RawResultsEndpoint(HttpClientWrapper, RouteBuilder);
}

public IPutEndpoint<RawResultRowModel, RawResultRowModel> ModifyResultRow(long resultRowId, bool triggerCalculation = false)
{
var routeBuilder = RouteBuilder.Copy();
routeBuilder.AddEndpoint("ModResultRow");
routeBuilder.AddParameter(resultRowId);
routeBuilder.WithParameters(x => x.Add("triggerCaculation", triggerCalculation));
return new PutEndpoint<RawResultRowModel, RawResultRowModel>(HttpClientWrapper, routeBuilder);
}

public IPostEndpoint<bool, ParseSimSessionResult> Upload()
{
return new UploadResultEndpoint(HttpClientWrapper, RouteBuilder);
Expand Down
25 changes: 25 additions & 0 deletions src/iRLeagueApiCore.Client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# iRLeagueApiCore.Client

Simple client for using the iRLeagueManager API from a .NET application

## Usage

### Register service

```csharp
services.AddLeagueApiClient();
```

### Use client

```csharp
client = service.GetRequiredService<ILeagueApiClient>();

var leagues = await client.Leagues().Get();
```

### Log in as API user

```csharp
await client.LogIn("Username", "Password");
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
using iRLeagueApiCore.Client.Service;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using System.Text.Json.Serialization;
using System.Text.Json;

namespace Microsoft.Extensions.DependencyInjection;
public static class IRLeagueApiClientServiceExtensions
{
public static IServiceCollection AddLeagueApiClient(this IServiceCollection services, Action<LeagueApiClientConfiguration>? configure = null)
{
services.AddHttpClient();
services.TryAddScoped<HttpClientWrapperFactory>();

var jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
jsonOptions.Converters.Add(new JsonStringEnumConverter());
jsonOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;

services.TryAddScoped<HttpClientWrapperFactory>(sp => new(
sp.GetRequiredService<ILoggerFactory>(),
jsonOptions
));
services.TryAddScoped<ITokenStore, DefaultTokenStore>();
services.TryAddScoped<IAsyncTokenProvider>(sp => sp.GetRequiredService<ITokenStore>());

// run configuration
var configuration = new LeagueApiClientConfiguration(services);
configure?.Invoke(configuration);
Expand Down
13 changes: 11 additions & 2 deletions src/iRLeagueApiCore.Client/iRLeagueApiCore.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup />

<ItemGroup>
<PackageReference Include="iRLeagueApiCore.Common" Version="0.11.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
Expand All @@ -13,14 +12,16 @@
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
<PackageId>iRLeagueApiCore.Client</PackageId>
<Version>0.11.4</Version>
<Version>0.12.0</Version>
<Authors>Simon Schulze</Authors>
<Company>Simon Schulze</Company>
<PackageDescription>This package contains shared objects for all members of the iRLeagueDatabase-iRLeagueApi stack</PackageDescription>
<RepositoryUrl>https://github.com/SSchulze1989/iRLeagueApiCore</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -29,5 +30,13 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\iRLeagueApiCore.Common\iRLeagueApiCore.Common.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

</Project>

41 changes: 41 additions & 0 deletions src/iRLeagueApiCore.Common/Converters/JsonTimeSpanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#if NETCOREAPP
using System.Text.Json;

namespace iRLeagueApiCore.Common.Converters;

public class JsonTimeSpanConverter : JsonConverter<TimeSpan>
{
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (typeof(long).IsAssignableFrom(typeToConvert))
{
var longValue = reader.GetInt64();
return new TimeSpan(longValue);
}
else
{
var timeSpanString = reader.GetString();
if (string.IsNullOrWhiteSpace(timeSpanString))
{
return TimeSpan.Zero;
}
var hasDays = timeSpanString.Count(c => c == '.') > 1;
if (hasDays)
{
return TimeSpan.ParseExact(timeSpanString, @"dd\.hh\:mm\:ss\.fffff", null);
}
return TimeSpan.ParseExact(timeSpanString, @"hh\:mm\:ss\.fffff", null);
}
}

public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
{
if (value.Days > 0)
{
writer.WriteStringValue(value.ToString(@"dd\.hh\:mm\:ss\.fffff"));
return;
}
writer.WriteStringValue(value.ToString(@"hh\:mm\:ss\.fffff"));
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json;

namespace iRLeagueApiCore.Common.Converters;

public sealed class JsonTimeSpanToTicksConverter : JsonConverter<TimeSpan>
{
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (typeof(long).IsAssignableFrom(typeToConvert))
{
var longValue = reader.GetInt64();
return new TimeSpan(longValue);
}
return TimeSpan.Zero;
}

public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value.Ticks);
}
}
Loading
Loading