-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/namespace-as-route
- Loading branch information
Showing
40 changed files
with
615 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ecipe.Service.Application/CodingStyle/RichEntity/FindTargetUsingQueryContextConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Baked.Business; | ||
using Baked.Domain.Model; | ||
using Baked.Orm; | ||
using Baked.RestApi.Configuration; | ||
using Baked.RestApi.Model; | ||
using Humanizer; | ||
|
||
namespace Baked.CodingStyle.RichEntity; | ||
|
||
public class FindTargetUsingQueryContextConvention(DomainModel _domain) | ||
: IApiModelConvention<ActionModelContext> | ||
{ | ||
public void Apply(ActionModelContext context) | ||
{ | ||
if (context.Action.MappedMethod is null) { return; } | ||
if (context.Action.MappedMethod.Has<InitializerAttribute>()) { return; } | ||
if (context.Controller.MappedType is null) { return; } | ||
if (!context.Controller.MappedType.TryGetMetadata(out var metadata)) { return; } | ||
if (!metadata.Has<EntityAttribute>()) { return; } | ||
|
||
var entityType = context.Controller.MappedType; | ||
if (!entityType.TryGetQueryContextType(_domain, out var queryContextType)) { return; } | ||
|
||
var idProperty = entityType.GetMembers().Properties["Id"]; | ||
|
||
var target = context.Action.Parameters.Single(p => p.IsTarget()); | ||
target.Name = "id"; | ||
target.From = ParameterModelFrom.Route; | ||
target.RoutePosition = 1; | ||
target.AdditionalAttributes.Add($"SwaggerSchema(\"Unique value to find {context.Controller.MappedType.Name.Humanize().ToLowerInvariant()} resource\")"); | ||
target.Type = idProperty.PropertyType.CSharpFriendlyFullName; | ||
|
||
var queryContextParameter = context.Action.AddQueryContextAsService(queryContextType); | ||
context.Action.RouteParts = [entityType.Name.Pluralize(), context.Action.Name]; | ||
context.Action.FindTargetStatement = queryContextParameter.BuildSingleBy("id", fromRoute: true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...aked.Recipe.Service.Application/CodingStyle/RichEntity/TargetEntityFromRouteConvention.cs
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...d.Recipe.Service.Application/CodingStyle/RichTransient/AddIdParameterToRouteConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Baked.Business; | ||
using Baked.RestApi.Configuration; | ||
using Baked.RestApi.Model; | ||
using Humanizer; | ||
|
||
namespace Baked.CodingStyle.RichTransient; | ||
|
||
public class AddIdParameterToRouteConvention : IApiModelConvention<ActionModelContext> | ||
{ | ||
public void Apply(ActionModelContext context) | ||
{ | ||
if (!context.Controller.MappedType.TryGetMembers(out var members)) { return; } | ||
if (!members.Methods.Having<InitializerAttribute>().Any()) { return; } | ||
if (!members.Has<LocatableAttribute>()) { return; } | ||
if (context.Action.MappedMethod is null) { return; } | ||
if (context.Action.MappedMethod.Has<InitializerAttribute>()) { return; } | ||
|
||
var initializer = members.Methods.Having<InitializerAttribute>().Single(); | ||
if (!initializer.DefaultOverload.Parameters.TryGetValue("id", out var parameter)) { return; } | ||
|
||
context.Action.Parameter["id"] = | ||
new(parameter.ParameterType, ParameterModelFrom.Route, parameter.Name, MappedParameter: parameter) | ||
{ | ||
IsOptional = parameter.IsOptional, | ||
DefaultValue = parameter.DefaultValue, | ||
IsInvokeMethodParameter = false, | ||
RoutePosition = 1, | ||
AdditionalAttributes = [$"SwaggerSchema(\"Unique value to find {context.Controller.MappedType.Name.Humanize().ToLowerInvariant()} resource\")"] | ||
}; | ||
context.Action.RouteParts = [context.Controller.MappedType.Name.Pluralize(), context.Action.Name]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ipe.Service.Application/CodingStyle/RichTransient/FindTargetUsingInitializerConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Baked.Business; | ||
using Baked.RestApi.Configuration; | ||
|
||
namespace Baked.CodingStyle.RichTransient; | ||
|
||
public class FindTargetUsingInitializerConvention : IApiModelConvention<ActionModelContext> | ||
{ | ||
public void Apply(ActionModelContext context) | ||
{ | ||
if (!context.Controller.MappedType.TryGetMembers(out var members)) { return; } | ||
if (!members.Methods.Having<InitializerAttribute>().Any()) { return; } | ||
if (context.Action.MappedMethod is null) { return; } | ||
if (context.Action.MappedMethod.Has<InitializerAttribute>()) { return; } | ||
|
||
var initializer = members.Methods.Having<InitializerAttribute>().Single(); | ||
var initilzerParameters = context.Action.Parameters.Where(p => !p.FromServices && !p.IsInvokeMethodParameter && (p.FromQuery || p.FromRoute)); | ||
context.Action.FindTargetStatement = $"target.{initializer.Name}({initilzerParameters.Select(p => $"{p.InternalName}: {p.RenderLookup($"@{p.Name}")}").Join(", ")})"; | ||
} | ||
} |
Oops, something went wrong.