Skip to content

Commit

Permalink
Json Serializing bugs fixed (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Brands (RiwaAdmin) <[email protected]>
  • Loading branch information
rbrands and Robert Brands (RiwaAdmin) authored Jan 24, 2024
1 parent 5e4e381 commit 4e1f68d
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 21 deletions.
2 changes: 1 addition & 1 deletion MeetUpFunctions/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class Constants
public const string DEFAULT_DISCLAIMER = "Disclaimer";
public const string DEFAULT_GUEST_DISCLAIMER = "Guest Disclaimer";

public const string VERSION = "2024-01-02";
public const string VERSION = "2024-01-24";
public const int ADMINOVERBOOKFACTOR = 1; // no overbooking any more, because not needed

public const int LOG_TTL = 30 * 24 * 3600; // 30 days TTL for Log items
Expand Down
102 changes: 102 additions & 0 deletions MeetUpFunctions/RemoveParticipantFromCalendarItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,108 @@ CosmosDBRepository<Participant> cosmosRepository
}

[FunctionName("RemoveParticipantFromCalendarItem")]






































































































public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req)
{
Expand Down
2 changes: 0 additions & 2 deletions MeetUpPlanner/Client/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public string DisplayName
return sb.ToString();
}
}
[MaxLength(120, ErrorMessage = "Die Tel-Nr/Mail-Adresse ist zu lang"), MinLength(8, ErrorMessage = "Die Tel-Nr/Mail-Adresse ist zu kurz.")]
[Required(ErrorMessage = "Tel-Nr/Mail-Adresse fehlen.")]
public string PhoneMail { get; set; }
public Boolean NoAddressNeeded { get; set; } = false;
public bool SaveSettings { get; set; } = true;
Expand Down
23 changes: 23 additions & 0 deletions MeetUpPlanner/Client/BackendApiRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using Azure.Storage.Blobs;
using Azure.Core;
using System.Text;
using Newtonsoft.Json;
using Radzen;
using static System.Net.WebRequestMethods;

namespace MeetUpPlanner.Client
{
Expand Down Expand Up @@ -250,6 +253,26 @@ public async Task RemoveFederation(CalendarItem calendarItem)
return;

}
public async Task<BackendResult> RemoveParticipant(Participant participant)
{
this.PrepareHttpClient();
HttpResponseMessage response = await _http.PostAsJsonAsync<Participant>($"Calendar/removeparticipant", participant);
string responseBody = await response.Content.ReadAsStringAsync();

BackendResult result = JsonConvert.DeserializeObject<BackendResult>(responseBody);
return result;
}
public async Task<BackendResult> AddParticipant(Participant participant)
{
this.PrepareHttpClient();
HttpResponseMessage response = await _http.PostAsJsonAsync<Participant>($"Calendar/addparticipant", participant);
string responseBody = await response.Content.ReadAsStringAsync();

BackendResult result = JsonConvert.DeserializeObject<BackendResult>(responseBody);
return result;
}



}
}
2 changes: 1 addition & 1 deletion MeetUpPlanner/Client/Pages/About.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</div>

