From 194d23c57bbf6e2aa260fe58e8c4cee5865877cc Mon Sep 17 00:00:00 2001 From: Jason Ray Date: Wed, 11 Sep 2024 14:29:28 -0400 Subject: [PATCH] Add Result.Created void methods so that return Result type is implicitly handled. (#200) * Created methods should use the passed value to correctly create to respective Result response with the set status of ResultStatus.Created * Reverted changes in order to make use of the Void result * Added the created methods to the Result.Void class so that it can implicitly convert from the Value to the Result with the Created status set. --------- Co-authored-by: Steve Smith --- src/Ardalis.Result/Result.Void.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Ardalis.Result/Result.Void.cs b/src/Ardalis.Result/Result.Void.cs index 7209074..55f5c74 100644 --- a/src/Ardalis.Result/Result.Void.cs +++ b/src/Ardalis.Result/Result.Void.cs @@ -49,6 +49,30 @@ public static Result Success(T value, string successMessage) return new Result(value, successMessage); } + /// + /// Represents a successful operation that resulted in the creation of a new resource. + /// Accepts a value as the result of the operation. + /// + /// Sets the Value property + /// A Result + public static Result Created(T value) + { + return Result.Created(value); + } + + /// + /// Represents a successful operation that resulted in the creation of a new resource. + /// Accepts a value as the result of the operation. + /// Accepts a location for the new resource. + /// + /// Sets the Value property + /// The location of the newly created resource + /// A Result + public static Result Created(T value, string location) + { + return Result.Created(value, location); + } + /// /// Represents an error that occurred during the execution of the service. /// Error messages may be provided and will be exposed via the Errors property.