Skip to content

Commit ac56150

Browse files
committed
Update SPPreview version and enhance OkMatch<T> handling
Updated the SPPreview version in Directory.Build.props from -preview-4.8 to -preview-4.9. Added a new using directive for RoyalCode.SmartProblems.Entities in OkMatch'1.cs. Introduced an implicit conversion operator and a new constructor in the OkMatch<T> class to handle FindResult<T> objects more effectively, providing specific logic for "not found" cases.
1 parent db11ac1 commit ac56150

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111
<PropertyGroup>
1212
<SPVer>1.0.0</SPVer>
13-
<SPPreview>-preview-4.8</SPPreview>
13+
<SPPreview>-preview-4.9</SPPreview>
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<FluentValidationVer>12.0.0</FluentValidationVer>

src/RoyalCode.SmartProblems.ApiResults/HttpResults/OkMatch'1.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Http.HttpResults;
44
using Microsoft.AspNetCore.Http.Metadata;
5+
using RoyalCode.SmartProblems.Entities;
56
using RoyalCode.SmartProblems.Metadata;
67
using System.Net.Mime;
78
using System.Reflection;
@@ -28,6 +29,13 @@ public sealed class OkMatch<T> : IResult, INestedHttpResult, IEndpointMetadataPr
2829
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2930
public static implicit operator OkMatch<T>(Result<T> result) => new(result);
3031

32+
/// <summary>
33+
/// Creates a new <see cref="OkMatch{T}"/> for the <see cref="Result{TValue}"/>.
34+
/// </summary>
35+
/// <param name="result"></param>
36+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
37+
public static implicit operator OkMatch<T>(FindResult<T> result) => new(result);
38+
3139
/// <summary>
3240
/// Creates a new <see cref="OkMatch{T}"/> for the <see cref="Ok{TValue}"/>.
3341
/// </summary>
@@ -74,6 +82,17 @@ public OkMatch(Result<T> result)
7482
static error => new MatchErrorResult(error));
7583
}
7684

85+
/// <summary>
86+
/// Creates a new <see cref="IResult"/> for the <see cref="FindResult{TEntity}"/> match.
87+
/// </summary>
88+
/// <param name="result">The <see cref="FindResult{TEntity}"/> to be converted.</param>
89+
public OkMatch(FindResult<T> result)
90+
{
91+
Result = result.NotFound(out var problem)
92+
? new MatchErrorResult(problem)
93+
: TypedResults.Ok(result.Entity);
94+
}
95+
7796
/// <summary>
7897
/// Creates a new <see cref="OkMatch{T}"/> for the <see cref="Ok{TValue}"/> match.
7998
/// </summary>

0 commit comments

Comments
 (0)