Skip to content

Commit

Permalink
+ Checkpoint for Legend Onboarding implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
KDotIV committed Jun 13, 2024
1 parent c2253f9 commit 4e1b9df
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 12 deletions.
2 changes: 0 additions & 2 deletions SengokuProvider.Library/Models/Legends/LegendData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using SengokuProvider.Library.Models.Common;
using SengokuProvider.Library.Models.Events;
using SengokuProvider.Library.Models.Players;

namespace SengokuProvider.Library.Models.Legends
{
Expand Down
13 changes: 13 additions & 0 deletions SengokuProvider.Library/Models/Legends/LegendQueryResult.cs
Original file line number Diff line number Diff line change
@@ -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
{

}
}
17 changes: 17 additions & 0 deletions SengokuProvider.Library/Models/Players/StandingsQueryResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace SengokuProvider.Library.Models.Players
{
public class StandingsQueryResult
{
public required int PlayerID { get; set; }
public required List<StandingsResult> 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; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace SengokuProvider.Library.Services.Legends
using SengokuProvider.Library.Models.Legends;

namespace SengokuProvider.Library.Services.Legends
{
public interface ILegendIntakeService
{
public Task<LegendData?> GenerateNewLegends(int playerId);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using SengokuProvider.Library.Models.Legends;
using SengokuProvider.Library.Models.Players;

namespace SengokuProvider.Library.Services.Legends
{
public interface ILegendQueryService
{
public Task<LegendData> GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand getLegendsByPlayerLinkCommand);
public Task<LegendData?> GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand getLegendsByPlayerLinkCommand);
public Task<StandingsQueryResult?> QueryStandingsByPlayerId(int playerId);
}
}
16 changes: 10 additions & 6 deletions SengokuProvider.Library/Services/Legends/LegendIntakeService.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -16,5 +12,13 @@ public LegendIntakeService(string connectionString, ILegendQueryService querySer
_legendQueryService = queryService;
}

public async Task<LegendData?> GenerateNewLegends(int playerId)
{
Console.WriteLine("Beginning Onboarding Process...");

var currentData = await _legendQueryService.QueryStandingsByPlayerId(playerId);

return null;
}
}
}
}
51 changes: 49 additions & 2 deletions SengokuProvider.Library/Services/Legends/LegendQueryService.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -15,12 +16,58 @@ public LegendQueryService(string connectionString, GraphQLHttpClient graphQlClie
_client = graphQlClient;
}

public async Task<LegendData> GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand command)
public async Task<LegendData?> GetLegendsByPlayerLink(GetLegendsByPlayerLinkCommand command)
{
return await QueryLegendsByPlayerLink(command.PlayerLinkId);
}
public async Task<StandingsQueryResult?> QueryStandingsByPlayerId(int playerId)
{
if (playerId == 0) return null;

try
{
using (var conn = new NpgsqlConnection(_connectString))
{
await conn.OpenAsync();

private async Task<LegendData> 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<StandingsResult>()
};
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<LegendData?> QueryLegendsByPlayerLink(int playerLinkId)
{
try
{
Expand Down
7 changes: 7 additions & 0 deletions SengokuProvider.Worker/Handlers/LegendReceivedWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ private async Task<int> 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;
}

Expand Down

0 comments on commit 4e1b9df

Please sign in to comment.