aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models/Http/UserInfo.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-31 00:42:06 +0800
committerGitHub <noreply@github.com>2020-10-31 00:42:06 +0800
commita3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f (patch)
treeee006874b0c93e9bfc76f141a092a8b9585a1f95 /Timeline/Models/Http/UserInfo.cs
parent0c4caaebe2480e77918d5d7df234f0edaeab74ba (diff)
parent7ce0846d9ec968da3ea4f7ebcc6db26db8e49089 (diff)
downloadtimeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.tar.gz
timeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.tar.bz2
timeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.zip
Merge pull request #161 from crupest/upgrade
Upgrade packages and split front end and back end.
Diffstat (limited to 'Timeline/Models/Http/UserInfo.cs')
-rw-r--r--Timeline/Models/Http/UserInfo.cs90
1 files changed, 0 insertions, 90 deletions
diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs
deleted file mode 100644
index d92a12c4..00000000
--- a/Timeline/Models/Http/UserInfo.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-using AutoMapper;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Infrastructure;
-using Microsoft.AspNetCore.Mvc.Routing;
-using Timeline.Controllers;
-
-namespace Timeline.Models.Http
-{
- /// <summary>
- /// Info of a user.
- /// </summary>
- public class UserInfo
- {
- /// <summary>
- /// Unique id.
- /// </summary>
- public string UniqueId { get; set; } = default!;
- /// <summary>
- /// Username.
- /// </summary>
- public string Username { get; set; } = default!;
- /// <summary>
- /// Nickname.
- /// </summary>
- public string Nickname { get; set; } = default!;
- /// <summary>
- /// True if the user is a administrator.
- /// </summary>
- public bool? Administrator { get; set; } = default!;
-#pragma warning disable CA1707 // Identifiers should not contain underscores
- /// <summary>
- /// Related links.
- /// </summary>
- public UserInfoLinks _links { get; set; } = default!;
-#pragma warning restore CA1707 // Identifiers should not contain underscores
- }
-
- /// <summary>
- /// Related links for user.
- /// </summary>
- public class UserInfoLinks
- {
- /// <summary>
- /// Self.
- /// </summary>
- public string Self { get; set; } = default!;
- /// <summary>
- /// Avatar url.
- /// </summary>
- public string Avatar { get; set; } = default!;
- /// <summary>
- /// Personal timeline url.
- /// </summary>
- public string Timeline { get; set; } = default!;
- }
-
- public class UserInfoLinksValueResolver : IValueResolver<User, UserInfo, UserInfoLinks>
- {
- private readonly IActionContextAccessor _actionContextAccessor;
- private readonly IUrlHelperFactory _urlHelperFactory;
-
- public UserInfoLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
- {
- _actionContextAccessor = actionContextAccessor;
- _urlHelperFactory = urlHelperFactory;
- }
-
- public UserInfoLinks Resolve(User source, UserInfo destination, UserInfoLinks destMember, ResolutionContext context)
- {
- var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
- var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
-
- var result = new UserInfoLinks
- {
- 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(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { Name = "@" + destination.Username })
- };
- return result;
- }
- }
-
- public class UserInfoAutoMapperProfile : Profile
- {
- public UserInfoAutoMapperProfile()
- {
- CreateMap<User, UserInfo>().ForMember(u => u._links, opt => opt.MapFrom<UserInfoLinksValueResolver>());
- }
- }
-}