Skip to content

Commit 39020f6

Browse files
committed
feat: 547
Gestione Filtri. Related work items: #547
1 parent 0dcde57 commit 39020f6

File tree

45 files changed

+929
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+929
-24
lines changed

src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/SEND/DatiRel/Queries/Persistence/Builder/RelTestataSQLBuilder.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence.Builder;
22

33
internal static class RelTestataSQLBuilder
4-
{
4+
{
5+
private static string _sqlAnni = @"
6+
SELECT distinct(year)
7+
FROM [pfd].[RelTestata]
8+
";
9+
10+
private static string _sqlMesi = @"
11+
SELECT distinct(month)
12+
FROM [pfd].[RelTestata]
13+
";
514

615
private static string _sqlDistinctTipologiaFatturaPagoPA = @"
716
SELECT TipologiaFattura
@@ -149,4 +158,22 @@ public static string OrderByDistinctTipologiaFattura()
149158
{
150159
return " ORDER BY ordine ";
151160
}
161+
162+
public static string SelectAnni()
163+
{
164+
return _sqlAnni;
165+
}
166+
167+
public static string SelectMesi()
168+
{
169+
return _sqlMesi;
170+
}
171+
172+
public static string OrderByMonth = " order by month desc";
173+
174+
public static string OrderByYear= " order by year desc";
175+
176+
public static string GroupByOrderByYear = " group by year, internal_organization_id, contract_id order by year desc";
177+
178+
public static string GroupByMonthByYear = " group by year, month, internal_organization_id, contract_id order by month desc";
152179
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Data;
2+
using System.Dynamic;
3+
using PortaleFatture.BE.Infrastructure.Common.Persistence;
4+
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence.Builder;
5+
6+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence;
7+
8+
public class RelAnniQueryByIdEntePersistence(RelAnniByIdEnteQuery command) : DapperBase, IQuery<IEnumerable<string>?>
9+
{
10+
private readonly RelAnniByIdEnteQuery _command = command;
11+
private static readonly string _sql = RelTestataSQLBuilder.SelectAnni();
12+
private static readonly string _orderBy = RelTestataSQLBuilder.GroupByOrderByYear;
13+
public async Task<IEnumerable<string>?> Execute(IDbConnection? connection, string schema, IDbTransaction? transaction, CancellationToken cancellationToken = default)
14+
{
15+
var authInfo = _command.AuthenticationInfo;
16+
dynamic parameters = new ExpandoObject();
17+
18+
var where = " WHERE internal_organization_id=@IdEnte ";
19+
parameters.IdEnte = authInfo.IdEnte;
20+
21+
return await ((IDatabase)this).SelectAsync<string>(
22+
connection!, _sql + where + _orderBy, parameters, transaction);
23+
}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Data;
2+
using PortaleFatture.BE.Infrastructure.Common.Persistence;
3+
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence.Builder;
4+
5+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence;
6+
7+
public class RelAnniQueryPersistence(RelAnniQuery command) : DapperBase, IQuery<IEnumerable<string>?>
8+
{
9+
private readonly RelAnniQuery _command = command;
10+
private static readonly string _sql = RelTestataSQLBuilder.SelectAnni();
11+
private static readonly string _orderBy = RelTestataSQLBuilder.OrderByYear;
12+
public async Task<IEnumerable<string>?> Execute(IDbConnection? connection, string schema, IDbTransaction? transaction, CancellationToken cancellationToken = default)
13+
{
14+
15+
return await ((IDatabase)this).SelectAsync<string>(
16+
connection!, _sql + _orderBy, _command, transaction);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Data;
2+
using System.Dynamic;
3+
using PortaleFatture.BE.Infrastructure.Common.Persistence;
4+
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence.Builder;
5+
6+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence;
7+
8+
public class RelMesiByIdEnteQueryPersistence(RelMesiByIdEnteQuery command) : DapperBase, IQuery<IEnumerable<string>?>
9+
{
10+
private readonly RelMesiByIdEnteQuery _command = command;
11+
private static readonly string _sql = RelTestataSQLBuilder.SelectMesi();
12+
private static readonly string _orderBy = RelTestataSQLBuilder.GroupByMonthByYear;
13+
public async Task<IEnumerable<string>?> Execute(IDbConnection? connection, string schema, IDbTransaction? transaction, CancellationToken cancellationToken = default)
14+
{
15+
var authInfo = _command.AuthenticationInfo;
16+
dynamic parameters = new ExpandoObject();
17+
var where = " WHERE year=@anno ";
18+
parameters.Anno = _command.Anno;
19+
where += " AND internal_organization_id=@IdEnte ";
20+
parameters.IdEnte = authInfo.IdEnte;
21+
return await ((IDatabase)this).SelectAsync<string>(
22+
connection!, _sql + where + _orderBy, parameters, transaction);
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Data;
2+
using System.Dynamic;
3+
using PortaleFatture.BE.Infrastructure.Common.Persistence;
4+
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence.Builder;
5+
6+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence;
7+
8+
public class RelMesiQueryPersistence(RelMesiQuery command) : DapperBase, IQuery<IEnumerable<string>?>
9+
{
10+
private readonly RelMesiQuery _command = command;
11+
private static readonly string _sql = RelTestataSQLBuilder.SelectMesi();
12+
private static readonly string _orderBy = RelTestataSQLBuilder.OrderByMonth;
13+
public async Task<IEnumerable<string>?> Execute(IDbConnection? connection, string schema, IDbTransaction? transaction, CancellationToken cancellationToken = default)
14+
{
15+
dynamic parameters = new ExpandoObject();
16+
var where = string.Empty;
17+
if (!string.IsNullOrEmpty(_command.Anno))
18+
{
19+
where += " WHERE year=@anno ";
20+
parameters.Anno = _command.Anno;
21+
}
22+
23+
return await ((IDatabase)this).SelectAsync<string>(
24+
connection!, _sql + where + _orderBy, parameters, transaction);
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using MediatR;
2+
using PortaleFatture.BE.Core.Auth;
3+
4+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries;
5+
public class RelAnniByIdEnteQuery(IAuthenticationInfo authenticationInfo) : IRequest<IEnumerable<string>?>
6+
{
7+
public IAuthenticationInfo AuthenticationInfo { get; internal set; } = authenticationInfo;
8+
public string? IdContratto { get; set; }
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using MediatR;
2+
using PortaleFatture.BE.Core.Auth;
3+
4+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries;
5+
public class RelAnniQuery(IAuthenticationInfo authenticationInfo) : IRequest<IEnumerable<string>?>
6+
{
7+
public IAuthenticationInfo AuthenticationInfo { get; internal set; } = authenticationInfo;
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using MediatR;
2+
using PortaleFatture.BE.Core.Auth;
3+
4+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries;
5+
6+
public class RelMesiByIdEnteQuery(IAuthenticationInfo authenticationInfo) : IRequest<IEnumerable<string>?>
7+
{
8+
public IAuthenticationInfo AuthenticationInfo { get; internal set; } = authenticationInfo;
9+
10+
public string? Anno { get; set; }
11+
12+
public string? IdContratto { get; set; }
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using MediatR;
2+
using PortaleFatture.BE.Core.Auth;
3+
4+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries;
5+
6+
public class RelMesiQuery(IAuthenticationInfo authenticationInfo) : IRequest<IEnumerable<string>?>
7+
{
8+
public IAuthenticationInfo AuthenticationInfo { get; internal set; } = authenticationInfo;
9+
10+
public string? Anno { get; set; }
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using MediatR;
2+
using Microsoft.Extensions.Localization;
3+
using Microsoft.Extensions.Logging;
4+
using PortaleFatture.BE.Core.Resources;
5+
using PortaleFatture.BE.Infrastructure.Common.Persistence.Schemas;
6+
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries;
7+
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence;
8+
9+
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.QueryHandlers;
10+
11+
public class RelAnniByIdEnteHandler(
12+
IFattureDbContextFactory factory,
13+
IStringLocalizer<Localization> localizer,
14+
ILogger<RelAnniByIdEnteHandler> logger) : IRequestHandler<RelAnniByIdEnteQuery, IEnumerable<string>?>
15+
{
16+
private readonly IFattureDbContextFactory _factory = factory;
17+
private readonly ILogger<RelAnniByIdEnteHandler> _logger = logger;
18+
private readonly IStringLocalizer<Localization> _localizer = localizer;
19+
public async Task<IEnumerable<string>?> Handle(RelAnniByIdEnteQuery request, CancellationToken ct)
20+
{
21+
using var rs = await _factory.Create(cancellationToken: ct);
22+
return await rs.Query(new RelAnniQueryByIdEntePersistence(request), ct);
23+
}
24+
}

0 commit comments

Comments
 (0)