diff --git a/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs b/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs index 25e368059..64fcc573c 100644 --- a/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs +++ b/Services/CO.CDP.DataSharing.WebApi/AutoMapper/DataSharingProfile.cs @@ -2,6 +2,7 @@ using CO.CDP.DataSharing.WebApi.Model; using CO.CDP.OrganisationInformation; using CO.CDP.OrganisationInformation.Persistence; +using System.Text.Json; using Address = CO.CDP.OrganisationInformation.Address; using Persistence = CO.CDP.OrganisationInformation.Persistence.Forms; @@ -101,7 +102,8 @@ public DataSharingProfile() .ForMember(m => m.EndValue, o => o.MapFrom(m => m.EndValue)) .ForMember(m => m.DateValue, o => o.MapFrom(m => ToDateOnly(m.DateValue))) .ForMember(m => m.TextValue, o => o.MapFrom(m => m.TextValue)) - .ForMember(m => m.OptionValue, o => o.Ignore()); + .ForMember(m => m.OptionValue, o => o.MapFrom(m => m.OptionValue != null ? new string[] { m.OptionValue } : null)) + .ForMember(m => m.JsonValue, o => o.MapFrom()); CreateMap() .ForMember(m => m.Type, o => o.MapFrom()) @@ -176,4 +178,17 @@ private string ToHtmlString(Persistence.FormAddress source) return $"{source.StreetAddress}
{source.Locality}
{source.PostalCode}
{source.Region}
{source.CountryName}"; } +} + +public class JsonValueResolver : IValueResolver?> +{ + public Dictionary? Resolve(Persistence.FormAnswer source, FormAnswer destination, Dictionary? destMember, ResolutionContext context) + { + if (string.IsNullOrEmpty(source.JsonValue)) + { + return null; + } + + return JsonSerializer.Deserialize>(source.JsonValue); + } } \ No newline at end of file diff --git a/Services/CO.CDP.DataSharing.WebApi/Model/FormAnswer.cs b/Services/CO.CDP.DataSharing.WebApi/Model/FormAnswer.cs index d2f33a4e3..af92de094 100644 --- a/Services/CO.CDP.DataSharing.WebApi/Model/FormAnswer.cs +++ b/Services/CO.CDP.DataSharing.WebApi/Model/FormAnswer.cs @@ -25,4 +25,7 @@ public record FormAnswer /// ["option-id-1"] public List OptionValue { get; init; } = []; + + /// {"id": "00000000-0000-0000-0000-000000000000", "type": "organisation OR connected-entity"} + public Dictionary? JsonValue { get; init; } } \ No newline at end of file