diff --git a/deployment/game_database/indexes.js b/deployment/game_database/indexes.js index 6570b5c..1ee24a3 100644 --- a/deployment/game_database/indexes.js +++ b/deployment/game_database/indexes.js @@ -1 +1,3 @@ -db.recordings.createIndex({ DateTime: 1 }); \ No newline at end of file +db.recordings.createIndex({ "DateTime": 1 }); +db.recordings.createIndex({ "location":1, "Event._id":1, "Player.Nickname": 1}); +db.recordings.createIndex({ "Player.Nickname": 1,"Event._id": 1 }); \ No newline at end of file diff --git a/rest_service/Controllers/PlayersController.cs b/rest_service/Controllers/PlayersController.cs index 964186b..e7df03d 100644 --- a/rest_service/Controllers/PlayersController.cs +++ b/rest_service/Controllers/PlayersController.cs @@ -1,6 +1,7 @@ using System.Xml.Linq; using Microsoft.AspNetCore.Mvc; using MongoDB.Bson; +using MongoDB.Bson.Serialization; using MongoDB.Driver; using RestService.Dtos.RequestObjects; using RestService.Dtos.ResponseObjects; @@ -15,6 +16,7 @@ public class PlayersController : BaseController private readonly IMongoCollection _playersCollection; private readonly IMongoCollection _playersUniqueCollection; private readonly IMongoCollection _playersUniqueCollectionOnSecondary; + private readonly IMongoCollection _recordingsCollection; public PlayersController(ILogger logger) : base(logger) { @@ -26,6 +28,8 @@ public PlayersController(ILogger logger) : base(logger) Constants.PlayersUniqueCollectionName, new MongoCollectionSettings() { ReadPreference = ReadPreference.SecondaryPreferred } ); + + _recordingsCollection = Database!.GetCollection(Constants.RecordingsCollectionName); } [HttpGet(Name = "GetPlayers")] @@ -63,6 +67,58 @@ public async Task> GetPlayers([FromQuery] PlayerRequest pla return playersResponse; } + [HttpGet("events", Name = "GetPlayerEvents")] + public async Task> GetEventsForPlayer([FromQuery] PlayerRequest playerRequest) + { + var pipeline = new List + { + new JsonPipelineStageDefinition( + "{$match:{'Player.Nickname': '" + playerRequest.Name + "'}}" + ), + new JsonPipelineStageDefinition( + "{$project:{_id: 0,'Player.Nickname': 1,'Event._id': 1}}" + ), + new JsonPipelineStageDefinition( + "{$group:{_id: 1,EventIds:{$addToSet: '$Event._id'}}}" + ), + new JsonPipelineStageDefinition( + "{$project:{_id: 0,EventId:{$sortArray:{input: '$EventIds',sortBy: 1}}}}" + ), + new JsonPipelineStageDefinition( + "{$unwind:{path: '$EventId'}}" + ), + new JsonPipelineStageDefinition( + @"{$lookup:{ + from: 'events', + localField: 'EventId', + foreignField: '_id', + as: 'event'}}" + ), + new JsonPipelineStageDefinition( + "{$unwind:{path: '$event'}}" + ), + new JsonPipelineStageDefinition( + "{$replaceRoot:{newRoot: '$event'}}" + ) + }; + + try + { + var result = await _recordingsCollection.AggregateAsync(pipeline); + List bsonDocuments = await result.ToListAsync(); + List events = bsonDocuments.Select(document => BsonSerializer.Deserialize(document)).ToList(); + + return events; + } + catch (Exception e) + { + Logger.LogError("GetEventsForPlayer did not find matches"); + Logger.LogError(e.Message); + + return new List(); + } + } + [HttpPost(Name = "CreatePlayer")] public async Task> CreatePlayer(PlayerRequest playerRequest) { diff --git a/website/Pages/EventHome.razor b/website/Pages/EventDashboard.razor similarity index 71% rename from website/Pages/EventHome.razor rename to website/Pages/EventDashboard.razor index 6bbb3fc..b0de8c4 100644 --- a/website/Pages/EventHome.razor +++ b/website/Pages/EventDashboard.razor @@ -1,4 +1,4 @@ -@page "/eventHome" +@page "/eventDashboard" @using RestSharp @using website.Data @using website.Utils @@ -21,7 +21,7 @@ margin: auto; } - + logo
@@ -33,29 +33,32 @@ GitHub
-
-
- - - - - -
-
- logo -
-
- @if (Event?.Name != null) - { -

@Event.Name

- } -
-

