-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathToAcceptedHttpResultTE.cs
More file actions
27 lines (24 loc) · 1.31 KB
/
ToAcceptedHttpResultTE.cs
File metadata and controls
27 lines (24 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace CSharpFunctionalExtensions.HttpResults.Generators.ResultExtensions;
internal class ToAcceptedHttpResultTE : IGenerateMethods
{
public string Generate(string mapperClassName, string resultErrorType, string httpResultType)
{
return $$"""
/// <summary>
/// Returns a <see cref="Accepted{TValue}"/> with Accepted status code in case of success result. Returns custom mapping in case of failure. You can provide an URI to create a location HTTP-Header.
/// </summary>
public static Results<Accepted<T>, {{httpResultType}}> ToAcceptedHttpResult<T>(this Result<T,{{resultErrorType}}> result, Func<T, Uri> uri)
{
if (result.IsSuccess) return TypedResults.Accepted(uri(result.Value), result.Value);
return ErrorMapperInstances.{{mapperClassName}}.Map(result.Error);
}
/// <summary>
/// Returns a <see cref="Accepted{TValue}"/> with Accepted status code in case of success result. Returns custom mapping in case of failure. You can provide an URI to create a location HTTP-Header.
/// </summary>
public static async Task<Results<Accepted<T>, {{httpResultType}}>> ToAcceptedHttpResult<T>(this Task<Result<T,{{resultErrorType}}>> result, Func<T, Uri> uri)
{
return (await result).ToAcceptedHttpResult(uri);
}
""";
}
}