aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-03-10 19:37:58 +0800
committercrupest <crupest@outlook.com>2020-03-10 19:37:58 +0800
commit95be9f58b7cf76f1c585791447e8393d61862e1c (patch)
treeb9165a233b00c4ab5be47f0ce786b64c178a9fdf /Timeline/Models
parent88232f85e69a5e4b390e73344b31372746d4adca (diff)
downloadtimeline-95be9f58b7cf76f1c585791447e8393d61862e1c.tar.gz
timeline-95be9f58b7cf76f1c585791447e8393d61862e1c.tar.bz2
timeline-95be9f58b7cf76f1c585791447e8393d61862e1c.zip
...
Diffstat (limited to 'Timeline/Models')
-rw-r--r--Timeline/Models/Http/Timeline.cs24
-rw-r--r--Timeline/Models/Http/UserInfo.cs2
-rw-r--r--Timeline/Models/Timeline.cs17
3 files changed, 31 insertions, 12 deletions
diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs
index 55c3a3bf..9e2aefd0 100644
--- a/Timeline/Models/Http/Timeline.cs
+++ b/Timeline/Models/Http/Timeline.cs
@@ -72,25 +72,27 @@ namespace Timeline.Models.Http
}
}
- public class TimelinePostConverter : ITypeConverter<ITimelinePostContent, TimelinePostContentInfo>
+ public class TimelinePostContentResolver : IValueResolver<TimelinePost, TimelinePostInfo, TimelinePostContentInfo>
{
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
- public TimelinePostConverter(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ public TimelinePostContentResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
{
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
}
- public TimelinePostContentInfo Convert(ITimelinePostContent source, TimelinePostContentInfo destination, ResolutionContext context)
+ public TimelinePostContentInfo Resolve(TimelinePost source, TimelinePostInfo destination, TimelinePostContentInfo destMember, ResolutionContext context)
{
if (_actionContextAccessor.ActionContext == null)
throw new InvalidOperationException("No action context, can't fill urls.");
var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);
- if (source is TextTimelinePostContent textContent)
+ var sourceContent = source.Content;
+
+ if (sourceContent is TextTimelinePostContent textContent)
{
return new TimelinePostContentInfo
{
@@ -98,14 +100,21 @@ namespace Timeline.Models.Http
Text = textContent.Text
};
}
- else if (source is ImageTimelinePostContent imageContent)
+ else if (sourceContent is ImageTimelinePostContent imageContent)
{
return new TimelinePostContentInfo
{
Type = TimelinePostContentTypes.Image,
- Url = urlHelper.ActionLink(action: "PostDataGet", nameof(TimelineController)[0..^nameof(Controller).Length], new { source.Name })
+ Url = urlHelper.ActionLink(
+ action: nameof(TimelineController.PostDataGet),
+ controller: nameof(TimelineController)[0..^nameof(Controller).Length],
+ values: new { Name = source.TimelineName, Id = source.Id })
};
}
+ else
+ {
+ throw new InvalidOperationException("Unknown content type.");
+ }
}
}
@@ -114,8 +123,7 @@ namespace Timeline.Models.Http
public TimelineInfoAutoMapperProfile()
{
CreateMap<Timeline, TimelineInfo>().ForMember(u => u._links, opt => opt.MapFrom<TimelineInfoLinksValueResolver>());
- CreateMap<TimelinePost, TimelinePostInfo>();
- CreateMap<ITimelinePostContent, TimelinePostContentInfo>().ConvertUsing<TimelinePostConverter>();
+ CreateMap<TimelinePost, TimelinePostInfo>().ForMember(p => p.Content, opt => opt.MapFrom<TimelinePostContentResolver>());
CreateMap<TimelinePatchRequest, TimelineChangePropertyRequest>();
}
}
diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs
index 4f887549..b4bf14c1 100644
--- a/Timeline/Models/Http/UserInfo.cs
+++ b/Timeline/Models/Http/UserInfo.cs
@@ -45,7 +45,7 @@ namespace Timeline.Models.Http
{
Self = urlHelper.ActionLink(nameof(UserController.Get), nameof(UserController)[0..^nameof(Controller).Length], new { destination.Username }),
Avatar = urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController)[0..^nameof(Controller).Length], new { destination.Username }),
- Timeline = urlHelper.ActionLink(nameof(PersonalTimelineController.TimelineGet), nameof(PersonalTimelineController)[0..^nameof(Controller).Length], new { destination.Username })
+ Timeline = urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { Name = "@" + destination.Username })
};
return result;
}
diff --git a/Timeline/Models/Timeline.cs b/Timeline/Models/Timeline.cs
index 6d4c924d..803a5c5c 100644
--- a/Timeline/Models/Timeline.cs
+++ b/Timeline/Models/Timeline.cs
@@ -48,11 +48,22 @@ namespace Timeline.Models
public class TimelinePost
{
+ public TimelinePost(long id, ITimelinePostContent content, DateTime time, User author, DateTime lastUpdated, string timelineName)
+ {
+ Id = id;
+ Content = content;
+ Time = time;
+ Author = author;
+ LastUpdated = lastUpdated;
+ TimelineName = timelineName;
+ }
+
public long Id { get; set; }
- public ITimelinePostContent Content { get; set; } = default!;
+ public ITimelinePostContent Content { get; set; }
public DateTime Time { get; set; }
- public User Author { get; set; } = default!;
- public DateTime LastUpdated { get; set; } = default!;
+ public User Author { get; set; }
+ public DateTime LastUpdated { get; set; }
+ public string TimelineName { get; set; }
}
#pragma warning disable CA1724 // Type names should not match namespaces