From 49bd47fb0eb81a88cce135f7ff7c25637790e63b Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 30 Jan 2020 23:49:02 +0800 Subject: Finish reafctor, TODO: Database migration. --- Timeline/Models/Http/UserInfo.cs | 21 +++++++++++++++------ Timeline/Models/Validation/NicknameValidator.cs | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'Timeline/Models') diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs index 6029b8aa..62d989a2 100644 --- a/Timeline/Models/Http/UserInfo.cs +++ b/Timeline/Models/Http/UserInfo.cs @@ -29,21 +29,30 @@ namespace Timeline.Models.Http public bool Administrator { get; set; } } - public class UserInfoSetAvatarUrlAction : IMappingAction + public class UserInfoAvatarUrlValueResolver : IValueResolver { private readonly IActionContextAccessor _actionContextAccessor; private readonly IUrlHelperFactory _urlHelperFactory; - public UserInfoSetAvatarUrlAction(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory) + public UserInfoAvatarUrlValueResolver() + { + } + + public UserInfoAvatarUrlValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory) { _actionContextAccessor = actionContextAccessor; _urlHelperFactory = urlHelperFactory; } - public void Process(object source, IUserInfo destination, ResolutionContext context) + public string Resolve(User source, IUserInfo destination, string destMember, ResolutionContext context) { + if (_actionContextAccessor == null) + { + return $"/users/{destination.Username}/avatar"; + } + var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); - destination.AvatarUrl = urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController), new { destination.Username }); + return urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController), new { destination.Username }); } } @@ -51,8 +60,8 @@ namespace Timeline.Models.Http { public UserInfoAutoMapperProfile() { - CreateMap().AfterMap(); - CreateMap().AfterMap(); + CreateMap().ForMember(u => u.AvatarUrl, opt => opt.MapFrom()); + CreateMap().ForMember(u => u.AvatarUrl, opt => opt.MapFrom()); } } } diff --git a/Timeline/Models/Validation/NicknameValidator.cs b/Timeline/Models/Validation/NicknameValidator.cs index 53a2916b..1d6ab163 100644 --- a/Timeline/Models/Validation/NicknameValidator.cs +++ b/Timeline/Models/Validation/NicknameValidator.cs @@ -7,7 +7,7 @@ namespace Timeline.Models.Validation { protected override (bool, string) DoValidate(string value) { - if (value.Length > 10) + if (value.Length > 25) return (false, MessageTooLong); return (true, GetSuccessMessage()); -- cgit v1.2.3