feat(api): TemplateHistoryController
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using PARR.API.Authentication.Models;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.MappingProfiles.Resolvers;
|
||||
using PARR.Common.Domain;
|
||||
using PARR.Constants.Shortcode;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Extensions;
|
||||
@@ -300,6 +301,29 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
|
||||
CreateMap<WeekendDay, WeekendResponse>();
|
||||
|
||||
#region TemplateHistory
|
||||
|
||||
CreateMap<TemplateHistory, TemplateHistoryResponse>()
|
||||
.ForMember(d => d.TemplateId, o => o.MapFrom(s => s.ParentId))
|
||||
.ForMember(d => d.Initiator, o => o.MapFrom(s => s));
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Initiator
|
||||
|
||||
CreateMap<IHistoryInitiator, HistoryInitiatorResponse>()
|
||||
.ForMember(d => d.Ip, o => o.MapFrom(s => s.InitiatorIp))
|
||||
.ForMember(d => d.Comment, o => o.MapFrom(s => s.InitiatorComment))
|
||||
.ForMember(d => d.ParrComponentId, o => o.MapFrom(s => s.InitiatorParrComponentId))
|
||||
.ForMember(d => d.ParrComponent, o => o.MapFrom<HistoryInitiatorParrComponentResolver>())
|
||||
.ForMember(d => d.User, o => o.MapFrom<HistoryInitiatorUserResolver>());
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.Common.Domain;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.MappingProfiles.Resolvers
|
||||
{
|
||||
public class HistoryInitiatorParrComponentResolver : IValueResolver<IHistoryInitiator, HistoryInitiatorResponse, ParrComponentResponse?>
|
||||
{
|
||||
private readonly IParrComponentService parrComponentService;
|
||||
|
||||
public HistoryInitiatorParrComponentResolver(IParrComponentService parrComponentService)
|
||||
{
|
||||
this.parrComponentService = parrComponentService;
|
||||
}
|
||||
|
||||
public ParrComponentResponse? Resolve(IHistoryInitiator source, HistoryInitiatorResponse destination, ParrComponentResponse? destMember, ResolutionContext context)
|
||||
{
|
||||
var component = parrComponentService.Get().FirstOrDefaultAsync(t => t.Id == source.InitiatorParrComponentId).GetAwaiter().GetResult();
|
||||
|
||||
if (component == null)
|
||||
return null;
|
||||
|
||||
return new ParrComponentResponse { Description = component.Description, Name = component.Name, Id = (int)component.Id };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.Common.Domain;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.MappingProfiles.Resolvers
|
||||
{
|
||||
public class HistoryInitiatorUserResolver : IValueResolver<IHistoryInitiator, HistoryInitiatorResponse, UserBaseResponse?>
|
||||
{
|
||||
private readonly IUserService userService;
|
||||
|
||||
public HistoryInitiatorUserResolver(IUserService userService)
|
||||
{
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public UserBaseResponse? Resolve(IHistoryInitiator source, HistoryInitiatorResponse destination, UserBaseResponse? destMember, ResolutionContext context)
|
||||
{
|
||||
var user = userService.Get().FirstOrDefaultAsync(t => t.Ip == source.InitiatorIp).GetAwaiter().GetResult();
|
||||
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
return new UserBaseResponse { Ip = user.Ip, Description = user.Description ?? string.Empty, Name = user.Name };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user