Skip to content

Commit c661342

Browse files
author
Jani Giannoudis
committed
new domain models lookup range result and lookup range bracket
payroll controller: new endpoint to get the payroll lookup ranges action parser: added text alternative for logical opertator &&/AND and operator ||/OR updated third-party nugets updated version to 0.9.0-beta.16
1 parent 0d34f20 commit c661342

21 files changed

Lines changed: 700 additions & 17 deletions

Api/Api.Controller/PayrollController.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,63 @@ await caseValueTool.GetTimeCaseValuesAsync(caseValueDate, caseType, caseFieldNam
14551455
return new LookupValueDataMap().ToApi(valueData);
14561456
}
14571457

1458+
protected async Task<ActionResult<ApiObject.LookupRangeResult[]>> GetPayrollLookupRangesAsync(
1459+
DomainObject.PayrollQuery query, string[] lookupNames, decimal? rangeValue, string culture)
1460+
{
1461+
try
1462+
{
1463+
// tenant
1464+
var authResult = await TenantRequestAsync(query.TenantId);
1465+
if (authResult != null)
1466+
{
1467+
return authResult;
1468+
}
1469+
1470+
// validate lookup names
1471+
if (lookupNames == null || lookupNames.Length == 0)
1472+
{
1473+
return BadRequest("Missing lookup names");
1474+
}
1475+
1476+
// query setup
1477+
var setupQuery = await SetupQuery(query);
1478+
if (setupQuery.Item2 != null)
1479+
{
1480+
// invalid setup response
1481+
return setupQuery.Item2;
1482+
}
1483+
var querySetup = setupQuery.Item1;
1484+
1485+
query.RegulationDate ??= CurrentEvaluationDate;
1486+
query.EvaluationDate ??= CurrentEvaluationDate;
1487+
1488+
// lookup provider
1489+
var lookupProvider = this.NewRegulationLookupProvider(Runtime.DbContext, querySetup.Tenant,
1490+
querySetup.Payroll, query.RegulationDate, query.EvaluationDate);
1491+
1492+
// build range brackets for each lookup
1493+
var results = new List<DomainObject.LookupRangeResult>();
1494+
foreach (var lookupName in lookupNames)
1495+
{
1496+
var lookupSet = await lookupProvider.GetLookupAsync(Runtime.DbContext, lookupName);
1497+
if (lookupSet == null)
1498+
{
1499+
return BadRequest($"Unknown lookup {lookupName}");
1500+
}
1501+
1502+
var result = DomainObject.LookupSetExtensions.BuildRangeBrackets(lookupSet, rangeValue);
1503+
result.LookupName = lookupName;
1504+
results.Add(result);
1505+
}
1506+
1507+
return new LookupRangeResultMap().ToApi(results);
1508+
}
1509+
catch (Exception exception)
1510+
{
1511+
return InternalServerError(exception);
1512+
}
1513+
}
1514+
14581515
protected async Task<ActionResult<ApiObject.ReportSet[]>> GetPayrollReportsAsync(
14591516
DomainObject.PayrollQuery query, string[] reportNames,
14601517
OverrideType? overrideType, UserType? userType, string clusterSetName)

