Add create and update dates to Delivery API response (#14427)

Co-authored-by: Elitsa <elm@umbraco.dk>
This commit is contained in:
Kenn Jacobsen
2023-06-26 07:33:16 +02:00
committed by GitHub
parent e92ea34098
commit 2c9d0b2cb1
7 changed files with 22 additions and 10 deletions

View File

@@ -10,6 +10,6 @@ public sealed class ApiContentBuilder : ApiContentBuilderBase<IApiContent>, IApi
{
}
protected override IApiContent Create(IPublishedContent content, Guid id, string name, string contentType, IApiContentRoute route, IDictionary<string, object?> properties)
=> new ApiContent(id, name, contentType, route, properties);
protected override IApiContent Create(IPublishedContent content, string name, IApiContentRoute route, IDictionary<string, object?> properties)
=> new ApiContent(content.Key, name, content.ContentType.Alias, content.CreateDate, content.UpdateDate, route, properties);
}

View File

@@ -17,7 +17,7 @@ public abstract class ApiContentBuilderBase<T>
_outputExpansionStrategyAccessor = outputExpansionStrategyAccessor;
}
protected abstract T Create(IPublishedContent content, Guid id, string name, string contentType, IApiContentRoute route, IDictionary<string, object?> properties);
protected abstract T Create(IPublishedContent content, string name, IApiContentRoute route, IDictionary<string, object?> properties);
public virtual T? Build(IPublishedContent content)
{
@@ -34,9 +34,7 @@ public abstract class ApiContentBuilderBase<T>
return Create(
content,
content.Key,
_apiContentNameProvider.GetName(content),
content.ContentType.Alias,
route,
properties);
}

View File

@@ -13,7 +13,7 @@ public sealed class ApiContentResponseBuilder : ApiContentBuilderBase<IApiConten
: base(apiContentNameProvider, apiContentRouteBuilder, outputExpansionStrategyAccessor)
=> _apiContentRouteBuilder = apiContentRouteBuilder;
protected override IApiContentResponse Create(IPublishedContent content, Guid id, string name, string contentType, IApiContentRoute route, IDictionary<string, object?> properties)
protected override IApiContentResponse Create(IPublishedContent content, string name, IApiContentRoute route, IDictionary<string, object?> properties)
{
var routesByCulture = new Dictionary<string, IApiContentRoute>();
@@ -35,6 +35,6 @@ public sealed class ApiContentResponseBuilder : ApiContentBuilderBase<IApiConten
routesByCulture[publishedCultureInfo.Culture] = cultureRoute;
}
return new ApiContentResponse(id, name, contentType, route, properties, routesByCulture);
return new ApiContentResponse(content.Key, name, content.ContentType.Alias, content.CreateDate, content.UpdateDate, route, properties, routesByCulture);
}
}

View File

@@ -2,14 +2,20 @@ namespace Umbraco.Cms.Core.Models.DeliveryApi;
public class ApiContent : ApiElement, IApiContent
{
public ApiContent(Guid id, string name, string contentType, IApiContentRoute route, IDictionary<string, object?> properties)
public ApiContent(Guid id, string name, string contentType, DateTime createDate, DateTime updateDate, IApiContentRoute route, IDictionary<string, object?> 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; }
}

View File

@@ -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<string, object?> properties, IDictionary<string, IApiContentRoute> cultures)
: base(id, name, contentType, route, properties)
public ApiContentResponse(Guid id, string name, string contentType, DateTime createDate, DateTime updateDate, IApiContentRoute route, IDictionary<string, object?> properties, IDictionary<string, IApiContentRoute> 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.

View File

@@ -4,5 +4,9 @@ public interface IApiContent : IApiElement
{
string? Name { get; }
public DateTime CreateDate { get; }
public DateTime UpdateDate { get; }
IApiContentRoute Route { get; }
}