Skip to content

Commit

Permalink
class per element value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Chrastina committed Mar 21, 2023
1 parent 2c6b5e9 commit fee4742
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Kontent.Ai.Delivery.ContentItems.Elements
{
internal class CustomElementValue : StringElementValue
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using Kontent.Ai.Delivery.Abstractions;

namespace Kontent.Ai.Delivery.ContentItems.Elements
{
internal class MultipleChoiceElementValue: ContentElementValue<IEnumerable<IMultipleChoiceOption>>
{

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Kontent.Ai.Delivery.ContentItems.Elements
{
internal class StringElementValue : ContentElementValue<string>
internal abstract class StringElementValue : ContentElementValue<string>
{
}
}
7 changes: 7 additions & 0 deletions Kontent.Ai.Delivery/ContentItems/Elements/TextElementValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Kontent.Ai.Delivery.ContentItems.Elements
{
internal class TextElementValue : StringElementValue
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Kontent.Ai.Delivery.ContentItems.Elements
{
internal class UrlSlugElementValue : StringElementValue
{

}
}
14 changes: 8 additions & 6 deletions Kontent.Ai.Delivery/ContentItems/ModelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,16 @@ private ContentItemElements GetAllPropertiesValuesAsync(JObject elementsData, Pr
"rich_text" => element.ToObject<RichTextElementValue>(Serializer),
"asset" => element.ToObject<AssetElementValue>(Serializer),
"number" => element.ToObject<NumberElementValue>(Serializer),
// TODO do we want to use string/structured data for date time
// TODO do we want to use string/structured data for date time => structured is OK
"date_time" => element.ToObject<DateTimeElementValue>(Serializer),
"multiple_choice" => element.ToObject<ContentElementValue<IEnumerable<MultipleChoiceOption>>>(Serializer),
"taxonomy" => element.ToObject<ContentElementValue<IEnumerable<ITaxonomyTerm>>>(Serializer),
"multiple_choice" => element.ToObject<MultipleChoiceElementValue>(Serializer),
"taxonomy" => element.ToObject<TaxonomyElementValue>(Serializer),
// TODO what Linked items + what SubPages?
"modular_content" => element.ToObject<ContentElementValue<IEnumerable<string>>>(Serializer),
// TODO do we need to split this into UrlSlugElementValue/CustomElementValue/TextElementValue => Custom value has Searchable value => split to more classes
// Custom element, text element, URL slug element
_ => element.ToObject<StringElementValue>(Serializer)
"custom_element" => element.ToObject<CustomElementValue>(Serializer),
"url_slug" => element.ToObject<UrlSlugElementValue>(Serializer),
"text" => element.ToObject<TextElementValue>(Serializer),
_ => throw new ArgumentException($"Argument type {element["type"].ToString()} not supported.")
};

// TODO Fix the empty Codename? Probably yes (wrap ToObject with normalization logic)
Expand Down

0 comments on commit fee4742

Please sign in to comment.