Skip to content

Commit

Permalink
Merge pull request #139 from mongodb-developer/main
Browse files Browse the repository at this point in the history
#137 email toggle per event
  • Loading branch information
snarvaez authored May 5, 2024
2 parents f8d06cd + 8f5d08d commit eaae4c5
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
7 changes: 4 additions & 3 deletions rest_service/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public async Task<List<EventResponse>> GetEvents([FromQuery] EventRequest eventR
}

[HttpPost(Name = "CreateEvent")]
public async Task<Event> CreateEvent(EventRequest eventRequest)
public async Task<EventResponse> 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
{
Expand All @@ -58,6 +59,6 @@ public async Task<Event> CreateEvent(EventRequest eventRequest)
}


return newEvent;
return new EventResponse(newEvent);
}
}
2 changes: 1 addition & 1 deletion rest_service/Controllers/PlayersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task<List<PlayerResponse>> GetPlayers([FromQuery] PlayerRequest pla
var playerUnique = _playersUniqueCollection
.Find(Builders<PlayerUnique>
.Filter.Eq(x => x.Name, playerRequest.Name))
.First<PlayerUnique>();
.FirstOrDefault<PlayerUnique>();

if (playerUnique != null)
filter &= Builders<Player>.Filter.Eq(x => x.Location, playerUnique.Location);
Expand Down
1 change: 1 addition & 0 deletions rest_service/Dtos/RequestObjects/EventRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
2 changes: 2 additions & 0 deletions rest_service/Dtos/ResponseObjects/EventResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 5 additions & 0 deletions rest_service/Entities/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
1 change: 1 addition & 0 deletions website/Data/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
16 changes: 14 additions & 2 deletions website/Pages/EventRegister.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<Player>>(Constants.RestServiceEndpointPlayers);
// Get Player
var playerFilter = new Dictionary<string, string>
{
{ "name", _player.Name }
};

string playersUrlWithQuery = UrlHelper.BuildUrlWithQuery(Constants.RestServiceEndpointPlayers, playerFilter);
var playersUnique = await _restClient.GetJsonAsync<List<Player>>(playersUrlWithQuery);
var filteredPlayersUnique = playersUnique!.FindAll(p => p.Name!.Equals(_player.Name));
var existingPlayer = filteredPlayersUnique.FirstOrDefault();

Expand Down
18 changes: 16 additions & 2 deletions website/Pages/PlayerHome.razor
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ else
<input id="eventName" @bind="Event.Name" name="" class="form-control"
placeholder="Friendly description" type="text">
</div> <!-- form-group// -->

<div class="form-group input-group">

<div class="input-group-prepend">
<span class="input-group-text">
<i class="fa fa-comment"></i>
</span>
</div>

<input id="emailRequired" @bind="Event.EmailRequired" class="input.largerCheckbox" name="" type="checkbox" style="width:30px;height:30px">
<label for="emailRequired">&nbsp;eMail required</label>
</div> <!-- form-group// -->

<!-- TO DO: Obtain location from autocomplete box -->

<div class="form-group">
Expand Down Expand Up @@ -172,7 +185,7 @@ else

// Get Player
var playerFilter = new Dictionary<string, string>
{
{
{ "name", _name }
};

Expand Down Expand Up @@ -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<Player>(request);
await _restClient.PostAsync<Event>(request);

var newDestination = UrlForPlayerAndEvent(Event.Location, Player.Name, Event.Id);
NavigationManager!.NavigateTo(newDestination);
Expand Down

0 comments on commit eaae4c5

Please sign in to comment.