feat: add pre-humanized timestamp to api schema
This commit is contained in:
parent
1de869c6f0
commit
3868fcbaa8
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Humanizer;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using OliverBooth.Data.Blog;
|
using OliverBooth.Data.Blog;
|
||||||
using OliverBooth.Services;
|
using OliverBooth.Services;
|
||||||
|
@ -43,6 +44,7 @@ public sealed class BlogApiController : ControllerBase
|
||||||
title = post.Title,
|
title = post.Title,
|
||||||
published = post.Published.ToUnixTimeSeconds(),
|
published = post.Published.ToUnixTimeSeconds(),
|
||||||
updated = post.Updated?.ToUnixTimeSeconds(),
|
updated = post.Updated?.ToUnixTimeSeconds(),
|
||||||
|
humanizedTimestamp = post.Updated?.Humanize() ?? post.Published.Humanize(),
|
||||||
excerpt = _blogService.GetExcerpt(post, out bool trimmed),
|
excerpt = _blogService.GetExcerpt(post, out bool trimmed),
|
||||||
trimmed,
|
trimmed,
|
||||||
url = Url.Page("/Blog/Article",
|
url = Url.Page("/Blog/Article",
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
private readonly _url: string;
|
private readonly _url: string;
|
||||||
private readonly _trimmed: boolean;
|
private readonly _trimmed: boolean;
|
||||||
private readonly _identifier: string;
|
private readonly _identifier: string;
|
||||||
|
private readonly _humanizedTimestamp: string;
|
||||||
|
|
||||||
constructor(json: any) {
|
constructor(json: any) {
|
||||||
this._id = json.id;
|
this._id = json.id;
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
this._url = json.url;
|
this._url = json.url;
|
||||||
this._trimmed = json.trimmed;
|
this._trimmed = json.trimmed;
|
||||||
this._identifier = json.identifier;
|
this._identifier = json.identifier;
|
||||||
|
this._humanizedTimestamp = json.humanizedTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
get id(): number {
|
get id(): number {
|
||||||
|
@ -62,6 +64,10 @@
|
||||||
get identifier(): string {
|
get identifier(): string {
|
||||||
return this._identifier;
|
return this._identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get humanizedTimestamp(): string {
|
||||||
|
return this._humanizedTimestamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BlogPost;
|
export default BlogPost;
|
Loading…
Reference in New Issue