From df1ef1e21d8d889a2c9abd440039533c6a43818f Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 7 Jan 2021 16:23:20 +0800 Subject: 史诗级重构! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BackEnd/Timeline/Models/Http/User.cs | 73 +++++++++++------------------------- 1 file changed, 21 insertions(+), 52 deletions(-) (limited to 'BackEnd/Timeline/Models/Http/User.cs') diff --git a/BackEnd/Timeline/Models/Http/User.cs b/BackEnd/Timeline/Models/Http/User.cs index bdb40b9f..994c08bf 100644 --- a/BackEnd/Timeline/Models/Http/User.cs +++ b/BackEnd/Timeline/Models/Http/User.cs @@ -1,10 +1,4 @@ -using AutoMapper; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Routing; -using System.Collections.Generic; -using Timeline.Controllers; -using Timeline.Services; +using System.Collections.Generic; namespace Timeline.Models.Http { @@ -13,6 +7,17 @@ namespace Timeline.Models.Http /// public class HttpUser { + public HttpUser() { } + + public HttpUser(string uniqueId, string username, string nickname, List permissions, HttpUserLinks links) + { + UniqueId = uniqueId; + Username = username; + Nickname = nickname; + Permissions = permissions; + _links = links; + } + /// /// Unique id. /// @@ -44,6 +49,15 @@ namespace Timeline.Models.Http /// public class HttpUserLinks { + public HttpUserLinks() { } + + public HttpUserLinks(string self, string avatar, string timeline) + { + Self = self; + Avatar = avatar; + Timeline = timeline; + } + /// /// Self. /// @@ -57,49 +71,4 @@ namespace Timeline.Models.Http /// public string Timeline { get; set; } = default!; } - - public class HttpUserPermissionsValueConverter : ITypeConverter> - { - public List Convert(UserPermissions source, List destination, ResolutionContext context) - { - return source.ToStringList(); - } - } - - public class HttpUserLinksValueResolver : IValueResolver - { - private readonly IActionContextAccessor _actionContextAccessor; - private readonly IUrlHelperFactory _urlHelperFactory; - - public HttpUserLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory) - { - _actionContextAccessor = actionContextAccessor; - _urlHelperFactory = urlHelperFactory; - } - - public HttpUserLinks Resolve(UserInfo source, HttpUser destination, HttpUserLinks destMember, ResolutionContext context) - { - var actionContext = _actionContextAccessor.AssertActionContextForUrlFill(); - var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext); - - var result = new HttpUserLinks - { - 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 HttpUserAutoMapperProfile : Profile - { - public HttpUserAutoMapperProfile() - { - CreateMap>() - .ConvertUsing(); - CreateMap() - .ForMember(u => u._links, opt => opt.MapFrom()); - } - } } -- cgit v1.2.3