From 9e84b1e9ad1f2a45cd3e09759c69989fdc588c3d Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 2 Feb 2020 00:31:33 +0800 Subject: ... --- Timeline/Models/Http/TimelineCommon.cs | 36 +++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'Timeline/Models') diff --git a/Timeline/Models/Http/TimelineCommon.cs b/Timeline/Models/Http/TimelineCommon.cs index febb8186..0b2a714c 100644 --- a/Timeline/Models/Http/TimelineCommon.cs +++ b/Timeline/Models/Http/TimelineCommon.cs @@ -1,5 +1,7 @@ -using System; +using Microsoft.AspNetCore.Mvc; +using System; using System.Collections.Generic; +using Timeline.Controllers; namespace Timeline.Models.Http { @@ -28,17 +30,41 @@ namespace Timeline.Models.Http public DateTime LastUpdated { get; set; } = default!; } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is a DTO class.")] - public class BaseTimelineInfo + public class TimelineInfo { + public string? Name { get; set; } public string Description { get; set; } = default!; public UserInfo Owner { get; set; } = default!; public TimelineVisibility Visibility { get; set; } +#pragma warning disable CA2227 // Collection properties should be read only public List Members { get; set; } = default!; +#pragma warning restore CA2227 // Collection properties should be read only + +#pragma warning disable CA1707 // Identifiers should not contain underscores + public TimelineInfoLinks? _links { get; set; } +#pragma warning restore CA1707 // Identifiers should not contain underscores + } + + public class TimelineInfoLinks + { + public string Posts { get; set; } = default!; } - public class TimelineInfo : BaseTimelineInfo + public static class TimelineInfoExtensions { - public string Name { get; set; } = default!; + public static TimelineInfo FillLinks(this TimelineInfo info, IUrlHelper urlHelper) + { + if (info == null) + throw new ArgumentNullException(nameof(info)); + if (urlHelper == null) + throw new ArgumentNullException(nameof(urlHelper)); + + info._links = new TimelineInfoLinks + { + Posts = urlHelper.ActionLink(nameof(PersonalTimelineController.PostListGet), nameof(PersonalTimelineController)[0..^nameof(Controller).Length], new { info.Owner.Username }) + }; + + return info; + } } } -- cgit v1.2.3