Skip to content

Commit 9b4cd3d

Browse files
committed
Consolidating conversion of ProjectionDeclarationSyntaxError
1 parent 6971f3f commit 9b4cd3d

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

Source/Clients/Api/Projections/GenerateDeclarativeCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal async Task<GeneratedCodeResult> Handle(IProjections projections)
3535
GeneratedCode code => new GeneratedCodeResult(code.Code, []),
3636
ProjectionDeclarationParsingErrors errors => new GeneratedCodeResult(
3737
string.Empty,
38-
errors.Errors.Select(e => new ProjectionDeclarationSyntaxError(e.Message, e.Line, e.Column))),
38+
errors.Errors.ToApi()),
3939
_ => throw new InvalidOperationException("Unexpected result type from GenerateDeclarativeCode")
4040
};
4141
}

Source/Clients/Api/Projections/GenerateModelBoundCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal async Task<GeneratedCodeResult> Handle(IProjections projections)
3535
GeneratedCode code => new GeneratedCodeResult(code.Code, []),
3636
ProjectionDeclarationParsingErrors errors => new GeneratedCodeResult(
3737
string.Empty,
38-
errors.Errors.Select(e => new ProjectionDeclarationSyntaxError(e.Message, e.Line, e.Column))),
38+
errors.Errors.ToApi()),
3939
_ => throw new InvalidOperationException("Unexpected result type from GenerateModelBoundCode")
4040
};
4141
}

Source/Clients/Api/Projections/PreviewProjection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ internal async Task<ProjectionPreview> Handle(IProjections projections)
4949
ProjectionDeclarationParsingErrors errors => new ProjectionPreview(
5050
[],
5151
new JsonObject(),
52-
errors.Errors.Select(e => new ProjectionDeclarationSyntaxError(e.Message, e.Line, e.Column))),
52+
errors.Errors.ToApi()),
5353

5454
_ => throw new InvalidOperationException("Unexpected result type from Preview")
5555
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Cratis.Chronicle.Api.Projections;
5+
6+
/// <summary>
7+
/// Extension methods for converting <see cref="Contracts.Projections.ProjectionDeclarationSyntaxError"/> to <see cref="ProjectionDeclarationSyntaxError"/>.
8+
/// </summary>
9+
public static class ProjectionDeclarationSyntaxErrorConverters
10+
{
11+
/// <summary>
12+
/// Converts a <see cref="Contracts.Projections.ProjectionDeclarationSyntaxError"/> to <see cref="ProjectionDeclarationSyntaxError"/>.
13+
/// </summary>
14+
/// <param name="error">The contract error to convert.</param>
15+
/// <returns>The converted API error.</returns>
16+
public static ProjectionDeclarationSyntaxError ToApi(this Contracts.Projections.ProjectionDeclarationSyntaxError error) =>
17+
new(error.Message, error.Line, error.Column);
18+
19+
/// <summary>
20+
/// Converts a collection of <see cref="Contracts.Projections.ProjectionDeclarationSyntaxError"/> to <see cref="ProjectionDeclarationSyntaxError"/>.
21+
/// </summary>
22+
/// <param name="errors">The contract errors to convert.</param>
23+
/// <returns>The converted API errors.</returns>
24+
public static IEnumerable<ProjectionDeclarationSyntaxError> ToApi(this IEnumerable<Contracts.Projections.ProjectionDeclarationSyntaxError> errors) =>
25+
errors.Select(e => e.ToApi());
26+
}

0 commit comments

Comments
 (0)