feat(api): Доделал респонс RobotTaskScheduleResponse

This commit is contained in:
Mikhail Trubnikov
2023-10-11 11:10:35 +10:00
parent a4dde4c59a
commit 8ebdcd6d8a
11 changed files with 212 additions and 8 deletions

View File

@@ -0,0 +1,22 @@
using AutoMapper;
using PARR.API.Contracts.V1.Responses;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
namespace PARR.API.MappingProfiles.Resolvers
{
public class RobotTaskScheduleExcludeResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, string>
{
private readonly SettingsFromDb settingsFromDb;
public RobotTaskScheduleExcludeResolver(SettingsFromDb settingsFromDb)
{
this.settingsFromDb = settingsFromDb;
}
public string Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, string destMember, ResolutionContext context)
{
return settingsFromDb.ScheduleExclude;
}
}
}

View File

@@ -0,0 +1,22 @@
using AutoMapper;
using PARR.API.Contracts.V1.Responses;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
namespace PARR.API.MappingProfiles.Resolvers
{
public class RobotTaskScheduleRepeatRangeResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, string>
{
private readonly SettingsFromDb settingsFromDb;
public RobotTaskScheduleRepeatRangeResolver(SettingsFromDb settingsFromDb)
{
this.settingsFromDb = settingsFromDb;
}
public string Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, string destMember, ResolutionContext context)
{
return settingsFromDb.ScheduleRepeatRange;
}
}
}

View File

@@ -0,0 +1,37 @@
using AutoMapper;
using PARR.API.Contracts.V1.Responses;
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.MappingProfiles.Resolvers
{
public class RobotTaskScheduleSchResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, List<RobotTaskScheduleSchResponse>?>
{
private readonly IEsppSchTypeConfigService esppConfigService;
public RobotTaskScheduleSchResolver(IEsppSchTypeConfigService esppConfigService)
{
this.esppConfigService = esppConfigService;
}
public List<RobotTaskScheduleSchResponse>? Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, List<RobotTaskScheduleSchResponse>? destMember, ResolutionContext context)
{
//todo: может вынести эту логику в сервис?
var appInWorksId = source.Template!.ApplicationInWorkId;
var configs = esppConfigService.GetWithSchIncludes()
.Where(t => t.EsppSchValues.Any(x => x.ApplicationsInWorkId == appInWorksId))
.ToList();
var response = configs.Select(conf =>
new RobotTaskScheduleSchResponse
{
Order = conf.Order,
Type = conf.EsppSchType!.Name,
Value = conf.EsppSchValues.First().EsppSchTypeValue!.Value
});
return response.OrderBy(t => t.Order).ToList();
}
}
}

View File

@@ -0,0 +1,22 @@
using AutoMapper;
using PARR.API.Contracts.V1.Responses;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
namespace PARR.API.MappingProfiles.Resolvers
{
public class RobotTaskScheduleTimezoneResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, string>
{
private readonly SettingsFromDb settingsFromDb;
public RobotTaskScheduleTimezoneResolver(SettingsFromDb settingsFromDb)
{
this.settingsFromDb = settingsFromDb;
}
public string Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, string destMember, ResolutionContext context)
{
return settingsFromDb.ScheduleTimezone;
}
}
}