diff --git a/src/InternshipSystem.Api/Controllers/InternshipController.cs b/src/InternshipSystem.Api/Controllers/InternshipController.cs index e52bc44..9fdfa47 100644 --- a/src/InternshipSystem.Api/Controllers/InternshipController.cs +++ b/src/InternshipSystem.Api/Controllers/InternshipController.cs @@ -44,6 +44,7 @@ namespace InternshipSystem.Api.Controllers .Include(i => i.InternshipRegistration.Company) .Include(i => i.InternshipRegistration.BranchAddress) .Include(i => i.InternshipRegistration.Type) + .Include(i => i.InternshipRegistration.Subjects) .Include(i => i.Report) .Include(i => i.Documentation) .SingleAsync(i => i.Student.Id == user.PersonNumber, cancellationToken); diff --git a/src/InternshipSystem.Api/Converters/StringArrayConverter.cs b/src/InternshipSystem.Api/Converters/StringArrayConverter.cs new file mode 100644 index 0000000..e4c80ce --- /dev/null +++ b/src/InternshipSystem.Api/Converters/StringArrayConverter.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace InternshipSystem.Api.Converters +{ + public class StringArrayConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var token = JToken.Load(reader); + + if (token.Type == JTokenType.Array) + { + return token.ToObject>(); + } + + return new List + { + token.ToObject() + }; + } + + public override bool CanConvert(Type objectType) + { + return objectType == typeof(List); + } + + public override bool CanWrite => false; + } +} \ No newline at end of file diff --git a/src/InternshipSystem.Api/GutCasClient.cs b/src/InternshipSystem.Api/GutCasClient.cs index 08f0714..75784b6 100644 --- a/src/InternshipSystem.Api/GutCasClient.cs +++ b/src/InternshipSystem.Api/GutCasClient.cs @@ -1,11 +1,13 @@ using System.Collections.Generic; +using System.IO; using System.Net.Http; using System.Net.Http.Headers; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; using InternshipSystem.Api.Options; using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using JsonConverter = System.Text.Json.Serialization.JsonConverter; namespace InternshipSystem.Api.Controllers { @@ -39,9 +41,9 @@ namespace InternshipSystem.Api.Controllers }; var response = await _client.SendAsync(request, cancellationToken); - await using var stream = await response.Content.ReadAsStreamAsync(); + var content = await response.Content.ReadAsStringAsync(); - var value = await JsonSerializer.DeserializeAsync>(stream); + var value = JsonConvert.DeserializeObject>(content); return value["access_token"].ToString(); } @@ -60,15 +62,10 @@ namespace InternshipSystem.Api.Controllers request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); var response = await _client.SendAsync(request, cancellationToken); - await using var stream = await response.Content.ReadAsStreamAsync(); - - var result = await JsonSerializer.DeserializeAsync( - stream, - new JsonSerializerOptions - { - PropertyNameCaseInsensitive = true - }); + var content = await response.Content.ReadAsStringAsync(); + var result = JsonConvert.DeserializeObject(content); + return result.Attributes; } } diff --git a/src/InternshipSystem.Api/InternshipSystem.Api.csproj b/src/InternshipSystem.Api/InternshipSystem.Api.csproj index f512388..123f3c3 100644 --- a/src/InternshipSystem.Api/InternshipSystem.Api.csproj +++ b/src/InternshipSystem.Api/InternshipSystem.Api.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/InternshipSystem.Api/Result/CasUserData.cs b/src/InternshipSystem.Api/Result/CasUserData.cs index 560a3ac..14c90dd 100644 --- a/src/InternshipSystem.Api/Result/CasUserData.cs +++ b/src/InternshipSystem.Api/Result/CasUserData.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using InternshipSystem.Api.Converters; +using Newtonsoft.Json; namespace InternshipSystem.Api.Controllers { @@ -7,8 +9,12 @@ namespace InternshipSystem.Api.Controllers public string AlbumNumber { get; set; } public string FirstName { get; set; } public string LastName { get; set; } + + [JsonConverter(typeof(StringArrayConverter))] public List Mail { get; set; } public string PersonNumber { get; set; } + + [JsonConverter(typeof(StringArrayConverter))] public List Pg_Cui_Portalroles { get; set; } } } \ No newline at end of file