From 2c9d0b2cb1f0e9508b66c7c2401481b6cac1faa2 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Mon, 26 Jun 2023 07:33:16 +0200 Subject: [PATCH] Add create and update dates to Delivery API response (#14427) Co-authored-by: Elitsa --- src/Umbraco.Core/DeliveryApi/ApiContentBuilder.cs | 4 ++-- src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs | 4 +--- src/Umbraco.Core/DeliveryApi/ApiContentResponseBuilder.cs | 4 ++-- src/Umbraco.Core/Models/DeliveryApi/ApiContent.cs | 8 +++++++- src/Umbraco.Core/Models/DeliveryApi/ApiContentResponse.cs | 4 ++-- src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs | 4 ++++ .../Umbraco.Core/DeliveryApi/ContentBuilderTests.cs | 4 ++++ 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/DeliveryApi/ApiContentBuilder.cs b/src/Umbraco.Core/DeliveryApi/ApiContentBuilder.cs index 11ea4faf77..135afe068a 100644 --- a/src/Umbraco.Core/DeliveryApi/ApiContentBuilder.cs +++ b/src/Umbraco.Core/DeliveryApi/ApiContentBuilder.cs @@ -10,6 +10,6 @@ public sealed class ApiContentBuilder : ApiContentBuilderBase, IApi { } - protected override IApiContent Create(IPublishedContent content, Guid id, string name, string contentType, IApiContentRoute route, IDictionary properties) - => new ApiContent(id, name, contentType, route, properties); + protected override IApiContent Create(IPublishedContent content, string name, IApiContentRoute route, IDictionary properties) + => new ApiContent(content.Key, name, content.ContentType.Alias, content.CreateDate, content.UpdateDate, route, properties); } diff --git a/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs b/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs index ae70f0fdde..8ffcd6d849 100644 --- a/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs +++ b/src/Umbraco.Core/DeliveryApi/ApiContentBuilderBase.cs @@ -17,7 +17,7 @@ public abstract class ApiContentBuilderBase _outputExpansionStrategyAccessor = outputExpansionStrategyAccessor; } - protected abstract T Create(IPublishedContent content, Guid id, string name, string contentType, IApiContentRoute route, IDictionary properties); + protected abstract T Create(IPublishedContent content, string name, IApiContentRoute route, IDictionary properties); public virtual T? Build(IPublishedContent content) { @@ -34,9 +34,7 @@ public abstract class ApiContentBuilderBase return Create( content, - content.Key, _apiContentNameProvider.GetName(content), - content.ContentType.Alias, route, properties); } diff --git a/src/Umbraco.Core/DeliveryApi/ApiContentResponseBuilder.cs b/src/Umbraco.Core/DeliveryApi/ApiContentResponseBuilder.cs index eb9cea6961..a551115a1e 100644 --- a/src/Umbraco.Core/DeliveryApi/ApiContentResponseBuilder.cs +++ b/src/Umbraco.Core/DeliveryApi/ApiContentResponseBuilder.cs @@ -13,7 +13,7 @@ public sealed class ApiContentResponseBuilder : ApiContentBuilderBase _apiContentRouteBuilder = apiContentRouteBuilder; - protected override IApiContentResponse Create(IPublishedContent content, Guid id, string name, string contentType, IApiContentRoute route, IDictionary properties) + protected override IApiContentResponse Create(IPublishedContent content, string name, IApiContentRoute route, IDictionary properties) { var routesByCulture = new Dictionary(); @@ -35,6 +35,6 @@ public sealed class ApiContentResponseBuilder : ApiContentBuilderBase properties) + public ApiContent(Guid id, string name, string contentType, DateTime createDate, DateTime updateDate, IApiContentRoute route, IDictionary properties) : base(id, contentType, properties) { Name = name; + CreateDate = createDate; + UpdateDate = updateDate; Route = route; } public string Name { get; } + public DateTime CreateDate { get; } + + public DateTime UpdateDate { get; } + public IApiContentRoute Route { get; } } diff --git a/src/Umbraco.Core/Models/DeliveryApi/ApiContentResponse.cs b/src/Umbraco.Core/Models/DeliveryApi/ApiContentResponse.cs index d692ff464e..ce57cf7417 100644 --- a/src/Umbraco.Core/Models/DeliveryApi/ApiContentResponse.cs +++ b/src/Umbraco.Core/Models/DeliveryApi/ApiContentResponse.cs @@ -4,8 +4,8 @@ namespace Umbraco.Cms.Core.Models.DeliveryApi; public class ApiContentResponse : ApiContent, IApiContentResponse { - public ApiContentResponse(Guid id, string name, string contentType, IApiContentRoute route, IDictionary properties, IDictionary cultures) - : base(id, name, contentType, route, properties) + public ApiContentResponse(Guid id, string name, string contentType, DateTime createDate, DateTime updateDate, IApiContentRoute route, IDictionary properties, IDictionary cultures) + : base(id, name, contentType, createDate, updateDate, route, properties) => Cultures = cultures; // a little DX; by default this dictionary will be serialized as the first part of the response due to the inner workings of the serializer. diff --git a/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs b/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs index 0f605eda19..9192cbe7d5 100644 --- a/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs +++ b/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs @@ -4,5 +4,9 @@ public interface IApiContent : IApiElement { string? Name { get; } + public DateTime CreateDate { get; } + + public DateTime UpdateDate { get; } + IApiContentRoute Route { get; } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ContentBuilderTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ContentBuilderTests.cs index 026ab42c0c..6e0dfd7e6f 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ContentBuilderTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ContentBuilderTests.cs @@ -28,6 +28,8 @@ public class ContentBuilderTests : DeliveryApiTests var urlSegment = "url-segment"; var name = "The page"; ConfigurePublishedContentMock(content, key, name, urlSegment, contentType.Object, new[] { prop1, prop2 }); + content.SetupGet(c => c.CreateDate).Returns(new DateTime(2023, 06, 01)); + content.SetupGet(c => c.UpdateDate).Returns(new DateTime(2023, 07, 12)); var publishedUrlProvider = new Mock(); publishedUrlProvider @@ -47,6 +49,8 @@ public class ContentBuilderTests : DeliveryApiTests Assert.AreEqual(2, result.Properties.Count); Assert.AreEqual("Delivery API value", result.Properties["deliveryApi"]); Assert.AreEqual("Default value", result.Properties["default"]); + Assert.AreEqual(new DateTime(2023, 06, 01), result.CreateDate); + Assert.AreEqual(new DateTime(2023, 07, 12), result.UpdateDate); } [Test]