diff options
author | crupest <crupest@outlook.com> | 2020-01-30 23:49:02 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-01-30 23:49:02 +0800 |
commit | 5aaa4f95e6bdd46e6740c1ecbbd46bdf415eedd2 (patch) | |
tree | 70ddc26cf29bdf4b19e9a746cac6017845e009fc /Timeline/Models | |
parent | d988669de355df12d3be3c658e8617c275fe70dd (diff) | |
download | timeline-5aaa4f95e6bdd46e6740c1ecbbd46bdf415eedd2.tar.gz timeline-5aaa4f95e6bdd46e6740c1ecbbd46bdf415eedd2.tar.bz2 timeline-5aaa4f95e6bdd46e6740c1ecbbd46bdf415eedd2.zip |
Finish reafctor, TODO: Database migration.
Diffstat (limited to 'Timeline/Models')
-rw-r--r-- | Timeline/Models/Http/UserInfo.cs | 21 | ||||
-rw-r--r-- | Timeline/Models/Validation/NicknameValidator.cs | 2 |
2 files changed, 16 insertions, 7 deletions
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<object, IUserInfo>
+ public class UserInfoAvatarUrlValueResolver : IValueResolver<User, IUserInfo, string>
{
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<User, UserInfo>().AfterMap<UserInfoSetAvatarUrlAction>();
- CreateMap<User, UserInfoForAdmin>().AfterMap<UserInfoSetAvatarUrlAction>();
+ CreateMap<User, UserInfo>().ForMember(u => u.AvatarUrl, opt => opt.MapFrom<UserInfoAvatarUrlValueResolver>());
+ CreateMap<User, UserInfoForAdmin>().ForMember(u => u.AvatarUrl, opt => opt.MapFrom<UserInfoAvatarUrlValueResolver>());
}
}
}
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());
|