Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- added intelligent mapping when targeting a Nox table #1502

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Nox.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebApi", "WebApi", "{672E56
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Generator.Tests", "tests\Nox.Generator.Tests\Nox.Generator.Tests.csproj", "{58599385-98BD-44A4-9990-A7AEDCAFC8A0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "r", "r", "{820129FF-6448-42E2-8792-ABE1A8CBF722}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "0SolutionItems", "0SolutionItems", "{820129FF-6448-42E2-8792-ABE1A8CBF722}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
GitVersion.yml = GitVersion.yml
Expand Down
3 changes: 3 additions & 0 deletions samples/Cryptocash.Api/Cryptocash.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<InputFiles Include="../.nox/design/**/*.yaml" />
<InputFiles Include="*generator.nox.yaml" />
</ItemGroup>
<ItemGroup>
<Folder Update="..\.nox\design" />
</ItemGroup>
<Target Name="NoxGeneratorBeforeTarget" BeforeTargets="CoreCompile" Inputs="@(InputFiles)" Outputs="$(OutputDirectory)">
<NoxGeneratorTask NoxYamlFiles="@(InputFiles)" OutputDirectory="$(OutputDirectory)"></NoxGeneratorTask>
</Target>
Expand Down
18 changes: 9 additions & 9 deletions samples/Cryptocash.Api/Nox.Generated/Generator.g.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Generated
#nullable enable
/* Found files ->
// Generated

#nullable enable

/* Found files ->
- cryptocash.application.nox.yaml
- cryptocash.solution.nox.yaml
- cryptocash.domain.nox.yaml
Expand Down Expand Up @@ -34,7 +34,7 @@
- countriesByName.apiRouteMapping.nox.yaml
- cryptocash.apiConfiguration.nox.yaml
- cryptocash.presentation.nox.yaml
- generator.nox.yaml
Logging Verbosity Minimal
SUCCESS.
*/
- generator.nox.yaml
Logging Verbosity Minimal
SUCCESS.
*/
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,31 @@
# yaml-language-server: $schema=../../../../../schemas/integrationTransform.json
#

# NOTE: When targeting a Nox db table, target type and isRequired are redundant

mapping:
- source:
name: CountryId
type: integer
target:
name: Id
type: integer
isRequired: true

- source:
name: CountryName
type: string
target:
name: Name
type: string
isRequired: true

- source:
name: NoOfInhabitants
type: integer
target:
name: Population
type: integer
isRequired: true

# NOTE: create and edit dates are not mapped as the field names are the same in the source and target, Nox will map them auto-magically

# This demonstrated a field that only exists in the source, we will map it to a target field in the transform function
- source:
name: DateCreated
name: ConcurrencyStamp
type: string
target:
name: CreateDate
type: dateTime
isRequired: true

- source:
name: DateChanged
type: string
target:
name: EditDate
type: dateTime

# Left this here as a reminder - Integrations that target Nox Entity tables are not allowed to target Etag attribute.
# - source:
# name: ConcurrencyStamp
# type: string
# target:
# name: Etag
# type: guid
# isRequired: true

- target:
name: PopulationMillions
type: integer
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ source:
- CreateDate
- EditDate


sourceAdapterType: databaseQuery

queryOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ attributes:
- name: EditDate
description: The date on which the country record was last updated
type: dateTime

- name: PopulationMillions
description: This holds a calculated value, set in the transform function. value = NoFoInhabitants / 1million
type: number
numberTypeOptions:


- name: NameWithConcurrency
description: This holds a concat of CountryName and ConcurrencyStamp, which is set in the transform function
type: text

persistence:
isAudited: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<ItemGroup>
<Folder Include="Generated\Nox.Generator\Nox.Generator.NoxCodeGenerator\" />
<Folder Include="Migrations\" />
<Folder Include="Mixed\" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Globalization;
using CryptocashIntegration.Application.Integration.CustomTransform;
using Nox.Integration.Abstractions.Interfaces;

namespace Cryptocash.Integration.Integrations;

Expand All @@ -9,7 +7,12 @@ public class JsonToTableTransform: JsonToTableTransformBase
public override JsonToTableTargetDto Invoke(JsonToTableSourceDto source)
{
var result = base.Invoke(source);
result.PopulationMillions = source.NoOfInhabitants / 1000000;
if (source.NoOfInhabitants.HasValue)
{
result.PopulationMillions = (int)source.NoOfInhabitants / 1000000;
}

result.NameWithConcurrency = source.CountryName + "_" + source.ConcurrencyStamp;
return result;
}
}
}
4 changes: 0 additions & 4 deletions samples/Cryptocash.Integration/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

builder.AddNox();

//You have to register all your integration transformation handlers.
builder.Services.RegisterIntegrationTransform<JsonToTableTransform>();
//builder.Services.RegisterIntegrationTransform<TestTransform>();

//builder.AddNox((noxOptions) => noxOptions.WithoutNoxLogging());

// builder.AddNox((noxOptions) => noxOptions.WithNoxLogging((loggerConfiguration) =>
Expand Down
Loading
Loading