Api/Api.Core/PayrollEngine.Api.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<ItemGroup>
1010
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.1" />
1111
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
12-
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
13-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.1" />
12+
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.2" />
13+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.3" />
1414
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
1515
</ItemGroup>
1616

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using DomainObject = PayrollEngine.Domain.Model;
2+
using ApiObject = PayrollEngine.Api.Model;
3+
using Riok.Mapperly.Abstractions;
4+
5+
namespace PayrollEngine.Api.Map;
6+
7+
/// <summary>
8+
/// Map a domain object with an api object
9+
/// </summary>
10+
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)]
11+
public partial class LookupRangeBracketMap : ApiMapBase<DomainObject.LookupRangeBracket, ApiObject.LookupRangeBracket>
12+
{
13+
public override partial ApiObject.LookupRangeBracket ToApi(DomainObject.LookupRangeBracket domainObject);
14+
public override partial DomainObject.LookupRangeBracket ToDomain(ApiObject.LookupRangeBracket apiObject);
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using DomainObject = PayrollEngine.Domain.Model;
2+
using ApiObject = PayrollEngine.Api.Model;
3+
using Riok.Mapperly.Abstractions;
4+
5+
namespace PayrollEngine.Api.Map;
6+
7+
/// <summary>
8+
/// Map a domain object with an api object
9+
/// </summary>
10+
[Mapper(EnumMappingStrategy = EnumMappingStrategy.ByName, EnumMappingIgnoreCase = true)]
11+
public partial class LookupRangeResultMap : ApiMapBase<DomainObject.LookupRangeResult, ApiObject.LookupRangeResult>
12+
{
13+
public override partial ApiObject.LookupRangeResult ToApi(DomainObject.LookupRangeResult domainObject);
14+
public override partial DomainObject.LookupRangeResult ToDomain(ApiObject.LookupRangeResult apiObject);
15+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace PayrollEngine.Api.Model;
2+
3+
/// <summary>
4+
/// A lookup range bracket with computed bounds
5+
/// </summary>
6+
// ReSharper disable UnusedAutoPropertyAccessor.Global
7+
// ReSharper disable PropertyCanBeMadeInitOnly.Global
8+
public class LookupRangeBracket
9+
{
10+
/// <summary>
11+
/// The lookup value key
12+
/// </summary>
13+
public string Key { get; set; }
14+
15+
/// <summary>
16+
/// The lookup value as JSON
17+
/// </summary>
18+
public string Value { get; set; }
19+
20+
/// <summary>
21+
/// The range start value
22+
/// </summary>
23+
public decimal RangeStart { get; set; }
24+
25+
/// <summary>
26+
/// The range end value (unbound bracket: Decimal.MaxValue)
27+
/// </summary>
28+
public decimal RangeEnd { get; set; }
29+
30+
/// <summary>
31+
/// The brackets range value
32+
/// </summary>
33+
/// <remarks>
34+
/// Threshold lookup: value within the matching bracket.
35+
/// Progressive lookup: matching bracket value range, except the last one which the value within his range.
36+
/// Other: null.
37+
/// </remarks>
38+
public decimal? RangeValue { get; set; }
39+
40+
/// <inheritdoc/>
41+
public override string ToString() =>
42+
$"{Key}: {RangeStart} - {RangeEnd}";
43+
}

Api/Api.Model/LookupRangeResult.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
3+
namespace PayrollEngine.Api.Model;
4+
5+
/// <summary>
6+
/// Result of a lookup range bracket computation
7+
/// </summary>
8+
// ReSharper disable UnusedAutoPropertyAccessor.Global
9+
// ReSharper disable PropertyCanBeMadeInitOnly.Global
10+
public class LookupRangeResult
11+
{
12+
/// <summary>
13+
/// The lookup name
14+
/// </summary>
15+
public string LookupName { get; set; }
16+
17+
/// <summary>
18+
/// The lookup range mode
19+
/// </summary>
20+
public LookupRangeMode RangeMode { get; set; }
21+
22+
/// <summary>
23+
/// The lookup range size
24+
/// </summary>
25+
public decimal? RangeSize { get; set; }
26+
27+
/// <summary>
28+
/// Range brackets
29+
/// </summary>
30+
public List<LookupRangeBracket> Brackets { get; set; }
31+
32+
/// <inheritdoc/>
33+
public override string ToString() =>
34+
LookupName;
35+
}

Api/Api.Model/PayrollEngine.Api.Model.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="PayrollEngine.Core" Version="0.9.0-beta.15" />
14+
<PackageReference Include="PayrollEngine.Core" Version="0.9.0-beta.16" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

Api/Api.Model/PayrollEngine.Api.Model.xml

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Backend.Controller/PayrollController.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel.DataAnnotations;
42
using System.Linq;
53
using System.Threading.Tasks;
4+
using System.Collections.Generic;
5+
using System.ComponentModel.DataAnnotations;
66
using Microsoft.AspNetCore.Mvc;
77
using PayrollEngine.Api.Core;
8-
using PayrollEngine.Domain.Application.Service;
98
using PayrollEngine.Domain.Model;
109
using ApiObject = PayrollEngine.Api.Model;
10+
using PayrollEngine.Domain.Application.Service;
1111

1212
namespace PayrollEngine.Backend.Controller;
1313

@@ -739,6 +739,42 @@ public override async Task<ActionResult> QueryPayrollCaseChangeValuesAsync(int t
739739
lookupName, lookupKey, rangeValue, culture);
740740
}
741741

742+
/// <summary>
743+
/// Get payroll lookup range brackets
744+
/// </summary>
745+
/// <param name="tenantId">The tenant id</param>
746+
/// <param name="payrollId">The payroll id</param>
747+
/// <param name="lookupNames">The lookup names (case-insensitive)</param>
748+
/// <param name="rangeValue">Optional value to find matching brackets (supported by threshold and progressive lookups)</param>
749+
/// <param name="regulationDate">The regulation date (default: UTC now)</param>
750+
/// <param name="evaluationDate">The evaluation date (default: UTC now)</param>
751+
/// <param name="culture">The content culture</param>
752+
/// <returns>The lookup range results</returns>
753+
[HttpGet("{payrollId}/lookups/ranges")]
754+
[OkResponse]
755+
[NotFoundResponse]
756+
[ApiOperationId("GetPayrollLookupRanges")]
757+
public async Task<ActionResult<ApiObject.LookupRangeResult[]>> GetPayrollLookupRangesAsync(int tenantId, int payrollId,
758+
[FromQuery][Required] string[] lookupNames, [FromQuery] decimal? rangeValue,
759+
[FromQuery] DateTime? regulationDate, [FromQuery] DateTime? evaluationDate, [FromQuery] string culture)
760+
{
761+
// authorization
762+
var authResult = await TenantRequestAsync(tenantId);
763+
if (authResult != null)
764+
{
765+
return authResult;
766+
}
767+
return await base.GetPayrollLookupRangesAsync(
768+
new()
769+
{
770+
TenantId = tenantId,
771+
PayrollId = payrollId,
772+
RegulationDate = regulationDate,
773+
EvaluationDate = evaluationDate
774+
},
775+
lookupNames, rangeValue, culture);
776+
}
777+
742778
/// <summary>
743779
/// Get payroll report sets
744780
/// </summary>

Backend.Controller/PayrollEngine.Backend.Controller.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)