-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from SSchulze1989/feature/modify-raw-results
Feature/modify raw results
- Loading branch information
Showing
18 changed files
with
426 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/iRLeagueApiCore.Client/Endpoints/Results/IRawResultsEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/iRLeagueApiCore.Client/Endpoints/Results/RawResultsEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/iRLeagueApiCore.Common/Models/Results/RawEventResultModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace iRLeagueApiCore.Common.Models; | ||
|
||
public sealed class RawEventResultModel | ||
{ | ||
public long EventId { get; set; } | ||
public IEnumerable<RawSessionResultModel> SessionResults { get; set; } = Array.Empty<RawSessionResultModel>(); | ||
} |
96 changes: 96 additions & 0 deletions
96
src/iRLeagueApiCore.Common/Models/Results/RawResultRowModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
namespace iRLeagueApiCore.Common.Models; | ||
|
||
[DataContract] | ||
public sealed class RawResultRowModel | ||
{ | ||
[DataMember] | ||
public long ResultRowId { get; set; } | ||
[DataMember] | ||
public long MemberId { get; set; } | ||
[DataMember] | ||
public double StartPosition { get; set; } | ||
[DataMember] | ||
public double FinishPosition { get; set; } | ||
[DataMember] | ||
public string CarNumber { get; set; } = string.Empty; | ||
[DataMember] | ||
public int ClassId { get; set; } | ||
[DataMember] | ||
public string Car { get; set; } = string.Empty; | ||
[DataMember] | ||
public string CarClass { get; set; } = string.Empty; | ||
[DataMember] | ||
public double CompletedLaps { get; set; } | ||
[DataMember] | ||
public double LeadLaps { get; set; } | ||
[DataMember] | ||
public int FastLapNr { get; set; } | ||
[DataMember] | ||
public double Incidents { get; set; } | ||
[DataMember] | ||
public int Status { get; set; } | ||
[DataMember] | ||
public TimeSpan QualifyingTime { get; set; } | ||
[DataMember] | ||
public TimeSpan Interval { get; set; } | ||
[DataMember] | ||
public TimeSpan AvgLapTime { get; set; } | ||
[DataMember] | ||
public TimeSpan FastestLapTime { get; set; } | ||
[DataMember] | ||
public double PositionChange { get; set; } | ||
[DataMember] | ||
public string IRacingId { get; set; } = string.Empty; | ||
[DataMember] | ||
public int SimSessionType { get; set; } | ||
[DataMember] | ||
public int OldIRating { get; set; } | ||
[DataMember] | ||
public int NewIRating { get; set; } | ||
[DataMember] | ||
public int SeasonStartIRating { get; set; } | ||
[DataMember] | ||
public string License { get; set; } = string.Empty; | ||
[DataMember] | ||
public double OldSafetyRating { get; set; } | ||
[DataMember] | ||
public double NewSafetyRating { get; set; } | ||
[DataMember] | ||
public int OldCpi { get; set; } | ||
[DataMember] | ||
public int NewCpi { get; set; } | ||
[DataMember] | ||
public int ClubId { get; set; } | ||
[DataMember] | ||
public string ClubName { get; set; } = string.Empty; | ||
[DataMember] | ||
public int CarId { get; set; } | ||
[DataMember] | ||
public double CompletedPct { get; set; } | ||
[DataMember] | ||
public DateTime? QualifyingTimeAt { get; set; } | ||
[DataMember] | ||
public int Division { get; set; } | ||
[DataMember] | ||
public int OldLicenseLevel { get; set; } | ||
[DataMember] | ||
public int NewLicenseLevel { get; set; } | ||
[DataMember] | ||
public int NumPitStops { get; set; } | ||
[DataMember] | ||
public string PittedLaps { get; set; } = string.Empty; | ||
[DataMember] | ||
public int NumOfftrackLaps { get; set; } | ||
[DataMember] | ||
public string OfftrackLaps { get; set; } = string.Empty; | ||
[DataMember] | ||
public int NumContactLaps { get; set; } | ||
[DataMember] | ||
public string ContactLaps { get; set; } = string.Empty; | ||
[DataMember] | ||
public double RacePoints { get; set; } | ||
[DataMember] | ||
public long? TeamId { get; set; } | ||
[DataMember] | ||
public bool PointsEligible { get; set; } | ||
} |
7 changes: 7 additions & 0 deletions
7
src/iRLeagueApiCore.Common/Models/Results/RawSessionResultModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace iRLeagueApiCore.Common.Models; | ||
|
||
public sealed class RawSessionResultModel | ||
{ | ||
public long SessionId { get; set; } | ||
public IEnumerable<RawResultRowModel> ResultRows { get; set; } = Array.Empty<RawResultRowModel>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/iRLeagueApiCore.Server/Handlers/Results/GetRawResultsFromEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using iRLeagueApiCore.Common.Models; | ||
using System.Linq.Expressions; | ||
|
||
namespace iRLeagueApiCore.Server.Handlers.Results; | ||
|
||
public record GetRawResultsFromEventRequest(long EventId) : IRequest<RawEventResultModel>; | ||
|
||
public class GetRawResultsFromEventHandler : ResultHandlerBase<GetRawResultsFromEventHandler, GetRawResultsFromEventRequest, RawEventResultModel> | ||
{ | ||
public GetRawResultsFromEventHandler(ILogger<GetRawResultsFromEventHandler> logger, LeagueDbContext dbContext, | ||
IEnumerable<IValidator<GetRawResultsFromEventRequest>> validators) : base(logger, dbContext, validators) | ||
{ | ||
} | ||
|
||
public override async Task<RawEventResultModel> Handle(GetRawResultsFromEventRequest request, CancellationToken cancellationToken) | ||
{ | ||
await validators.ValidateAllAndThrowAsync(request, cancellationToken); | ||
var result = await dbContext.EventResults | ||
.Where(x => x.EventId == request.EventId) | ||
.Select(MapToRawEventResultModelExpression) | ||
.FirstOrDefaultAsync(cancellationToken) | ||
?? throw new ResourceNotFoundException(); | ||
return result; | ||
} | ||
|
||
private Expression<Func<EventResultEntity, RawEventResultModel>> MapToRawEventResultModelExpression => result => new() | ||
{ | ||
EventId = result.EventId, | ||
SessionResults = result.SessionResults.Select(sessionResult => new RawSessionResultModel() | ||
{ | ||
SessionId = sessionResult.SessionId, | ||
ResultRows = sessionResult.ResultRows.Select(row => new RawResultRowModel() | ||
{ | ||
ResultRowId = row.ResultRowId, | ||
MemberId = row.MemberId, | ||
StartPosition = row.StartPosition, | ||
FinishPosition = row.FinishPosition, | ||
CarNumber = row.CarNumber, | ||
ClassId = row.ClassId, | ||
Car = row.Car, | ||
CarClass = row.CarClass, | ||
CompletedLaps = row.CompletedLaps, | ||
LeadLaps = row.LeadLaps, | ||
FastLapNr = row.FastLapNr, | ||
Incidents = row.Incidents, | ||
Status = row.Status, | ||
QualifyingTime = row.QualifyingTime, | ||
Interval = row.Interval, | ||
AvgLapTime = row.AvgLapTime, | ||
FastestLapTime = row.FastestLapTime, | ||
PositionChange = row.PositionChange, | ||
IRacingId = row.IRacingId, | ||
SimSessionType = row.SimSessionType, | ||
OldIRating = row.OldIRating, | ||
NewIRating = row.NewIRating, | ||
SeasonStartIRating = row.SeasonStartIRating, | ||
License = row.License, | ||
OldSafetyRating = row.OldSafetyRating, | ||
NewSafetyRating = row.NewSafetyRating, | ||
OldCpi = row.OldCpi, | ||
NewCpi = row.NewCpi, | ||
ClubId = row.ClubId, | ||
ClubName = row.ClubName, | ||
CarId = row.CarId, | ||
CompletedPct = row.CompletedPct, | ||
QualifyingTimeAt = row.QualifyingTimeAt, | ||
Division = row.Division, | ||
OldLicenseLevel = row.OldLicenseLevel, | ||
NewLicenseLevel = row.NewLicenseLevel, | ||
NumPitStops = row.NumPitStops, | ||
PittedLaps = row.PittedLaps, | ||
NumOfftrackLaps = row.NumOfftrackLaps, | ||
OfftrackLaps = row.OfftrackLaps, | ||
NumContactLaps = row.NumContactLaps, | ||
ContactLaps = row.ContactLaps, | ||
RacePoints = row.RacePoints, | ||
TeamId = row.TeamId, | ||
PointsEligible = row.PointsEligible, | ||
}).ToList(), | ||
}).ToList(), | ||
}; | ||
} |
Oops, something went wrong.