Skip to content

Commit b160478

Browse files
authored
Added Queries as HTTP GET (#63)
1 parent a816d54 commit b160478

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

samples/EasyWay.Samples/Queries/SampleQuery.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{
33
public class SampleQuery : Query<SampleModule, SampleQueryResult>
44
{
5-
public string Name { get; set; }
5+
public required string Name { get; init; }
6+
7+
public required int Age { get; init; }
68
}
79
}

source/EasyWay.WebApi/RcpStyleExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static WebKernel MapQuery<TModule, TQuery, TReadModel>(this WebKernel web
1414
where TQuery : Query<TModule, TReadModel>
1515
where TReadModel : ReadModel
1616
{
17-
webKernel.App.MapPost(typeof(TModule).Name + "/_queries/" + typeof(TQuery).Name, async ([FromBody] TQuery query, IModuleExecutor<TModule> executor, CancellationToken cancellationToken) =>
17+
webKernel.App.MapGet("api/" + typeof(TModule).Name + "/" + typeof(TQuery).Name, async ([AsParameters] TQuery query, IModuleExecutor<TModule> executor, CancellationToken cancellationToken) =>
1818
{
1919
var queryResult = await executor.Execute(query, cancellationToken);
2020

@@ -35,7 +35,7 @@ public static WebKernel MapCommand<TModule, TCommand>(this WebKernel webKernel)
3535
where TModule : EasyWayModule
3636
where TCommand : Command<TModule>
3737
{
38-
webKernel.App.MapPost(typeof(TModule).Name + "/_commands/" + typeof(TCommand).Name, async ([FromBody] TCommand command, IModuleExecutor<TModule> executor, CancellationToken cancellationToken) =>
38+
webKernel.App.MapPost("api/" + typeof(TModule).Name + "/" + typeof(TCommand).Name, async ([FromBody] TCommand command, IModuleExecutor<TModule> executor, CancellationToken cancellationToken) =>
3939
{
4040
var commandResult = await executor.Execute(command, cancellationToken);
4141

@@ -55,7 +55,7 @@ public static WebKernel MapCommand<TModule, TCommand, TCommandResult>(this WebKe
5555
where TCommand : Command<TModule, TCommandResult>
5656
where TCommandResult : OperationResult
5757
{
58-
webKernel.App.MapPost(typeof(TModule).Name + "/_commands/" + typeof(TCommand).Name, async ([FromBody] TCommand command, IModuleExecutor<TModule> executor, CancellationToken cancellationToken) =>
58+
webKernel.App.MapPost("api/" + typeof(TModule).Name + "/" + typeof(TCommand).Name, async ([FromBody] TCommand command, IModuleExecutor<TModule> executor, CancellationToken cancellationToken) =>
5959
{
6060
var commandResult = await executor.Execute(command, cancellationToken);
6161

0 commit comments

Comments
 (0)