From 4e1b9df0ae6cb6dd9c02472f898ba3cf133bd694 Mon Sep 17 00:00:00 2001 From: "K." Date: Wed, 12 Jun 2024 22:06:19 -0400 Subject: [PATCH] + Checkpoint for Legend Onboarding implementation --- .../Models/Legends/LegendData.cs | 2 - .../Models/Legends/LegendQueryResult.cs | 13 +++++ .../Models/Players/StandingsQueryResult.cs | 17 +++++++ .../Services/Legends/ILegendIntakeService.cs | 5 +- .../Services/Legends/ILegendQueryService.cs | 4 +- .../Services/Legends/LegendIntakeService.cs | 16 +++--- .../Services/Legends/LegendQueryService.cs | 51 ++++++++++++++++++- .../Handlers/LegendReceivedWorker.cs | 7 +++ 8 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 SengokuProvider.Library/Models/Legends/LegendQueryResult.cs create mode 100644 SengokuProvider.Library/Models/Players/StandingsQueryResult.cs diff --git a/SengokuProvider.Library/Models/Legends/LegendData.cs b/SengokuProvider.Library/Models/Legends/LegendData.cs index 9a37088..f8f3c9f 100644 --- a/SengokuProvider.Library/Models/Legends/LegendData.cs +++ b/SengokuProvider.Library/Models/Legends/LegendData.cs @@ -1,6 +1,4 @@ using SengokuProvider.Library.Models.Common; -using SengokuProvider.Library.Models.Events; -using SengokuProvider.Library.Models.Players; namespace SengokuProvider.Library.Models.Legends { diff --git a/SengokuProvider.Library/Models/Legends/LegendQueryResult.cs b/SengokuProvider.Library/Models/Legends/LegendQueryResult.cs new file mode 100644 index 0000000..5f84e2a --- /dev/null +++ b/SengokuProvider.Library/Models/Legends/LegendQueryResult.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SengokuProvider.Library.Models.Legends +{ + public class LegendQueryResult + { + + } +} diff --git a/SengokuProvider.Library/Models/Players/StandingsQueryResult.cs b/SengokuProvider.Library/Models/Players/StandingsQueryResult.cs new file mode 100644 index 0000000..1b132f2 --- /dev/null +++ b/SengokuProvider.Library/Models/Players/StandingsQueryResult.cs @@ -0,0 +1,17 @@ +namespace SengokuProvider.Library.Models.Players +{ + public class StandingsQueryResult + { + public required int PlayerID { get; set; } + public required List StandingData { get; set; } + } + + public class StandingsResult + { + public required int EntrantID { get; set; } + public required int TournamentLink { get; set; } + public required int Placement { get; set; } + public required int EntrantsNum { get; set; } + public required bool IsActive { get; set; } + } +} diff --git a/SengokuProvider.Library/Services/Legends/ILegendIntakeService.cs b/SengokuProvider.Library/Services/Legends/ILegendIntakeService.cs index 86667f2..6f4ab07 100644 --- a/SengokuProvider.Library/Services/Legends/ILegendIntakeService.cs +++ b/SengokuProvider.Library/Services/Legends/ILegendIntakeService.cs @@ -1,6 +1,9 @@ -namespace SengokuProvider.Library.Services.Legends +using SengokuProvider.Library.Models.Legends; + +namespace SengokuProvider.Library.Services.Legends { public interface ILegendIntakeService { + public Task GenerateNewLegends(int playerId); } } \ No newline at end of file diff --git a/SengokuProvider.Library/Services/Legends/ILegendQueryService.cs b/SengokuProvider.Library/Services/Legends/ILegendQueryService.cs index 98654bf..622d43c 100644 --- a/SengokuProvider.Library/Services/Legends/ILegendQueryService.cs +++ b/SengokuProvider.Library/Services/Legends/ILegendQueryService.cs @@ -1,9 +1,11 @@ using SengokuProvider.Library.Models.Legends; +using SengokuProvider.Library.Models.Players; namespace SengokuProvider.Library.Services.Legends { public interface ILegendQueryService { - public Task GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand getLegendsByPlayerLinkCommand); + public Task GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand getLegendsByPlayerLinkCommand); + public Task QueryStandingsByPlayerId(int playerId); } } \ No newline at end of file diff --git a/SengokuProvider.Library/Services/Legends/LegendIntakeService.cs b/SengokuProvider.Library/Services/Legends/LegendIntakeService.cs index f32629d..d45d8f3 100644 --- a/SengokuProvider.Library/Services/Legends/LegendIntakeService.cs +++ b/SengokuProvider.Library/Services/Legends/LegendIntakeService.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using SengokuProvider.Library.Models.Legends; namespace SengokuProvider.Library.Services.Legends { @@ -16,5 +12,13 @@ public LegendIntakeService(string connectionString, ILegendQueryService querySer _legendQueryService = queryService; } + public async Task GenerateNewLegends(int playerId) + { + Console.WriteLine("Beginning Onboarding Process..."); + + var currentData = await _legendQueryService.QueryStandingsByPlayerId(playerId); + + return null; + } } -} +} \ No newline at end of file diff --git a/SengokuProvider.Library/Services/Legends/LegendQueryService.cs b/SengokuProvider.Library/Services/Legends/LegendQueryService.cs index a319497..81099a5 100644 --- a/SengokuProvider.Library/Services/Legends/LegendQueryService.cs +++ b/SengokuProvider.Library/Services/Legends/LegendQueryService.cs @@ -1,6 +1,7 @@ using GraphQL.Client.Http; using Npgsql; using SengokuProvider.Library.Models.Legends; +using SengokuProvider.Library.Models.Players; namespace SengokuProvider.Library.Services.Legends { @@ -15,12 +16,58 @@ public LegendQueryService(string connectionString, GraphQLHttpClient graphQlClie _client = graphQlClient; } - public async Task GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand command) + public async Task GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand command) { return await QueryLegendsByPlayerLink(command.PlayerLinkId); } + public async Task QueryStandingsByPlayerId(int playerId) + { + if (playerId == 0) return null; + + try + { + using (var conn = new NpgsqlConnection(_connectString)) + { + await conn.OpenAsync(); - private async Task QueryLegendsByPlayerLink(int playerLinkId) + using (var cmd = new NpgsqlCommand(@"SELECT * FROM standings WHERE player_id = @Input", conn)) + { + cmd.Parameters.AddWithValue("@Input", playerId); + + using(var reader = await cmd.ExecuteReaderAsync()) + { + var queryResult = new StandingsQueryResult + { + PlayerID = reader.GetInt32(reader.GetOrdinal("player_id")), + StandingData = new List() + }; + while (await reader.ReadAsync()) + { + var newStanding = new StandingsResult + { + EntrantID = reader.GetInt32(reader.GetOrdinal("entrant_id")), + TournamentLink = reader.GetInt32(reader.GetOrdinal("tournament_link")), + EntrantsNum = reader.GetInt32(reader.GetOrdinal("entrants_num")), + Placement = reader.GetInt32(reader.GetOrdinal("placement")), + IsActive = reader.GetBoolean(reader.GetOrdinal("active")) + }; + queryResult.StandingData.Add(newStanding); + } + return queryResult; + } + } + } + } + catch (NpgsqlException ex) + { + throw new ApplicationException("Database error occurred: ", ex); + } + catch (Exception ex) + { + throw new ApplicationException("Unexpected Error Occurred: ", ex); + } + } + private async Task QueryLegendsByPlayerLink(int playerLinkId) { try { diff --git a/SengokuProvider.Worker/Handlers/LegendReceivedWorker.cs b/SengokuProvider.Worker/Handlers/LegendReceivedWorker.cs index 72d633e..2bfc30e 100644 --- a/SengokuProvider.Worker/Handlers/LegendReceivedWorker.cs +++ b/SengokuProvider.Worker/Handlers/LegendReceivedWorker.cs @@ -83,6 +83,13 @@ private async Task OnboardNewPlayer(OnboardReceivedData currentMessage) { if (currentMessage == null) { return 0; } + var currentIntake = _legendFactory.CreateIntakeHandler(); + if(currentMessage.Command is OnboardLegendsByPlayerCommand onboardCommand) + { + var newLegend = await currentIntake.GenerateNewLegends(onboardCommand.PlayerId); + + } + return 0; }