-

Event Dashboard

- -
-
+@if (_event != null) +{ +
+
+

+

Event Dashboard

+ + + + + + +
+
+ logo +
+
+ @if (_event?.Name != null) + { +

@_event.Name

+ } +
+
+
+} @if (_chartUrl.Length == 0) { @@ -72,7 +75,7 @@ else @code { - private Event? Event { get; set; } + private Event? _event { get; set; } private string _eventId = string.Empty; private string _chartUrl = string.Empty; private readonly RestClient _restClient = RestServiceClient.Create(); @@ -90,12 +93,12 @@ else }; string eventsUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointEvents, eventsFilter); var events = await _restClient.GetJsonAsync>(eventsUrlWithQuery); - Event = events.FirstOrDefault(); + _event = events.FirstOrDefault(); DotEnv.Load(); var envVars = DotEnv.Read(); var atlasChartIdEvent = envVars["ATLAS_CHART_ID_EVENT"]; - _chartUrl = ChartsUrl.CreateEventUrl(atlasChartIdEvent, Event!.Id!, Event.Location!); + _chartUrl = ChartsUrl.CreateEventUrl(atlasChartIdEvent, _event!.Id!, _event.Location!); } catch (Exception e) { @@ -110,7 +113,7 @@ else private string GetQRCodeForCurrentUrl() { string url = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + - NavigationManager.BaseUri + "?EventId=" + _eventId; + NavigationManager.BaseUri + "/EventRegister?EventId=" + _eventId; Console.WriteLine(url); return url; } diff --git a/website/Pages/EventRegister.razor b/website/Pages/EventRegister.razor new file mode 100644 index 0000000..d0986f5 --- /dev/null +++ b/website/Pages/EventRegister.razor @@ -0,0 +1,301 @@ +@page "/EventRegister" +@using RestSharp +@using website.Data +@using website.Utils +@using dotenv.net + +@inject NavigationManager NavigationManager +@inject IJSRuntime JS + + + + logo + +
+
+ Solution +    |    + MDB for Gaming +    |    + GitHub +
+
+
+
+ +

+

Registration & Login

+ + + @if ((_event != null)) + { + + + + + +
+
+ logo +
+
+

+ @_event.Name +

+
+ } + +

+ @_errorMessage +

+ +
+
+
+ + + +
+ + + +
+ @if (_suggestedNames.Count > 0) + { +
    + @foreach (var name in _suggestedNames) + { +
  • SelectName(name))> + @name +
  • + } +
+ } +
+
+ +
+
+ + + +
+ +
+ +
+
+ + + +
+ + +
+ + +
+
+ + +
+
+
+
+
+ +
+ @if (_chartUrl.Length == 0) + { +

+ Loading... +

+ } + else + { +
+ +
+ } +
+ +@code { + private Player _player { get; } = new(); + private List _suggestedNames = new(); + private Event? _event; + private string _eventId = string.Empty; + private string _chartUrl = string.Empty; + private string _errorMessage = string.Empty; + private readonly RestClient _restClient = RestServiceClient.Create(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await JS.InvokeAsync("enableListener"); + } + } + + protected override async Task OnInitializedAsync() + { + await SetEventFromUrlParameters(); + DotEnv.Load(); + var envVars = DotEnv.Read(); + var atlasChartIdHome = envVars["ATLAS_CHART_ID_HOME"]; + + _chartUrl = ChartsUrl.CreateHomeUrl(atlasChartIdHome, _event!.Id!, _event.Location!); + } + + private async Task SetEventFromUrlParameters() + { + var queryParameters = UrlHelper.GetParameters(NavigationManager.Uri); + _eventId = queryParameters.TryGetValue(Constants.QueryParameterEventId, out var eventIdValue) ? eventIdValue : + queryParameters.TryGetValue("event", out var eventValue) ? eventValue : + Constants.DefaultEventId; + + var eventsFilter = new Dictionary + { + { "id", _eventId } + }; + + string eventsUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointEvents, eventsFilter); + var events = await _restClient.GetJsonAsync>(eventsUrlWithQuery); + + _event = events.FirstOrDefault(); + } + + private async Task CreatePlayer() + { + if (string.IsNullOrEmpty(_player.Name) || string.IsNullOrEmpty(_event?.Location)) + { + _errorMessage = "[please fill out the form]"; + return; + } + + _errorMessage = ""; + + //TO-DO ADD FILTER FOR PLAYER!!!! + var playersUnique = await _restClient.GetJsonAsync>(Constants.RestServiceEndpointPlayers); + var filteredPlayersUnique = playersUnique!.FindAll(p => p.Name!.Equals(_player.Name)); + var existingPlayer = filteredPlayersUnique.FirstOrDefault(); + + if (existingPlayer != null) + { + _errorMessage = $"[{_player.Name}] exists! Login instead?"; + } + else + { + _player.Location = _event.Location; + + var request = new RestRequest(Constants.RestServiceEndpointPlayers).AddJsonBody(_player); + await _restClient.PostAsync(request); + + var newDestination = UrlForPlayerAndEvent(_player.Location, _player.Name, _event.Id!); + NavigationManager!.NavigateTo(newDestination); + } + } + + private async Task LoginPlayer() + { + if (string.IsNullOrEmpty(_player.Name)) + { + _errorMessage = "[Enter your name!]"; + return; + } + + _errorMessage = ""; + + var args = new Dictionary + { + { "Name", _player.Name } + }; + + string urlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, args); + + var players = await _restClient.GetJsonAsync>(urlWithQuery); + var filteredPlayers = players!.FindAll(p => p.Name!.Equals(_player.Name)); + var existingPlayer = filteredPlayers.FirstOrDefault(); + + if (existingPlayer != null) + { + var newDestination = UrlForPlayerAndEvent(_event!.Location!, existingPlayer.Name!, _event.Id!); + NavigationManager!.NavigateTo(newDestination); + } + else + { + _errorMessage = $"[{_player.Name}] not found. Register instead?"; + } + } + + private async Task AutoCompleteName(ChangeEventArgs e) + { + var input = e.Value!.ToString()!; + + if (input.Length >= 3) + { + + var args = new Dictionary + { + { "Name", input } + }; + + string urlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayersAutoComplete, args); + + var names = await _restClient.GetJsonAsync>(urlWithQuery); + + _suggestedNames = names; + await JS.InvokeAsync("showAutoComplete"); + + } + else + { + _suggestedNames.Clear(); + } + } + + private void SelectName(string name) + { + _player.Name = name; + _suggestedNames.Clear(); + } + + private static string UrlForPlayerAndEvent(string location, string name, string eventId) + { + var newDestination = "/playerEventHome?location=" + location + "&Name=" + name + "&EventId=" + eventId; + return newDestination; + } + + // return current url location + private string GetQRCodeForCurrentUrl() + { + string url = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + + NavigationManager.BaseUri + "/EventRegister?EventId=" + _eventId; + Console.WriteLine(url); + return url; + } + +} \ No newline at end of file diff --git a/website/Pages/EventRegister.razor.css b/website/Pages/EventRegister.razor.css new file mode 100644 index 0000000..4c4c2f9 --- /dev/null +++ b/website/Pages/EventRegister.razor.css @@ -0,0 +1,5 @@ +.foo { + color: #0b5ed7; +} + + diff --git a/website/Pages/Index.razor b/website/Pages/Index.razor index 62e0523..358d9c5 100644 --- a/website/Pages/Index.razor +++ b/website/Pages/Index.razor @@ -21,7 +21,7 @@ height: 90vh; } - + logo
@@ -36,35 +36,10 @@
- - - - - -
-
- logo -
-
-

- - @if ((_event != null)) - { - if ((_event.Location != null) && (_event.Name != null)) - { - @_event.Name - } - else - { - @_event.Name - } - } - -

-
- -

Registration & Login

+

+

Registration & Login

+

@_errorMessage @@ -78,7 +53,7 @@

+ @bind="Player.Name" name="" @oninput="AutoCompleteName" required pattern="/^[a-zA-Z0-9_\-]+$/">
@@ -113,7 +88,8 @@
+ placeholder="E-Mail for prizes (optional)" type="email" + pattern="/^[a-zA-Z0-9._%+-]+@@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/"> @@ -133,27 +109,9 @@ -
- @if (_chartUrl.Length == 0) - { -

- Loading... -

- } - else - { -
- -
- } -
- @code { private Player Player { get; } = new(); private List _suggestedNames = new(); - private Event? _event; - private string _eventId = string.Empty; - private string _chartUrl = string.Empty; private string _errorMessage = string.Empty; private readonly RestClient _restClient = RestServiceClient.Create(); @@ -167,35 +125,13 @@ protected override async Task OnInitializedAsync() { - await SetEventFromUrlParameters(); DotEnv.Load(); var envVars = DotEnv.Read(); - var atlasChartIdHome = envVars["ATLAS_CHART_ID_HOME"]; - - _chartUrl = ChartsUrl.CreateHomeUrl(atlasChartIdHome, _event!.Id!, _event.Location!); - } - - private async Task SetEventFromUrlParameters() - { - var queryParameters = UrlHelper.GetParameters(NavigationManager.Uri); - _eventId = queryParameters.TryGetValue(Constants.QueryParameterEventId, out var eventIdValue) ? eventIdValue : - queryParameters.TryGetValue("event", out var eventValue) ? eventValue : - Constants.DefaultEventId; - - var eventsFilter = new Dictionary -{ -{ "id", _eventId } -}; - - string eventsUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointEvents, eventsFilter); - var events = await _restClient.GetJsonAsync>(eventsUrlWithQuery); - - _event = events.FirstOrDefault(); } private async Task CreatePlayer() { - if (string.IsNullOrEmpty(Player.Name) || string.IsNullOrEmpty(_event?.Location)) + if (string.IsNullOrEmpty(Player.Name)) { _errorMessage = "[please fill out the form]"; return; @@ -213,12 +149,12 @@ } else { - Player.Location = _event.Location; + Player.Location = "US"; // TO-DO Obtain from autocomplete input box var request = new RestRequest(Constants.RestServiceEndpointPlayers).AddJsonBody(Player); await _restClient.PostAsync(request); - var newDestination = UrlForPlayer(Player.Location, Player.Name, _event.Id!); + var newDestination = UrlForPlayer(Player.Location, Player.Name); NavigationManager!.NavigateTo(newDestination); } } @@ -234,9 +170,9 @@ _errorMessage = ""; var args = new Dictionary -{ -{ "Name", Player.Name } -}; + { + { "Name", Player.Name } + }; string urlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, args); @@ -246,7 +182,7 @@ if (existingPlayer != null) { - var newDestination = UrlForPlayer(_event!.Location!, existingPlayer.Name!, _event.Id!); + var newDestination = UrlForPlayer("US", existingPlayer.Name!); // TO-DO Obtain from autocomplete input box NavigationManager!.NavigateTo(newDestination); } else @@ -263,9 +199,9 @@ { var args = new Dictionary -{ -{ "Name", input } -}; + { + { "Name", input } + }; string urlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayersAutoComplete, args); @@ -287,19 +223,10 @@ _suggestedNames.Clear(); } - private static string UrlForPlayer(string location, string name, string eventId) + private static string UrlForPlayer(string location, string name) { - var newDestination = "/playerHome?location=" + location + "&Name=" + name + "&EventId=" + eventId; + var newDestination = "/playerHome?location=" + location + "&Name=" + name + "&hack=1"; // hack for players with trailing space return newDestination; } - // return current url location - private string GetQRCodeForCurrentUrl() - { - string url = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + - NavigationManager.BaseUri + "?EventId=" + _eventId; - Console.WriteLine(url); - return url; - } - } \ No newline at end of file diff --git a/website/Pages/PlayerEventHome.razor b/website/Pages/PlayerEventHome.razor new file mode 100644 index 0000000..9f582f8 --- /dev/null +++ b/website/Pages/PlayerEventHome.razor @@ -0,0 +1,234 @@ +@page "/playerEventHome" +@using RestSharp +@using website.Data +@using website.Utils +@using dotenv.net + +@inject NavigationManager NavigationManager +@inject Blazored.LocalStorage.ILocalStorageService localStore +@inject IJSRuntime JSRuntime + + + + + logo + +
+
+ Solution +    |    + MDB for Gaming +    |    + GitHub +
+
+ +@if (_event != null) +{ +
+ +
+} + +
+ @if (_event == null) + { +

+ Loading... +

+ } + else + { +
+

Player

+ +

+ @_errorMessage +

+ +
+
+
+ + + + + +
+ +
+ +
+
+ + + +
+ +
+ +
+
+ + + +
+ + +
+ +
+ Play Now +
+
+ +
+ } + +
+ + +
+ @if (_chartUrl.Length == 0) + { +

+ Loading... +

+ } + else + { +
+

Player Dashboard

+
+ + + + + } +
+ + +@code { + + private Event? _event { get; set; } + private Player _player { get; set; } = new(); + private string _eventId = string.Empty; + private string _location = string.Empty; + private string _name = string.Empty; + private string _chartUrl = string.Empty; + private string _errorMessage = string.Empty; + private readonly RestClient _restClient = RestServiceClient.Create(); + + protected override async Task OnInitializedAsync() + { + try + { + var queryParameters = UrlHelper.GetParameters(NavigationManager.Uri); + + _eventId = queryParameters[Constants.QueryParameterEventId]; + var eventsFilter = new Dictionary + { + { "id", _eventId } + }; + string eventsUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointEvents, eventsFilter); + var events = await _restClient.GetJsonAsync>(eventsUrlWithQuery); + _event = events.First(); + + _name = queryParameters[Constants.QueryParameterName]; + var playerFilter = new Dictionary + { + { "name", _name } + }; + string playersUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, playerFilter); + var players = await _restClient.GetJsonAsync>(playersUrlWithQuery); + _player = players.First(); + + _location = _event.Location; + + DotEnv.Load(); + var envVars = DotEnv.Read(); + var atlasChartIdPlayer = envVars["ATLAS_CHART_ID_PLAYER"]; + + var serviceIP = envVars["REST_SERVICE_IP"]; + var servicePort = envVars["GAME_CLIENT_PORT"]; // use different port for the game client + + _chartUrl = ChartsUrl.CreatePlayerUrl(atlasChartIdPlayer, _name, _location, _eventId); + + await localStore.SetItemAsStringAsync("eventId", _eventId); + await localStore.SetItemAsStringAsync("playerName", _player.Name); + await localStore.SetItemAsStringAsync("serviceIP", serviceIP); + await localStore.SetItemAsStringAsync("servicePort", servicePort); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + _errorMessage = "PLAYER NOT FOUND"; + } + } + + private async Task LaunchGame() + { + //NavigationManager!.NavigateTo("/player.html", true); + + await JSRuntime.InvokeAsync("open", "/player.html", "_blank"); + } + + // return current url location + private string GetQRCodeForCurrentUrl() + { + string url = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + + NavigationManager.BaseUri + "/EventRegister?EventId=" + _eventId; + Console.WriteLine(url); + return url; + } + +} diff --git a/website/Pages/PlayerHome.razor b/website/Pages/PlayerHome.razor index 7f8f1a9..4244902 100644 --- a/website/Pages/PlayerHome.razor +++ b/website/Pages/PlayerHome.razor @@ -25,7 +25,7 @@ } - + logo
@@ -37,30 +37,21 @@ GitHub
-
- @if (Event == null) - { + +@if (!ready) +{ +

Loading...

- } - else - { +
+} +else +{ + +
-

Player Dashboard

-

- @if ((Event != null)) - { - if ((Event.Location != null) && (Event.Name != null)) - { - @Event.Name - } - else - { - @Event.Name - } - } -

+

Player Home

@_errorMessage

@@ -69,7 +60,9 @@
- + + +
@@ -82,7 +75,7 @@
+ disabled>
@@ -94,49 +87,80 @@
- -
- Play Now -
- - } +
- + +
+
+

New Event

+

+ @_errorMessage +

+
+
+
+ + + +
+ +
-
- @if (_chartUrl.Length == 0) - { -

- Loading... -

- } - else - { -
-
-     - View Similar Players to @Player.Name -     -
-
- - } -
+
+
+ + + +
+ +
+ + +
+
+ +
+
+
+
+
+ +
+
+

Events Played In

+
+ @foreach (Event evt in Events) + { +

+ @evt.Id +

+
@evt.Name
+
 
+ } +
+
+
+} @code { - private Event? Event { get; set; } + private Event Event { get; set; } = new(); + private List Events { get; set; } = new(); private Player Player { get; set; } = new(); - private string _eventId = string.Empty; private string _location = string.Empty; private string _name = string.Empty; - private string _chartUrl = string.Empty; private string _errorMessage = string.Empty; private readonly RestClient _restClient = RestServiceClient.Create(); + private bool ready = false; protected override async Task OnInitializedAsync() { @@ -144,39 +168,29 @@ { var queryParameters = UrlHelper.GetParameters(NavigationManager.Uri); - _eventId = queryParameters[Constants.QueryParameterEventId]; - var eventsFilter = new Dictionary - { - { "id", _eventId } - }; - string eventsUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointEvents, eventsFilter); - var events = await _restClient.GetJsonAsync>(eventsUrlWithQuery); - Event = events.First(); - _name = queryParameters[Constants.QueryParameterName]; + + // Get Player var playerFilter = new Dictionary - { +{ { "name", _name } }; + string playersUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, playerFilter); var players = await _restClient.GetJsonAsync>(playersUrlWithQuery); + Player = players.First(); + _location = Player.Location; + + // Get Player Events + string playersEventsUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayersEvents, playerFilter); + var evts = await _restClient.GetJsonAsync>(playersEventsUrlWithQuery); + Events = evts.ToList(); - _location = Event.Location; + ready = Player != null && Events != null; DotEnv.Load(); var envVars = DotEnv.Read(); - var atlasChartIdPlayer = envVars["ATLAS_CHART_ID_PLAYER"]; - - var serviceIP = envVars["REST_SERVICE_IP"]; - var servicePort = envVars["GAME_CLIENT_PORT"]; // use different port for the game client - - _chartUrl = ChartsUrl.CreatePlayerUrl(atlasChartIdPlayer, _name, _location, _eventId); - - await localStore.SetItemAsStringAsync("eventId", _eventId); - await localStore.SetItemAsStringAsync("playerName", Player.Name); - await localStore.SetItemAsStringAsync("serviceIP", serviceIP); - await localStore.SetItemAsStringAsync("servicePort", servicePort); } catch (Exception e) { @@ -186,11 +200,46 @@ } } - private async Task LaunchGame() + private async Task CreateEvent() { - //NavigationManager!.NavigateTo("/player.html", true); + if (string.IsNullOrEmpty(Event.Id) || string.IsNullOrEmpty(Event.Name)) + { + _errorMessage = "[please fill out the Event ID and Name]"; + return; + } + + _errorMessage = ""; + + var args = new Dictionary +{ + { "id", Event.Id } + }; + + string urlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointEvents, args); + + var events = await _restClient.GetJsonAsync>(urlWithQuery); + var existingEvent = events.FirstOrDefault(); - await JSRuntime.InvokeAsync("open", "/player.html", "_blank"); + if (existingEvent != null) + { + _errorMessage = $"THIS EVENT ALREADY EXISTS!!!"; + } + else + { + Event.Location = _location; // TO-DO + + var request = new RestRequest(Constants.RestServiceEndpointEvents).AddJsonBody(Event); + await _restClient.PostAsync(request); + + var newDestination = UrlForPlayerAndEvent(Event.Location, Player.Name, Event.Id); + NavigationManager!.NavigateTo(newDestination); + } + } + + private static string UrlForPlayerAndEvent(string location, string name, string eventId) + { + var newDestination = "/playerEventHome?location=" + location + "&Name=" + name + "&EventId=" + eventId; + return newDestination; } } \ No newline at end of file diff --git a/website/Pages/PlayerSimilar.razor b/website/Pages/PlayerSimilar.razor index 2f93c51..e13929c 100644 --- a/website/Pages/PlayerSimilar.razor +++ b/website/Pages/PlayerSimilar.razor @@ -25,7 +25,7 @@ } - + logo
@@ -47,9 +47,9 @@ else {
-

Player Dashboard

+

Player Similarity

- Similar Players based on Highest Score, Speed and Acceleration + Vector Search based on Scores, Speed and Acceleration

@_errorMessage @@ -59,10 +59,12 @@
- + + +
- +
@@ -71,7 +73,7 @@
-

@@ -81,7 +83,7 @@ - + @@ -145,12 +147,9 @@ -
-
-     - View JSON data -     -
+ @@ -198,12 +197,9 @@ -
-
-     - View JSON data -     -
+ @@ -213,12 +209,9 @@
@rec.Name
-
-
-     - View JSON data -     -
+
@@ -228,12 +221,9 @@
@rec.Name
-
-
-     - View JSON data -     -
+
@@ -280,12 +270,9 @@ @rec.SessionStatisticsPlain.PowerUpPlayerSpeedCollected -
-
-     - View JSON data -     -
+ } @@ -297,7 +284,7 @@ private string _eventId = string.Empty; - private Player? Player { get; set; } = new(); + private Player? _player { get; set; } = new(); private List? Similar { get; set; } = new(); private List? SimilarByStats { get; set; } = new(); private List? SimilarBySpeed { get; set; } = new(); @@ -324,13 +311,13 @@ _name = queryParameters[Constants.QueryParameterName]; _eventId = queryParameters[Constants.QueryParameterEventId]; var playerFilter = new Dictionary - { + { { "name", _name } }; string playersUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, playerFilter); var players = await _restClient.GetJsonAsync>(playersUrlWithQuery); - Player = players.First(); + _player = players.First(); // overall similarity string similarUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilar, playerFilter); @@ -345,7 +332,7 @@ string similarByAccelUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointRecordingsSimilarByAccel, playerFilter); SimilarByAccel = await _restClient.GetJsonAsync>(similarByAccelUrlWithQuery); - ready = Player != null && Similar != null && SimilarByStats != null && SimilarBySpeed != null && SimilarByAccel != null; + ready = _player != null && Similar != null && SimilarByStats != null && SimilarBySpeed != null && SimilarByAccel != null; DotEnv.Load(); var envVars = DotEnv.Read(); diff --git a/website/Pages/PlayerSimilar_json.razor b/website/Pages/PlayerSimilar_json.razor index 1308e22..ebbac14 100644 --- a/website/Pages/PlayerSimilar_json.razor +++ b/website/Pages/PlayerSimilar_json.razor @@ -24,8 +24,7 @@ } - - + logo diff --git a/website/Utils/Constants.cs b/website/Utils/Constants.cs index 1669d40..52d91f4 100644 --- a/website/Utils/Constants.cs +++ b/website/Utils/Constants.cs @@ -8,6 +8,7 @@ public static class Constants public const string RestServiceEndpointPlayers = "players"; public const string RestServiceEndpointPlayersAutoComplete = "players/autocomplete"; public const string RestServiceEndpointPlayersSearch = "players/search"; + public const string RestServiceEndpointPlayersEvents = "players/events"; public const string RestServiceEndpointRecordings = "recordings"; public const string RestServiceEndpointRecordingsSimilar = "recordings/similar"; public const string RestServiceEndpointRecordingsSimilarBySpeed = "recordings/similarBySpeed";