Skip to content

Commit f58f934

Browse files
committed
Atualiza dependências e refatora métodos de busca
Mudanças nas configurações e dependências do projeto. * Atualização do arquivo `Directory.Build.props` - Alterado `SearchesPreview` e `ProblemsVer` para novas versões. - Atualizados `LibTargets` e `AspTargets` para incluir `net8` e `net9`. * Refatoração dos métodos em `SearchExtensions.cs` - Renomeados métodos de `MapFirstDto` para `MapSelectFirst`. - Atualizada lógica interna para usar `FirstModelEndpoint`. Mudanças nas dependências de teste. * Atualização do arquivo `tests.targets` - Versões de `Microsoft.NET.Test.Sdk`, `xunit.runner.visualstudio` e `FluentAssertions` atualizadas. Adição de nova funcionalidade para critérios de busca. * Inclusão do arquivo `EFSearchesExtensions.cs` - Adicionada classe `EFSearchesExtensions` com método `Criteria<TEntity>` para `DbContext`.
1 parent 20f9b07 commit f58f934

File tree

5 files changed

+66
-46
lines changed

5 files changed

+66
-46
lines changed

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66
<PropertyGroup>
77
<SearchesVer>0.8.0</SearchesVer>
8-
<SearchesPreview>-preview-2</SearchesPreview>
8+
<SearchesPreview>-preview-3</SearchesPreview>
99
</PropertyGroup>
1010
<PropertyGroup>
1111
<DotNetCoreVersion Condition="'$(TargetFramework)' == 'net8'">8.0.2</DotNetCoreVersion>
@@ -14,6 +14,6 @@
1414
<PropertyGroup>
1515
<PropSelVer>1.0.2</PropSelVer>
1616
<OpHintVer>1.0.0</OpHintVer>
17-
<ProblemsVer>1.0.0-preview-4.0</ProblemsVer>
17+
<ProblemsVer>1.0.0-preview-4.3</ProblemsVer>
1818
</PropertyGroup>
1919
</Project>

