diff --git a/rest_service/Controllers/EventsController.cs b/rest_service/Controllers/EventsController.cs index 93f15ed..24a75ff 100644 --- a/rest_service/Controllers/EventsController.cs +++ b/rest_service/Controllers/EventsController.cs @@ -38,14 +38,15 @@ public async Task> GetEvents([FromQuery] EventRequest eventR } [HttpPost(Name = "CreateEvent")] - public async Task CreateEvent(EventRequest eventRequest) + public async Task CreateEvent(EventRequest eventRequest) { Logger.LogDebug($"Route {nameof(CreateEvent)} called."); var newEvent = new Event() { Id = eventRequest.Id, Name = eventRequest.Name, - Location = eventRequest.Location + Location = eventRequest.Location, + EmailRequired = eventRequest.EmailRequired }; try { @@ -58,6 +59,6 @@ public async Task CreateEvent(EventRequest eventRequest) } - return newEvent; + return new EventResponse(newEvent); } } \ No newline at end of file diff --git a/rest_service/Controllers/PlayersController.cs b/rest_service/Controllers/PlayersController.cs index e7df03d..6610c81 100644 --- a/rest_service/Controllers/PlayersController.cs +++ b/rest_service/Controllers/PlayersController.cs @@ -53,7 +53,7 @@ public async Task> GetPlayers([FromQuery] PlayerRequest pla var playerUnique = _playersUniqueCollection .Find(Builders .Filter.Eq(x => x.Name, playerRequest.Name)) - .First(); + .FirstOrDefault(); if (playerUnique != null) filter &= Builders.Filter.Eq(x => x.Location, playerUnique.Location); diff --git a/rest_service/Dtos/RequestObjects/EventRequest.cs b/rest_service/Dtos/RequestObjects/EventRequest.cs index 0d4771a..7a2a96c 100644 --- a/rest_service/Dtos/RequestObjects/EventRequest.cs +++ b/rest_service/Dtos/RequestObjects/EventRequest.cs @@ -7,4 +7,5 @@ public class EventRequest [JsonProperty("id")] public string? Id { get; set; } [JsonProperty("name")] public string? Name { get; set; } [JsonProperty("location")] public string? Location { get; set; } + [JsonProperty("emailRequired")] public bool EmailRequired { get; set; } } \ No newline at end of file diff --git a/rest_service/Dtos/ResponseObjects/EventResponse.cs b/rest_service/Dtos/ResponseObjects/EventResponse.cs index 96cfee0..0030a16 100644 --- a/rest_service/Dtos/ResponseObjects/EventResponse.cs +++ b/rest_service/Dtos/ResponseObjects/EventResponse.cs @@ -8,11 +8,13 @@ public class EventResponse [BsonElement("_id")] public string? Id { get; set; } [BsonElement("name")] public string? Name { get; set; } [BsonElement("location")] public string? Location { get; set; } + [BsonElement("emailRequired")] public bool EmailRequired { get; set; } public EventResponse(Event @event) { Id = @event.Id; Name = @event.Name; Location = @event.Location; + EmailRequired = @event.EmailRequired; } } \ No newline at end of file diff --git a/rest_service/Entities/Event.cs b/rest_service/Entities/Event.cs index ba102b0..5d1668a 100644 --- a/rest_service/Entities/Event.cs +++ b/rest_service/Entities/Event.cs @@ -6,6 +6,11 @@ namespace RestService.Entities; public class Event { [BsonElement("_id")] public string? Id { get; set; } + [BsonElement("name")] public string? Name { get; set; } + [BsonElement("location")] public string? Location { get; set; } + + [BsonIgnoreIfDefault] + [BsonElement("emailRequired")] public bool EmailRequired { get; set; } } \ No newline at end of file diff --git a/website/Data/Event.cs b/website/Data/Event.cs index 64e5303..3fd7b3f 100644 --- a/website/Data/Event.cs +++ b/website/Data/Event.cs @@ -7,4 +7,5 @@ public class Event [JsonProperty("id")] public string? Id { get; set; } [JsonProperty("name")] public string? Name { get; set; } [JsonProperty("location")] public string? Location { get; set; } + [JsonProperty("emailRequired")] public bool EmailRequired { get; set; } } \ No newline at end of file diff --git a/website/Pages/EventRegister.razor b/website/Pages/EventRegister.razor index d085d50..2a0db67 100644 --- a/website/Pages/EventRegister.razor +++ b/website/Pages/EventRegister.razor @@ -119,7 +119,7 @@ Register @@ -196,10 +196,22 @@ return; } + if ((bool)_event.EmailRequired && string.IsNullOrEmpty(_player.Email)) + { + _errorMessage = "[please provide an email]"; + return; + } + _errorMessage = ""; - //TO-DO ADD FILTER FOR PLAYER!!!! - var playersUnique = await _restClient.GetJsonAsync>(Constants.RestServiceEndpointPlayers); + // Get Player + var playerFilter = new Dictionary + { + { "name", _player.Name } + }; + + string playersUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, playerFilter); + var playersUnique = await _restClient.GetJsonAsync>(playersUrlWithQuery); var filteredPlayersUnique = playersUnique!.FindAll(p => p.Name!.Equals(_player.Name)); var existingPlayer = filteredPlayersUnique.FirstOrDefault(); @@ -223,7 +235,7 @@ { if (string.IsNullOrEmpty(_player.Name)) { - _errorMessage = "[Enter your name!]"; + _errorMessage = "[Enter your Nickname!]"; return; } @@ -231,11 +243,10 @@ var args = new Dictionary { - { "Name", _player.Name } + { "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(); diff --git a/website/Pages/PlayerHome.razor b/website/Pages/PlayerHome.razor index ae39531..37f98ed 100644 --- a/website/Pages/PlayerHome.razor +++ b/website/Pages/PlayerHome.razor @@ -119,6 +119,19 @@ else + +
+ +
+ + + +
+ + + +
+
@@ -172,7 +185,7 @@ else // Get Player var playerFilter = new Dictionary -{ + { { "name", _name } }; @@ -227,9 +240,10 @@ else else { Event.Location = _location; // TO-DO + Console.WriteLine("############ Event.EmailRequired= " + Event.EmailRequired.ToString()); var request = new RestRequest(Constants.RestServiceEndpointEvents).AddJsonBody(Event); - await _restClient.PostAsync(request); + await _restClient.PostAsync(request); var newDestination = UrlForPlayerAndEvent(Event.Location, Player.Name, Event.Id); NavigationManager!.NavigateTo(newDestination);