-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DMS-396] Coerce date middleware (#339)
* Coerce date middleware * E2E tests
- Loading branch information
1 parent
0279947
commit eb42af8
Showing
8 changed files
with
118 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
}, | ||
"additionalProperties": false | ||
}, | ||
"compatibleDsRange": true, | ||
"description": { | ||
"type": "string" | ||
}, | ||
|
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
30 changes: 30 additions & 0 deletions
30
src/dms/core/EdFi.DataManagementService.Core/Middleware/CoerceDateTimesMiddleware.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,30 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Licensed to the Ed-Fi Alliance under one or more agreements. | ||
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
// See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
using EdFi.DataManagementService.Core.ApiSchema.Extensions; | ||
using System.Text.Json.Nodes; | ||
using EdFi.DataManagementService.Core.Pipeline; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace EdFi.DataManagementService.Core.Middleware; | ||
|
||
internal class CoerceDateTimesMiddleware(ILogger logger) : IPipelineStep | ||
{ | ||
public async Task Execute(PipelineContext context, Func<Task> next) | ||
{ | ||
logger.LogDebug("Entering CoerceDateTimesMiddleware - {TraceId}", context.FrontendRequest.TraceId); | ||
|
||
foreach (string path in context.ResourceSchema.DateTimeJsonPaths.Select(path => path.Value)) | ||
{ | ||
IEnumerable<JsonNode?> jsonNodes = context.ParsedBody.SelectNodesFromArrayPath(path, logger); | ||
foreach (JsonNode? jsonNode in jsonNodes) | ||
{ | ||
jsonNode?.TryCoerceDateToDateTime(); | ||
} | ||
} | ||
|
||
await next(); | ||
} | ||
} |
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