diff options
author | 杨宇千 <crupest@outlook.com> | 2020-02-03 18:38:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-03 18:38:14 +0800 |
commit | 97010e98a11ad6fd6c075cee414c30174001fe5d (patch) | |
tree | 28ef20f9dfe742008bb934f09b99d1d4719cabaa /Timeline/Models/Http/TimelineCommon.cs | |
parent | 1c880744293c9f47ff1241109b72c035680251df (diff) | |
parent | be8cbe2c4ddf2076cc02bcb2feb1a70d30a4bda0 (diff) | |
download | timeline-97010e98a11ad6fd6c075cee414c30174001fe5d.tar.gz timeline-97010e98a11ad6fd6c075cee414c30174001fe5d.tar.bz2 timeline-97010e98a11ad6fd6c075cee414c30174001fe5d.zip |
Merge pull request #57 from crupest/dev
Add normal timeline feature.
Diffstat (limited to 'Timeline/Models/Http/TimelineCommon.cs')
-rw-r--r-- | Timeline/Models/Http/TimelineCommon.cs | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/Timeline/Models/Http/TimelineCommon.cs b/Timeline/Models/Http/TimelineCommon.cs index febb8186..1cb47dac 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,56 @@ 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<UserInfo> 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 TimelineInfo : BaseTimelineInfo
+ public class TimelineInfoLinks
{
- public string Name { get; set; } = default!;
+ public string Posts { get; set; } = default!;
+ }
+
+ public static class TimelineInfoExtensions
+ {
+ public static TimelineInfo FillLinksForPersonalTimeline(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;
+ }
+
+ public static TimelineInfo FillLinksForNormalTimeline(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(TimelineController.PostListGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { info.Name })
+ };
+
+ return info;
+ }
}
}
|