src/RoyalCode.SmartSearch.AspNetCore/Extensions/SearchExtensions.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,83 +445,92 @@ public static RouteHandlerBuilder MapFirst<TEntity, TFilter, TId1, TId2, TId3>(t
445445
/// Maps a GET endpoint to a first DTO based on the applied filter.
446446
/// </summary>
447447
/// <typeparam name="TEntity">The type of the entity to be queried.</typeparam>
448+
/// <typeparam name="TDto">The type of the DTO to be returned.</typeparam>
448449
/// <typeparam name="TFilter">The type of the applied filter.</typeparam>
449450
/// <param name="builder">The route builder.</param>
450451
/// <param name="pattern">The route pattern.</param>
451452
/// <returns>A builder for additional endpoint configuration.</returns>
452-
public static RouteHandlerBuilder MapFirstDto<TEntity, TFilter>(this IEndpointRouteBuilder builder,
453+
public static RouteHandlerBuilder MapSelectFirst<TEntity, TDto, TFilter>(this IEndpointRouteBuilder builder,
453454
[StringSyntax("Route")] string pattern)
454455
where TEntity : class
456+
where TDto : class
455457
where TFilter : class
456458
{
457-
var first = new FirstEntityEndpoint<TEntity, TFilter>();
459+
var first = new FirstModelEndpoint<TEntity, TDto, TFilter>();
458460
return builder.MapGet(pattern, first.First);
459461
}
460462

461463
/// <summary>
462464
/// Maps a GET endpoint to a first DTO based on the applied filter.
463465
/// </summary>
464466
/// <typeparam name="TEntity">The type of the entity to be queried.</typeparam>
467+
/// <typeparam name="TDto">The type of the DTO to be returned.</typeparam>
465468
/// <typeparam name="TFilter">The type of the applied filter.</typeparam>
466469
/// <param name="builder">The route builder.</param>
467470
/// <param name="pattern">The route pattern.</param>
468471
/// <param name="searchAction">Action to apply additional logic to the search criteria.</param>
469472
/// <returns>A builder for additional endpoint configuration.</returns>
470-
public static RouteHandlerBuilder MapFirstDto<TEntity, TFilter>(this IEndpointRouteBuilder builder,
473+
public static RouteHandlerBuilder MapSelectFirst<TEntity, TDto, TFilter>(this IEndpointRouteBuilder builder,
471474
[StringSyntax("Route")] string pattern,
472475
Action<ICriteria<TEntity>> searchAction)
473476
where TEntity : class
477+
where TDto : class
474478
where TFilter : class
475479
{
476-
var first = new FirstEntityEndpoint<TEntity, TFilter>(searchAction);
480+
var first = new FirstModelEndpoint<TEntity, TDto, TFilter>(searchAction);
477481
return builder.MapGet(pattern, first.First);
478482
}
479483

480484
/// <summary>
481485
/// Maps a GET endpoint to a first DTO based on the applied filter with an additional identifier.
482486
/// </summary>
483487
/// <typeparam name="TEntity">The type of the entity to be queried.</typeparam>
488+
/// <typeparam name="TDto">The type of the DTO to be returned.</typeparam>
484489
/// <typeparam name="TFilter">The type of the applied filter.</typeparam>
485490
/// <typeparam name="TId">The type of the first additional identifier.</typeparam>
486491
/// <param name="builder">The route builder.</param>
487492
/// <param name="pattern">The route pattern.</param>
488493
/// <param name="searchAction">Action to apply additional logic to the search criteria.</param>
489494
/// <returns>A builder for additional endpoint configuration.</returns>
490-
public static RouteHandlerBuilder MapFirstDto<TEntity, TFilter, TId>(this IEndpointRouteBuilder builder,
495+
public static RouteHandlerBuilder MapSelectFirst<TEntity, TDto, TFilter, TId>(this IEndpointRouteBuilder builder,
491496
[StringSyntax("Route")] string pattern,
492497
Action<TId, ICriteria<TEntity>> searchAction)
493498
where TEntity : class
499+
where TDto : class
494500
where TFilter : class
495501
{
496-
var first = new FirstEntityEndpoint<TEntity, TFilter, TId>(searchAction);
502+
var first = new FirstModelEndpoint<TEntity, TDto, TFilter, TId>(searchAction);
497503
return builder.MapGet(pattern, first.First);
498504
}
499505

500506
/// <summary>
501507
/// Maps a GET endpoint to a first DTO based on the applied filter with two additional identifiers.
502508
/// </summary>
503509
/// <typeparam name="TEntity">The type of the entity to be queried.</typeparam>
510+
/// <typeparam name="TDto">The type of the DTO to be returned.</typeparam>
504511
/// <typeparam name="TFilter">The type of the applied filter.</typeparam>
505512
/// <typeparam name="TId1">The type of the first additional identifier.</typeparam>
506513
/// <typeparam name="TId2">The type of the second additional identifier.</typeparam>
507514
/// <param name="builder">The route builder.</param>
508515
/// <param name="pattern">The route pattern.</param>
509516
/// <param name="searchAction">Action to apply additional logic to the search criteria.</param>
510517
/// <returns>A builder for additional endpoint configuration.</returns>
511-
public static RouteHandlerBuilder MapFirstDto<TEntity, TFilter, TId1, TId2>(this IEndpointRouteBuilder builder,
518+
public static RouteHandlerBuilder MapSelectFirst<TEntity, TDto, TFilter, TId1, TId2>(this IEndpointRouteBuilder builder,
512519
[StringSyntax("Route")] string pattern,
513520
Action<TId1, TId2, ICriteria<TEntity>> searchAction)
514521
where TEntity : class
522+
where TDto : class
515523
where TFilter : class
516524
{
517-
var first = new FirstEntityEndpoint<TEntity, TFilter, TId1, TId2>(searchAction);
525+
var first = new FirstModelEndpoint<TEntity, TDto, TFilter, TId1, TId2>(searchAction);
518526
return builder.MapGet(pattern, first.First);
519527
}
520528

521529
/// <summary>
522530
/// Maps a GET endpoint to a first DTO based on the applied filter with three additional identifiers.
523531
/// </summary>
524532
/// <typeparam name="TEntity">The type of the entity to be queried.</typeparam>
533+
/// <typeparam name="TDto">The type of the DTO to be returned.</typeparam>
525534
/// <typeparam name="TFilter">The type of the applied filter.</typeparam>
526535
/// <typeparam name="TId1">The type of the first additional identifier.</typeparam>
527536
/// <typeparam name="TId2">The type of the second additional identifier.</typeparam>
@@ -530,13 +539,14 @@ public static RouteHandlerBuilder MapFirstDto<TEntity, TFilter, TId1, TId2>(this
530539
/// <param name="pattern">The route pattern.</param>
531540
/// <param name="searchAction">Action to apply additional logic to the search criteria.</param>
532541
/// <returns>A builder for additional endpoint configuration.</returns>
533-
public static RouteHandlerBuilder MapFirstDto<TEntity, TFilter, TId1, TId2, TId3>(this IEndpointRouteBuilder builder,
542+
public static RouteHandlerBuilder MapSelectFirst<TEntity, TDto, TFilter, TId1, TId2, TId3>(this IEndpointRouteBuilder builder,
534543
[StringSyntax("Route")] string pattern,
535544
Action<TId1, TId2, TId3, ICriteria<TEntity>> searchAction)
536545
where TEntity : class
546+
where TDto : class
537547
where TFilter : class
538548
{
539-
var first = new FirstEntityEndpoint<TEntity, TFilter, TId1, TId2, TId3>(searchAction);
549+
var first = new FirstModelEndpoint<TEntity, TDto, TFilter, TId1, TId2, TId3>(searchAction);
540550
return builder.MapGet(pattern, first.First);
541551
}
542552

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Microsoft.EntityFrameworkCore.Infrastructure;
2+
using RoyalCode.SmartSearch;
3+
using RoyalCode.SmartSearch.Defaults;
4+
using RoyalCode.SmartSearch.EntityFramework.Services;
5+
using RoyalCode.SmartSearch.Linq.Services;
6+
using RoyalCode.SmartSearch.Linq.Sortings;
7+
8+
namespace Microsoft.EntityFrameworkCore;
9+
10+
/// <summary>
11+
/// Extensions methods for <see cref="DbContext"/> to create <see cref="ICriteria{TEntity}"/>.
12+
/// </summary>
13+
public static class EFSearchesExtensions
14+
{
15+
/// <summary>
16+
/// <para>
17+
/// Creates a new <see cref="ICriteria{TEntity}"/> for the entity <typeparamref name="TEntity"/>
18+
/// using the <see cref="DbContext"/> used by the unit of work.
19+
/// </para>
20+
/// </summary>
21+
/// <typeparam name="TEntity">The entity type to create the criteria for.</typeparam>
22+
/// <param name="db">The <see cref="DbContext"/> to use for performing the searches.</param>
23+
/// <returns>A new <see cref="ICriteria{TEntity}"/> instance.</returns>
24+
public static ICriteria<TEntity> Criteria<TEntity>(this DbContext db)
25+
where TEntity : class
26+
{
27+
var specifierFactory = db.GetService<ISpecifierFactory>();
28+
var orderByFactory = db.GetService<IOrderByProvider>();
29+
var selectorFactory = db.GetService<ISelectorFactory>();
30+
31+
var preparer = new CriteriaPerformer<DbContext, TEntity>(
32+
db,
33+
specifierFactory,
34+
orderByFactory,
35+
selectorFactory);
36+
37+
var criteria = new Criteria<TEntity>(preparer);
38+
39+
return criteria;
40+
}
41+
}

src/RoyalCode.SmartSearch.EntityFramework/Extensions/EntityFrameworkSearchesServiceCollectionExtensions.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
using Microsoft.EntityFrameworkCore;
2-
using Microsoft.EntityFrameworkCore.Infrastructure;
32
using Microsoft.Extensions.DependencyInjection.Extensions;
43
using RoyalCode.SmartSearch;
5-
using RoyalCode.SmartSearch.Defaults;
64
using RoyalCode.SmartSearch.EntityFramework.Configurations;
75
using RoyalCode.SmartSearch.EntityFramework.Services;
86
using RoyalCode.SmartSearch.Linq;
9-
using RoyalCode.SmartSearch.Linq.Services;
10-
using RoyalCode.SmartSearch.Linq.Sortings;
117

128
namespace Microsoft.Extensions.DependencyInjection;
139

@@ -72,31 +68,4 @@ public static IServiceCollection AddSearchManager<TDbContext>(this IServiceColle
7268

7369
return services;
7470
}
75-
76-
/// <summary>
77-
/// <para>
78-
/// Creates a new <see cref="ICriteria{TEntity}"/> for the entity <typeparamref name="TEntity"/>
79-
/// using the <see cref="DbContext"/> used by the unit of work.
80-
/// </para>
81-
/// </summary>
82-
/// <typeparam name="TEntity"></typeparam>
83-
/// <param name="db"></param>
84-
/// <returns></returns>
85-
public static ICriteria<TEntity> Criteria<TEntity>(this DbContext db)
86-
where TEntity : class
87-
{
88-
var specifierFactory = db.GetService<ISpecifierFactory>();
89-
var orderByFactory = db.GetService<IOrderByProvider>();
90-
var selectorFactory = db.GetService<ISelectorFactory>();
91-
92-
var preparer = new CriteriaPerformer<DbContext, TEntity>(
93-
db,
94-
specifierFactory,
95-
orderByFactory,
96-
selectorFactory);
97-
98-
var criteria = new Criteria<TEntity>(preparer);
99-
100-
return criteria;
101-
}
10271
}

src/tests.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<DotNetCoreVersion>8.0.0</DotNetCoreVersion>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1515
<PackageReference Include="xunit" Version="2.9.3" />
16-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>
@@ -22,7 +22,7 @@
2222
<PrivateAssets>all</PrivateAssets>
2323
</PackageReference>
2424

25-
<PackageReference Include="FluentAssertions" Version="8.2.0" />
25+
<PackageReference Include="FluentAssertions" Version="8.5.0" />
2626
<PackageReference Include="Moq" Version="4.20.72" />
2727

2828
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="$(DotNetCoreVersion)" />

0 commit comments

Comments
 (0)