feat: add pre-humanized timestamp to api schema

This commit is contained in:
Oliver Booth 2023-08-10 14:34:52 +01:00
parent 1de869c6f0
commit 3868fcbaa8
Signed by: oliverbooth
GPG Key ID: 725DB725A0D9EE61
2 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Humanizer;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using OliverBooth.Data.Blog;
using OliverBooth.Services;
@ -43,6 +44,7 @@ public sealed class BlogApiController : ControllerBase
title = post.Title,
published = post.Published.ToUnixTimeSeconds(),
updated = post.Updated?.ToUnixTimeSeconds(),
humanizedTimestamp = post.Updated?.Humanize() ?? post.Published.Humanize(),
excerpt = _blogService.GetExcerpt(post, out bool trimmed),
trimmed,
url = Url.Page("/Blog/Article",

View File

@ -9,6 +9,7 @@
private readonly _url: string;
private readonly _trimmed: boolean;
private readonly _identifier: string;
private readonly _humanizedTimestamp: string;
constructor(json: any) {
this._id = json.id;
@ -21,6 +22,7 @@
this._url = json.url;
this._trimmed = json.trimmed;
this._identifier = json.identifier;
this._humanizedTimestamp = json.humanizedTimestamp;
}
get id(): number {
@ -62,6 +64,10 @@
get identifier(): string {
return this._identifier;
}
get humanizedTimestamp(): string {
return this._humanizedTimestamp;
}
}
export default BlogPost;