@code {
private const string clientVersion = "2024-01-02";
private const string clientVersion = "2024-01-24";
private string serverVersion = "tbd";
private string functionsVersion = "tbd";

Expand Down
12 changes: 2 additions & 10 deletions MeetUpPlanner/Client/Pages/Calendar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,7 @@
participant.CalendarItemId = itemId;
checkInDisabled = true;
StateHasChanged();
PrepareHttpClient();
HttpResponseMessage response = await Http.PostAsJsonAsync<Participant>($"Calendar/addparticipant", participant);
string responseBody = await response.Content.ReadAsStringAsync();

BackendResult result = JsonConvert.DeserializeObject<BackendResult>(responseBody);
BackendResult result = await Api.AddParticipant(participant);
if (result.Success)
{
if (IsConnected) await SendMessage();
Expand Down Expand Up @@ -518,11 +514,7 @@
// Find corresponding participant item
Participant participant = calendarItem.FindParticipant(AppStateStore.FirstName, AppStateStore.LastName);

PrepareHttpClient();
HttpResponseMessage response = await Http.PostAsJsonAsync<Participant>($"Calendar/removeparticipant", participant);
string responseBody = await response.Content.ReadAsStringAsync();

BackendResult result = JsonConvert.DeserializeObject<BackendResult>(responseBody);
BackendResult result = await Api.RemoveParticipant(participant);
if (result.Success)
{
if (IsConnected) await SendMessage();
Expand Down
4 changes: 4 additions & 0 deletions MeetUpPlanner/Server/Controllers/CalendarController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MeetUpPlanner.Shared;
using System;


namespace MeetUpPlanner.Server.Controllers
{
[Route("[controller]")]
Expand Down Expand Up @@ -53,6 +54,7 @@ public async Task<IActionResult> GetCalendarItems([FromHeader(Name = "x-meetup-t
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> GetExtendedCalendarItems([FromHeader(Name = "x-meetup-tenant")] string tenant, [FromHeader(Name = "x-meetup-keyword")] string keyword, [FromQuery] string privatekeywords)
{
logger.LogInformation("GetExtendedCalendarItems()");
if (String.IsNullOrEmpty(keyword))
{
keyword = _meetUpFunctions.InviteGuestKey;
Expand Down Expand Up @@ -117,6 +119,7 @@ public async Task<IActionResult> GetExtendedCalendarItemForGuest([FromHeader(Nam
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> AddParticipant([FromHeader(Name = "x-meetup-tenant")] string tenant, [FromHeader(Name = "x-meetup-keyword")] string keyword, [FromBody] Participant participant)
{
logger.LogInformation("AddParticipant");
if (String.IsNullOrEmpty(keyword))
{
keyword = _meetUpFunctions.InviteGuestKey;
Expand Down Expand Up @@ -146,6 +149,7 @@ public async Task<IActionResult> AddGuest([FromHeader(Name = "x-meetup-tenant")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> RemoveParticipant([FromHeader(Name = "x-meetup-tenant")] string tenant, [FromHeader(Name = "x-meetup-keyword")] string keyword, [FromBody] Participant participant)
{
logger.LogInformation("RemoveParticipant");
if (String.IsNullOrEmpty(keyword))
{
keyword = _meetUpFunctions.InviteGuestKey;
Expand Down
2 changes: 1 addition & 1 deletion MeetUpPlanner/Server/Controllers/UtilController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class UtilController : ControllerBase
{
private readonly MeetUpFunctions _meetUpFunctions;
private readonly ILogger<UtilController> logger;
const string serverVersion = "2024-01-20";
const string serverVersion = "2024-01-24";
string functionsVersion = "tbd";

public UtilController(ILogger<UtilController> logger, MeetUpFunctions meetUpFunctions)
Expand Down
11 changes: 8 additions & 3 deletions MeetUpPlanner/Server/Controllers/WinterpokalController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Threading.Tasks;
using Flurl.Http;
using Flurl;
using Flurl.Http.Newtonsoft;
using Newtonsoft.Json;
using Microsoft.Extensions.Logging;
using MeetUpPlanner.Server.Repositories;
using MeetUpPlanner.Shared;
Expand All @@ -29,15 +31,18 @@ public WinterpokalController(ILogger<WinterpokalController> logger, WinterpokalC
public async Task<WinterpokalTeam> GetTeam([FromRoute] string teamId)
{
_logger.LogInformation($"GetTeam({teamId})");

// To get the dynamic from the serializer Newtonsoft.Json has to be used,
// see https://www.nuget.org/packages/Flurl.Http.Newtonsoft/#readme-body-tab
dynamic response = await $"{_winterpokalConfig.ApiEndpoint}/api/v1/teams/get/{teamId}.json"
.WithHeader("api-token", _winterpokalConfig.ApiKey)
.GetJsonAsync<dynamic>();
.WithSettings(s => { s.JsonSerializer = new NewtonsoftJsonSerializer(); })
.GetJsonAsync();
WinterpokalTeam team = new WinterpokalTeam()
{
Id = Convert.ToInt64(teamId)
};
if (response.status != "OK")

if ( response.status != "OK" )
{
team.Name = "Team unbekannt";
}
Expand Down
1 change: 1 addition & 0 deletions MeetUpPlanner/Server/MeetUpPlanner.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Flurl" Version="4.0.0" />
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="Flurl.Http.Newtonsoft" Version="0.9.1" />
<PackageReference Include="Ical.Net" Version="4.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="7.0.15" />
Expand Down
6 changes: 3 additions & 3 deletions MeetUpPlanner/Shared/Participant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class Participant : CosmosDBEntity
/// </summary>
[JsonProperty(PropertyName = "calendarItemId")]
public string CalendarItemId { get; set; }
[JsonProperty(PropertyName = "participantFirstName"), MaxLength(100), Required(ErrorMessage = "Vornamen bitte eingeben.")]
[JsonProperty(PropertyName = "participantFirstName"), MaxLength(100)]
public string ParticipantFirstName { get; set; }
[JsonProperty(PropertyName = "participantLastName"), MaxLength(100), Required(ErrorMessage = "Nachnamen bitte eingeben.")]
[JsonProperty(PropertyName = "participantLastName"), MaxLength(100)]
public string ParticipantLastName { get; set; }
[JsonProperty(PropertyName = "participantAddressName", NullValueHandling = NullValueHandling.Ignore), MaxLength(100), Required(ErrorMessage = "Bitte eine Adress-Info eingeben.")]
[JsonProperty(PropertyName = "participantAdressInfo"), MaxLength(100)]
public string ParticipantAdressInfo { get; set; }
[JsonProperty(PropertyName = "checkInDate")]
public DateTime CheckInDate { get; set; }
Expand Down

0 comments on commit 4e1f68d

Please sign in to comment.