diff --git a/src/MaksIT.Results/MaksIT.Results.csproj b/src/MaksIT.Results/MaksIT.Results.csproj index 66cfbb2..618197c 100644 --- a/src/MaksIT.Results/MaksIT.Results.csproj +++ b/src/MaksIT.Results/MaksIT.Results.csproj @@ -8,7 +8,7 @@ MaksIT.Results - 1.0.0 + 1.0.1 Maksym Sadovnychyy MAKS-IT MaksIT.Results diff --git a/src/MaksIT.Results/Result.ClientError.cs b/src/MaksIT.Results/Result.ClientError.cs index 7d01ae1..a85c59c 100644 --- a/src/MaksIT.Results/Result.ClientError.cs +++ b/src/MaksIT.Results/Result.ClientError.cs @@ -1,250 +1,460 @@ using System.Net; -namespace MaksIT.Results { - public partial class Result { +namespace MaksIT.Results; - /// - /// Returns a result indicating that the server could not understand the request due to invalid syntax. - /// Corresponds to HTTP status code 400 Bad Request. - /// - public static Result BadRequest(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.BadRequest); - } +public partial class Result { - /// - /// Returns a result indicating that the client must authenticate itself to get the requested response. - /// Corresponds to HTTP status code 401 Unauthorized. - /// - public static Result Unauthorized(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.Unauthorized); - } + /// + /// Returns a result indicating that the server could not understand the request due to invalid syntax. + /// Corresponds to HTTP status code 400 Bad Request. + /// + public static Result BadRequest(string message) => + BadRequest(new List { message }); - /// - /// Returns a result indicating that the client does not have access rights to the content. - /// Corresponds to HTTP status code 403 Forbidden. - /// - public static Result Forbidden(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.Forbidden); - } - - /// - /// Returns a result indicating that the server can not find the requested resource. - /// Corresponds to HTTP status code 404 Not Found. - /// - public static Result NotFound(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.NotFound); - } - - /// - /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. - /// Corresponds to HTTP status code 409 Conflict. - /// - public static Result Conflict(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.Conflict); - } - - /// - /// Returns a result indicating that the requested resource is no longer available and will not be available again. - /// Corresponds to HTTP status code 410 Gone. - /// - public static Result Gone(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)410); // 410 Gone - } - - /// - /// Returns a result indicating that the request failed because it depended on another request and that request failed. - /// Corresponds to HTTP status code 424 Failed Dependency. - /// - public static Result FailedDependency(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)424); // 424 Failed Dependency - } - - /// - /// Returns a result indicating that the server requires the request to be conditional. - /// Corresponds to HTTP status code 428 Precondition Required. - /// - public static Result PreconditionRequired(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)428); // 428 Precondition Required - } - - /// - /// Returns a result indicating that the user has sent too many requests in a given amount of time. - /// Corresponds to HTTP status code 429 Too Many Requests. - /// - public static Result TooManyRequests(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)429); // 429 Too Many Requests - } - - /// - /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. - /// Corresponds to HTTP status code 431 Request Header Fields Too Large. - /// - public static Result RequestHeaderFieldsTooLarge(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)431); // 431 Request Header Fields Too Large - } - - /// - /// Returns a result indicating that the server cannot process the request entity because it is too large. - /// Corresponds to HTTP status code 413 Payload Too Large. - /// - public static Result PayloadTooLarge(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)413); // 413 Payload Too Large - } - - /// - /// Returns a result indicating that the server cannot process the request because the URI is too long. - /// Corresponds to HTTP status code 414 URI Too Long. - /// - public static Result UriTooLong(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)414); // 414 URI Too Long - } - - /// - /// Returns a result indicating that the server cannot process the request because the media type is unsupported. - /// Corresponds to HTTP status code 415 Unsupported Media Type. - /// - public static Result UnsupportedMediaType(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.UnsupportedMediaType); - } - - /// - /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. - /// Corresponds to HTTP status code 411 Length Required. - /// - public static Result LengthRequired(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)411); // 411 Length Required - } - - /// - /// Returns a result indicating that the server cannot process the request due to an illegal request entity. - /// Corresponds to HTTP status code 422 Unprocessable Entity. - /// - public static Result UnprocessableEntity(params string[] messages) { - return new Result(false, new List(messages), (HttpStatusCode)422); // 422 Unprocessable Entity - } + /// + /// Returns a result indicating that the server could not understand the request due to invalid syntax. + /// Corresponds to HTTP status code 400 Bad Request. + /// + public static Result BadRequest(List messages) { + return new Result(false, messages, HttpStatusCode.BadRequest); } - public partial class Result : Result { + /// + /// Returns a result indicating that the client must authenticate itself to get the requested response. + /// Corresponds to HTTP status code 401 Unauthorized. + /// + public static Result Unauthorized(string message) => + Unauthorized(new List { message }); - /// - /// Returns a result indicating that the server could not understand the request due to invalid syntax. - /// Corresponds to HTTP status code 400 Bad Request. - /// - public static Result BadRequest(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.BadRequest); - } + /// + /// Returns a result indicating that the client must authenticate itself to get the requested response. + /// Corresponds to HTTP status code 401 Unauthorized. + /// + public static Result Unauthorized(List messages) { + return new Result(false, messages, HttpStatusCode.Unauthorized); + } - /// - /// Returns a result indicating that the client must authenticate itself to get the requested response. - /// Corresponds to HTTP status code 401 Unauthorized. - /// - public static Result Unauthorized(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.Unauthorized); - } + /// + /// Returns a result indicating that the client does not have access rights to the content. + /// Corresponds to HTTP status code 403 Forbidden. + /// + public static Result Forbidden(string message) => + Forbidden(new List { message }); - /// - /// Returns a result indicating that the client does not have access rights to the content. - /// Corresponds to HTTP status code 403 Forbidden. - /// - public static Result Forbidden(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.Forbidden); - } + /// + /// Returns a result indicating that the client does not have access rights to the content. + /// Corresponds to HTTP status code 403 Forbidden. + /// + public static Result Forbidden(List messages) { + return new Result(false, messages, HttpStatusCode.Forbidden); + } - /// - /// Returns a result indicating that the server can not find the requested resource. - /// Corresponds to HTTP status code 404 Not Found. - /// - public static Result NotFound(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.NotFound); - } + /// + /// Returns a result indicating that the server can not find the requested resource. + /// Corresponds to HTTP status code 404 Not Found. + /// + public static Result NotFound(string message) => + NotFound(new List { message }); - /// - /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. - /// Corresponds to HTTP status code 409 Conflict. - /// - public static Result Conflict(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.Conflict); - } + /// + /// Returns a result indicating that the server can not find the requested resource. + /// Corresponds to HTTP status code 404 Not Found. + /// + public static Result NotFound(List messagess) { + return new Result(false, messagess, HttpStatusCode.NotFound); + } - /// - /// Returns a result indicating that the requested resource is no longer available and will not be available again. - /// Corresponds to HTTP status code 410 Gone. - /// - public static Result Gone(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)410); // 410 Gone - } + /// + /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. + /// Corresponds to HTTP status code 409 Conflict. + /// + public static Result Conflict(string message) => + Conflict(new List { message }); - /// - /// Returns a result indicating that the request failed because it depended on another request and that request failed. - /// Corresponds to HTTP status code 424 Failed Dependency. - /// - public static Result FailedDependency(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)424); // 424 Failed Dependency - } + /// + /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. + /// Corresponds to HTTP status code 409 Conflict. + /// + public static Result Conflict(List messages) { + return new Result(false, messages, HttpStatusCode.Conflict); + } - /// - /// Returns a result indicating that the server requires the request to be conditional. - /// Corresponds to HTTP status code 428 Precondition Required. - /// - public static Result PreconditionRequired(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)428); // 428 Precondition Required - } + /// + /// Returns a result indicating that the requested resource is no longer available and will not be available again. + /// Corresponds to HTTP status code 410 Gone. + /// + public static Result Gone(string message) => + Gone(new List { message }); - /// - /// Returns a result indicating that the user has sent too many requests in a given amount of time. - /// Corresponds to HTTP status code 429 Too Many Requests. - /// - public static Result TooManyRequests(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)429); // 429 Too Many Requests - } + /// + /// Returns a result indicating that the requested resource is no longer available and will not be available again. + /// Corresponds to HTTP status code 410 Gone. + /// + public static Result Gone(List messages) { + return new Result(false, messages, (HttpStatusCode)410); // 410 Gone + } - /// - /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. - /// Corresponds to HTTP status code 431 Request Header Fields Too Large. - /// - public static Result RequestHeaderFieldsTooLarge(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)431); // 431 Request Header Fields Too Large - } + /// + /// Returns a result indicating that the request failed because it depended on another request and that request failed. + /// Corresponds to HTTP status code 424 Failed Dependency. + /// + public static Result FailedDependency(string message) => + FailedDependency(new List { message }); - /// - /// Returns a result indicating that the server cannot process the request entity because it is too large. - /// Corresponds to HTTP status code 413 Payload Too Large. - /// - public static Result PayloadTooLarge(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)413); // 413 Payload Too Large - } + /// + /// Returns a result indicating that the request failed because it depended on another request and that request failed. + /// Corresponds to HTTP status code 424 Failed Dependency. + /// + public static Result FailedDependency(List messages) { + return new Result(false, messages, (HttpStatusCode)424); // 424 Failed Dependency + } - /// - /// Returns a result indicating that the server cannot process the request because the URI is too long. - /// Corresponds to HTTP status code 414 URI Too Long. - /// - public static Result UriTooLong(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)414); // 414 URI Too Long - } + /// + /// Returns a result indicating that the server requires the request to be conditional. + /// Corresponds to HTTP status code 428 Precondition Required. + /// + public static Result PreconditionRequired(string message) => + PreconditionRequired(new List { message }); - /// - /// Returns a result indicating that the server cannot process the request because the media type is unsupported. - /// Corresponds to HTTP status code 415 Unsupported Media Type. - /// - public static Result UnsupportedMediaType(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.UnsupportedMediaType); - } + /// + /// Returns a result indicating that the server requires the request to be conditional. + /// Corresponds to HTTP status code 428 Precondition Required. + /// + public static Result PreconditionRequired(List messages) { + return new Result(false, messages, (HttpStatusCode)428); // 428 Precondition Required + } - /// - /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. - /// Corresponds to HTTP status code 411 Length Required. - /// - public static Result LengthRequired(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)411); // 411 Length Required - } + /// + /// Returns a result indicating that the user has sent too many requests in a given amount of time. + /// Corresponds to HTTP status code 429 Too Many Requests. + /// + public static Result TooManyRequests(string message) => + TooManyRequests(new List { message }); - /// - /// Returns a result indicating that the server cannot process the request due to an illegal request entity. - /// Corresponds to HTTP status code 422 Unprocessable Entity. - /// - public static Result UnprocessableEntity(T? value, params string[] messages) { - return new Result(value, false, new List(messages), (HttpStatusCode)422); // 422 Unprocessable Entity - } + /// + /// Returns a result indicating that the user has sent too many requests in a given amount of time. + /// Corresponds to HTTP status code 429 Too Many Requests. + /// + public static Result TooManyRequests(List messages) { + return new Result(false, messages, (HttpStatusCode)429); // 429 Too Many Requests + } + + /// + /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. + /// Corresponds to HTTP status code 431 Request Header Fields Too Large. + /// + public static Result RequestHeaderFieldsTooLarge(string message) => + RequestHeaderFieldsTooLarge(new List { message }); + + /// + /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. + /// Corresponds to HTTP status code 431 Request Header Fields Too Large. + /// + public static Result RequestHeaderFieldsTooLarge(List messages) { + return new Result(false, messages, (HttpStatusCode)431); // 431 Request Header Fields Too Large + } + + /// + /// Returns a result indicating that the server cannot process the request entity because it is too large. + /// Corresponds to HTTP status code 413 Payload Too Large. + /// + public static Result PayloadTooLarge(string message) => + PayloadTooLarge(new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request entity because it is too large. + /// Corresponds to HTTP status code 413 Payload Too Large. + /// + public static Result PayloadTooLarge(List messages) { + return new Result(false, messages, (HttpStatusCode)413); // 413 Payload Too Large + } + + /// + /// Returns a result indicating that the server cannot process the request because the URI is too long. + /// Corresponds to HTTP status code 414 URI Too Long. + /// + public static Result UriTooLong(string message) => + UriTooLong(new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request because the URI is too long. + /// Corresponds to HTTP status code 414 URI Too Long. + /// + public static Result UriTooLong(List messages) { + return new Result(false, messages, (HttpStatusCode)414); // 414 URI Too Long + } + + /// + /// Returns a result indicating that the server cannot process the request because the media type is unsupported. + /// Corresponds to HTTP status code 415 Unsupported Media Type. + /// + public static Result UnsupportedMediaType(string message) => + UnsupportedMediaType(new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request because the media type is unsupported. + /// Corresponds to HTTP status code 415 Unsupported Media Type. + /// + public static Result UnsupportedMediaType(List messages) { + return new Result(false, messages, HttpStatusCode.UnsupportedMediaType); + } + + /// + /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. + /// Corresponds to HTTP status code 411 Length Required. + /// + public static Result LengthRequired(string message) => + LengthRequired(new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. + /// Corresponds to HTTP status code 411 Length Required. + /// + public static Result LengthRequired(List messages) { + return new Result(false, messages, (HttpStatusCode)411); // 411 Length Required + } + + /// + /// Returns a result indicating that the server cannot process the request due to an illegal request entity. + /// Corresponds to HTTP status code 422 Unprocessable Entity. + /// + public static Result UnprocessableEntity(string message) => + UnprocessableEntity(new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request due to an illegal request entity. + /// Corresponds to HTTP status code 422 Unprocessable Entity. + /// + public static Result UnprocessableEntity(List messages) { + return new Result(false, messages, (HttpStatusCode)422); // 422 Unprocessable Entity + } +} + +public partial class Result : Result { + + /// + /// Returns a result indicating that the server could not understand the request due to invalid syntax. + /// Corresponds to HTTP status code 400 Bad Request. + /// + public static Result BadRequest(T? value, string message) => + BadRequest(value, new List { message }); + + /// + /// Returns a result indicating that the server could not understand the request due to invalid syntax. + /// Corresponds to HTTP status code 400 Bad Request. + /// + public static Result BadRequest(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.BadRequest); + } + + /// + /// Returns a result indicating that the client must authenticate itself to get the requested response. + /// Corresponds to HTTP status code 401 Unauthorized. + /// + public static Result Unauthorized(T? value, string message) => + Unauthorized(value, new List { message }); + + /// + /// Returns a result indicating that the client must authenticate itself to get the requested response. + /// Corresponds to HTTP status code 401 Unauthorized. + /// + public static Result Unauthorized(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.Unauthorized); + } + + /// + /// Returns a result indicating that the client does not have access rights to the content. + /// Corresponds to HTTP status code 403 Forbidden. + /// + public static Result Forbidden(T? value, string message) => + Forbidden(value, new List { message }); + + /// + /// Returns a result indicating that the client does not have access rights to the content. + /// Corresponds to HTTP status code 403 Forbidden. + /// + public static Result Forbidden(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.Forbidden); + } + + /// + /// Returns a result indicating that the server can not find the requested resource. + /// Corresponds to HTTP status code 404 Not Found. + /// + public static Result NotFound(T? value, string message) => + NotFound(value, new List { message }); + + /// + /// Returns a result indicating that the server can not find the requested resource. + /// Corresponds to HTTP status code 404 Not Found. + /// + public static Result NotFound(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.NotFound); + } + + /// + /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. + /// Corresponds to HTTP status code 409 Conflict. + /// + public static Result Conflict(T? value, string message) => + Conflict(value, new List { message }); + + /// + /// Returns a result indicating that the request could not be completed due to a conflict with the current state of the resource. + /// Corresponds to HTTP status code 409 Conflict. + /// + public static Result Conflict(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.Conflict); + } + + /// + /// Returns a result indicating that the requested resource is no longer available and will not be available again. + /// Corresponds to HTTP status code 410 Gone. + /// + public static Result Gone(T? value, string message) => + Gone(value, new List { message }); + + /// + /// Returns a result indicating that the requested resource is no longer available and will not be available again. + /// Corresponds to HTTP status code 410 Gone. + /// + public static Result Gone(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)410); // 410 Gone + } + + /// + /// Returns a result indicating that the request failed because it depended on another request and that request failed. + /// Corresponds to HTTP status code 424 Failed Dependency. + /// + public static Result FailedDependency(T? value, string message) => + FailedDependency(value, new List { message }); + + /// + /// Returns a result indicating that the request failed because it depended on another request and that request failed. + /// Corresponds to HTTP status code 424 Failed Dependency. + /// + public static Result FailedDependency(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)424); // 424 Failed Dependency + } + + /// + /// Returns a result indicating that the server requires the request to be conditional. + /// Corresponds to HTTP status code 428 Precondition Required. + /// + public static Result PreconditionRequired(T? value, string message) => + PreconditionRequired(value, new List { message }); + + /// + /// Returns a result indicating that the server requires the request to be conditional. + /// Corresponds to HTTP status code 428 Precondition Required. + /// + public static Result PreconditionRequired(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)428); // 428 Precondition Required + } + + /// + /// Returns a result indicating that the user has sent too many requests in a given amount of time. + /// Corresponds to HTTP status code 429 Too Many Requests. + /// + public static Result TooManyRequests(T? value, string message) => + TooManyRequests(value, new List { message }); + + /// + /// Returns a result indicating that the user has sent too many requests in a given amount of time. + /// Corresponds to HTTP status code 429 Too Many Requests. + /// + public static Result TooManyRequests(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)429); // 429 Too Many Requests + } + + /// + /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. + /// Corresponds to HTTP status code 431 Request Header Fields Too Large. + /// + public static Result RequestHeaderFieldsTooLarge(T? value, string message) => + RequestHeaderFieldsTooLarge(value, new List { message }); + + /// + /// Returns a result indicating that the server is unwilling to process the request because its header fields are too large. + /// Corresponds to HTTP status code 431 Request Header Fields Too Large. + /// + public static Result RequestHeaderFieldsTooLarge(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)431); // 431 Request Header Fields Too Large + } + + /// + /// Returns a result indicating that the server cannot process the request entity because it is too large. + /// Corresponds to HTTP status code 413 Payload Too Large. + /// + public static Result PayloadTooLarge(T? value, string message) => + PayloadTooLarge(value, new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request entity because it is too large. + /// Corresponds to HTTP status code 413 Payload Too Large. + /// + public static Result PayloadTooLarge(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)413); // 413 Payload Too Large + } + + /// + /// Returns a result indicating that the server cannot process the request because the URI is too long. + /// Corresponds to HTTP status code 414 URI Too Long. + /// + public static Result UriTooLong(T? value, string message) => + UriTooLong(value, new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request because the URI is too long. + /// Corresponds to HTTP status code 414 URI Too Long. + /// + public static Result UriTooLong(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)414); // 414 URI Too Long + } + + /// + /// Returns a result indicating that the server cannot process the request because the media type is unsupported. + /// Corresponds to HTTP status code 415 Unsupported Media Type. + /// + public static Result UnsupportedMediaType(T? value, string message) => + UnsupportedMediaType(value, new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request because the media type is unsupported. + /// Corresponds to HTTP status code 415 Unsupported Media Type. + /// + public static Result UnsupportedMediaType(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.UnsupportedMediaType); + } + + /// + /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. + /// Corresponds to HTTP status code 411 Length Required. + /// + public static Result LengthRequired(T? value, string message) => + LengthRequired(value, new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request because it expects the request to have a defined Content-Length header. + /// Corresponds to HTTP status code 411 Length Required. + /// + public static Result LengthRequired(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)411); // 411 Length Required + } + + /// + /// Returns a result indicating that the server cannot process the request due to an illegal request entity. + /// Corresponds to HTTP status code 422 Unprocessable Entity. + /// + public static Result UnprocessableEntity(T? value, string message) => + UnprocessableEntity(value, new List { message }); + + /// + /// Returns a result indicating that the server cannot process the request due to an illegal request entity. + /// Corresponds to HTTP status code 422 Unprocessable Entity. + /// + public static Result UnprocessableEntity(T? value, List messages) { + return new Result(value, false, messages, (HttpStatusCode)422); // 422 Unprocessable Entity } } diff --git a/src/MaksIT.Results/Result.Information.cs b/src/MaksIT.Results/Result.Information.cs index efa2ff1..3c2efa5 100644 --- a/src/MaksIT.Results/Result.Information.cs +++ b/src/MaksIT.Results/Result.Information.cs @@ -1,75 +1,131 @@ using System.Net; -namespace MaksIT.Results { - public partial class Result { +namespace MaksIT.Results; - /// - /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. - /// Corresponds to HTTP status code 100 Continue. - /// - public static Result Continue(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.Continue); - } +public partial class Result { - /// - /// Returns a result indicating that the server is switching to a different protocol as requested by the client. - /// Corresponds to HTTP status code 101 Switching Protocols. - /// - public static Result SwitchingProtocols(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.SwitchingProtocols); - } - - /// - /// Returns a result indicating that the server has received and is processing the request, but no response is available yet. - /// Corresponds to HTTP status code 102 Processing. - /// - public static Result Processing(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.Processing); - } - - /// - /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. - /// Corresponds to HTTP status code 103 Early Hints. - /// - public static Result EarlyHints(params string[] messages) { - return new Result(true, new List(messages), (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code - } + /// + /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. + /// Corresponds to HTTP status code 100 Continue. + /// + public static Result Continue(string message) => + Continue(new List { message }); + /// + /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. + /// Corresponds to HTTP status code 100 Continue. + /// + public static Result Continue(List messages) { + return new Result(true, messages, HttpStatusCode.Continue); } - public partial class Result : Result { + /// + /// Returns a result indicating that the server is switching to a different protocol as requested by the client. + /// Corresponds to HTTP status code 101 Switching Protocols. + /// + public static Result SwitchingProtocols(string message) => + SwitchingProtocols(new List { message }); - /// - /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. - /// Corresponds to HTTP status code 100 Continue. - /// - public static Result Continue(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.Continue); - } + /// + /// Returns a result indicating that the server is switching to a different protocol as requested by the client. + /// Corresponds to HTTP status code 101 Switching Protocols. + /// + public static Result SwitchingProtocols(List messages) { + return new Result(true, messages, HttpStatusCode.SwitchingProtocols); + } - /// - /// Returns a result indicating that the server is switching to a different protocol as requested by the client. - /// Corresponds to HTTP status code 101 Switching Protocols. - /// - public static Result SwitchingProtocols(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.SwitchingProtocols); - } + /// + /// Returns a result indicating that the server has received and is processing the request, but no response is available yet. + /// Corresponds to HTTP status code 102 Processing. + /// + public static Result Processing(string message) => + Processing(new List { message }); - /// - /// Returns a result indicating that the server has received and is processing the request, but no response is available yet. - /// Corresponds to HTTP status code 102 Processing. - /// - public static Result Processing(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.Processing); - } + /// + /// Returns a result indicating that the server has received and is processing the request, but no response is available yet. + /// Corresponds to HTTP status code 102 Processing. + /// + public static Result Processing(List messages) { + return new Result(true, messages, HttpStatusCode.Processing); + } - /// - /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. - /// Corresponds to HTTP status code 103 Early Hints. - /// - public static Result EarlyHints(T? value, params string[] messages) { - return new Result(value, true, new List(messages), (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code - } + /// + /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. + /// Corresponds to HTTP status code 103 Early Hints. + /// + public static Result EarlyHints(string message) => + EarlyHints(new List { message }); + + /// + /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. + /// Corresponds to HTTP status code 103 Early Hints. + /// + public static Result EarlyHints(List messages) { + return new Result(true, messages, (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code } } + +public partial class Result : Result { + + /// + /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. + /// Corresponds to HTTP status code 100 Continue. + /// + public static Result Continue(T? value, string message) => + Continue(value, new List { message }); + + /// + /// Returns a result indicating that the initial part of a request has been received and the client should continue with the request. + /// Corresponds to HTTP status code 100 Continue. + /// + public static Result Continue(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.Continue); + } + + /// + /// Returns a result indicating that the server is switching to a different protocol as requested by the client. + /// Corresponds to HTTP status code 101 Switching Protocols. + /// + public static Result SwitchingProtocols(T? value, string message) => + SwitchingProtocols(value, new List { message }); + + /// + /// Returns a result indicating that the server is switching to a different protocol as requested by the client. + /// Corresponds to HTTP status code 101 Switching Protocols. + /// + public static Result SwitchingProtocols(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.SwitchingProtocols); + } + + /// + /// Returns a result indicating that the server has received and is processing the request, but no response is available yet. + /// Corresponds to HTTP status code 102 Processing. + /// + public static Result Processing(T? value, string message) => + Processing(value, new List { message }); + + /// + /// Returns a result indicating that the server has received and is processing the request, but no response is available yet. + /// Corresponds to HTTP status code 102 Processing. + /// + public static Result Processing(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.Processing); + } + + /// + /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. + /// Corresponds to HTTP status code 103 Early Hints. + /// + public static Result EarlyHints(T? value, string message) => + EarlyHints(value, new List { message }); + + /// + /// Returns a result indicating that the server is sending information about early hints that may be used by the client to begin preloading resources while the server prepares a final response. + /// Corresponds to HTTP status code 103 Early Hints. + /// + public static Result EarlyHints(T? value, List messages) { + return new Result(value, true, messages, (HttpStatusCode)103); // Early Hints is not defined in HttpStatusCode enum, 103 is the official code + } +} + diff --git a/src/MaksIT.Results/Result.Redirection.cs b/src/MaksIT.Results/Result.Redirection.cs index 0252a60..efa5128 100644 --- a/src/MaksIT.Results/Result.Redirection.cs +++ b/src/MaksIT.Results/Result.Redirection.cs @@ -1,138 +1,250 @@ using System.Net; -namespace MaksIT.Results { - public partial class Result { +namespace MaksIT.Results; - /// - /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. - /// Corresponds to HTTP status code 300 Multiple Choices. - /// - public static Result MultipleChoices(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.MultipleChoices); - } +public partial class Result { - /// - /// Returns a result indicating that the requested resource has been permanently moved to a new URI. - /// Corresponds to HTTP status code 301 Moved Permanently. - /// - public static Result MovedPermanently(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.MovedPermanently); - } + /// + /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. + /// Corresponds to HTTP status code 300 Multiple Choices. + /// + public static Result MultipleChoices(string message) => + MultipleChoices(new List { message }); - /// - /// Returns a result indicating that the requested resource resides temporarily under a different URI. - /// Corresponds to HTTP status code 302 Found. - /// - public static Result Found(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.Found); - } - - /// - /// Returns a result indicating that the response to the request can be found under another URI using the GET method. - /// Corresponds to HTTP status code 303 See Other. - /// - public static Result SeeOther(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.SeeOther); - } - - /// - /// Returns a result indicating that the requested resource has not been modified since the last request. - /// Corresponds to HTTP status code 304 Not Modified. - /// - public static Result NotModified(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.NotModified); - } - - /// - /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. - /// Corresponds to HTTP status code 305 Use Proxy. - /// - public static Result UseProxy(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.UseProxy); - } - - /// - /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. - /// Corresponds to HTTP status code 307 Temporary Redirect. - /// - public static Result TemporaryRedirect(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.TemporaryRedirect); - } - - /// - /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. - /// Corresponds to HTTP status code 308 Permanent Redirect. - /// - public static Result PermanentRedirect(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.PermanentRedirect); - } + /// + /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. + /// Corresponds to HTTP status code 300 Multiple Choices. + /// + public static Result MultipleChoices(List messages) { + return new Result(true, messages, HttpStatusCode.MultipleChoices); } - public partial class Result : Result { + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI. + /// Corresponds to HTTP status code 301 Moved Permanently. + /// + public static Result MovedPermanently(string message) => + MovedPermanently(new List { message }); - /// - /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. - /// Corresponds to HTTP status code 300 Multiple Choices. - /// - public static Result MultipleChoices(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.MultipleChoices); - } + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI. + /// Corresponds to HTTP status code 301 Moved Permanently. + /// + public static Result MovedPermanently(List messages) { + return new Result(true, messages, HttpStatusCode.MovedPermanently); + } - /// - /// Returns a result indicating that the requested resource has been permanently moved to a new URI. - /// Corresponds to HTTP status code 301 Moved Permanently. - /// - public static Result MovedPermanently(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.MovedPermanently); - } + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI. + /// Corresponds to HTTP status code 302 Found. + /// + public static Result Found(string message) => + Found(new List { message }); - /// - /// Returns a result indicating that the requested resource resides temporarily under a different URI. - /// Corresponds to HTTP status code 302 Found. - /// - public static Result Found(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.Found); - } + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI. + /// Corresponds to HTTP status code 302 Found. + /// + public static Result Found(List messages) { + return new Result(true, messages, HttpStatusCode.Found); + } - /// - /// Returns a result indicating that the response to the request can be found under another URI using the GET method. - /// Corresponds to HTTP status code 303 See Other. - /// - public static Result SeeOther(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.SeeOther); - } + /// + /// Returns a result indicating that the response to the request can be found under another URI using the GET method. + /// Corresponds to HTTP status code 303 See Other. + /// + public static Result SeeOther(string message) => + SeeOther(new List { message }); - /// - /// Returns a result indicating that the requested resource has not been modified since the last request. - /// Corresponds to HTTP status code 304 Not Modified. - /// - public static Result NotModified(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.NotModified); - } + /// + /// Returns a result indicating that the response to the request can be found under another URI using the GET method. + /// Corresponds to HTTP status code 303 See Other. + /// + public static Result SeeOther(List messages) { + return new Result(true, messages, HttpStatusCode.SeeOther); + } - /// - /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. - /// Corresponds to HTTP status code 305 Use Proxy. - /// - public static Result UseProxy(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.UseProxy); - } + /// + /// Returns a result indicating that the requested resource has not been modified since the last request. + /// Corresponds to HTTP status code 304 Not Modified. + /// + public static Result NotModified(string message) => + NotModified(new List { message }); - /// - /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. - /// Corresponds to HTTP status code 307 Temporary Redirect. - /// - public static Result TemporaryRedirect(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.TemporaryRedirect); - } + /// + /// Returns a result indicating that the requested resource has not been modified since the last request. + /// Corresponds to HTTP status code 304 Not Modified. + /// + public static Result NotModified(List messages) { + return new Result(true, messages, HttpStatusCode.NotModified); + } - /// - /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. - /// Corresponds to HTTP status code 308 Permanent Redirect. - /// - public static Result PermanentRedirect(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.PermanentRedirect); - } + /// + /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. + /// Corresponds to HTTP status code 305 Use Proxy. + /// + public static Result UseProxy(string message) => + UseProxy(new List { message }); + + /// + /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. + /// Corresponds to HTTP status code 305 Use Proxy. + /// + public static Result UseProxy(List messages) { + return new Result(true, messages, HttpStatusCode.UseProxy); + } + + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. + /// Corresponds to HTTP status code 307 Temporary Redirect. + /// + public static Result TemporaryRedirect(string message) => + TemporaryRedirect(new List { message }); + + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. + /// Corresponds to HTTP status code 307 Temporary Redirect. + /// + public static Result TemporaryRedirect(List messages) { + return new Result(true, messages, HttpStatusCode.TemporaryRedirect); + } + + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. + /// Corresponds to HTTP status code 308 Permanent Redirect. + /// + public static Result PermanentRedirect(string message) => + PermanentRedirect(new List { message }); + + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. + /// Corresponds to HTTP status code 308 Permanent Redirect. + /// + public static Result PermanentRedirect(List messages) { + return new Result(true, messages, HttpStatusCode.PermanentRedirect); + } +} + +public partial class Result : Result { + + /// + /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. + /// Corresponds to HTTP status code 300 Multiple Choices. + /// + public static Result MultipleChoices(T? value, string message) => + MultipleChoices(value, new List { message }); + + /// + /// Returns a result indicating that the request has multiple options, and the user or user-agent should select one of them. + /// Corresponds to HTTP status code 300 Multiple Choices. + /// + public static Result MultipleChoices(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.MultipleChoices); + } + + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI. + /// Corresponds to HTTP status code 301 Moved Permanently. + /// + public static Result MovedPermanently(T? value, string message) => + MovedPermanently(value, new List { message }); + + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI. + /// Corresponds to HTTP status code 301 Moved Permanently. + /// + public static Result MovedPermanently(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.MovedPermanently); + } + + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI. + /// Corresponds to HTTP status code 302 Found. + /// + public static Result Found(T? value, string message) => + Found(value, new List { message }); + + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI. + /// Corresponds to HTTP status code 302 Found. + /// + public static Result Found(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.Found); + } + + /// + /// Returns a result indicating that the response to the request can be found under another URI using the GET method. + /// Corresponds to HTTP status code 303 See Other. + /// + public static Result SeeOther(T? value, string message) => + SeeOther(value, new List { message }); + + /// + /// Returns a result indicating that the response to the request can be found under another URI using the GET method. + /// Corresponds to HTTP status code 303 See Other. + /// + public static Result SeeOther(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.SeeOther); + } + + /// + /// Returns a result indicating that the requested resource has not been modified since the last request. + /// Corresponds to HTTP status code 304 Not Modified. + /// + public static Result NotModified(T? value, string message) => + NotModified(value, new List { message }); + + /// + /// Returns a result indicating that the requested resource has not been modified since the last request. + /// Corresponds to HTTP status code 304 Not Modified. + /// + public static Result NotModified(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.NotModified); + } + + /// + /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. + /// Corresponds to HTTP status code 305 Use Proxy. + /// + public static Result UseProxy(T? value, string message) => + UseProxy(value, new List { message }); + + /// + /// Returns a result indicating that the requested resource must be accessed through the proxy given by the location field. + /// Corresponds to HTTP status code 305 Use Proxy. + /// + public static Result UseProxy(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.UseProxy); + } + + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. + /// Corresponds to HTTP status code 307 Temporary Redirect. + /// + public static Result TemporaryRedirect(T? value, string message) => + TemporaryRedirect(value, new List { message }); + + /// + /// Returns a result indicating that the requested resource resides temporarily under a different URI, but future requests should still use the original URI. + /// Corresponds to HTTP status code 307 Temporary Redirect. + /// + public static Result TemporaryRedirect(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.TemporaryRedirect); + } + + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. + /// Corresponds to HTTP status code 308 Permanent Redirect. + /// + public static Result PermanentRedirect(T? value, string message) => + PermanentRedirect(value, new List { message }); + + /// + /// Returns a result indicating that the requested resource has been permanently moved to a new URI, and future references should use the new URI. + /// Corresponds to HTTP status code 308 Permanent Redirect. + /// + public static Result PermanentRedirect(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.PermanentRedirect); } } diff --git a/src/MaksIT.Results/Result.ServerError.cs b/src/MaksIT.Results/Result.ServerError.cs index e9b60d4..249b30e 100644 --- a/src/MaksIT.Results/Result.ServerError.cs +++ b/src/MaksIT.Results/Result.ServerError.cs @@ -1,186 +1,339 @@ using System.Net; -namespace MaksIT.Results { +namespace MaksIT.Results; - public partial class Result { +public partial class Result { - /// - /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. - /// Corresponds to HTTP status code 500 Internal Server Error. - /// - public static Result InternalServerError(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.InternalServerError); - } + /// + /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. + /// Corresponds to HTTP status code 500 Internal Server Error. + /// + public static Result InternalServerError(string message) => + InternalServerError(new List { message }); - /// - /// Returns a result indicating the server does not support the functionality required to fulfill the request. - /// Corresponds to HTTP status code 501 Not Implemented. - /// - public static Result NotImplemented(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.NotImplemented); - } - - /// - /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. - /// Corresponds to HTTP status code 502 Bad Gateway. - /// - public static Result BadGateway(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.BadGateway); - } - - /// - /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. - /// Corresponds to HTTP status code 503 Service Unavailable. - /// - public static Result ServiceUnavailable(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.ServiceUnavailable); - } - - /// - /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. - /// Corresponds to HTTP status code 504 Gateway Timeout. - /// - public static Result GatewayTimeout(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.GatewayTimeout); - } - - /// - /// Returns a result indicating the server does not support the HTTP protocol version used in the request. - /// Corresponds to HTTP status code 505 HTTP Version Not Supported. - /// - public static Result HttpVersionNotSupported(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.HttpVersionNotSupported); - } - - /// - /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. - /// Corresponds to HTTP status code 506 Variant Also Negotiates. - /// - public static Result VariantAlsoNegotiates(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.VariantAlsoNegotiates); - } - - /// - /// Returns a result indicating the server is unable to store the representation needed to complete the request. - /// Corresponds to HTTP status code 507 Insufficient Storage. - /// - public static Result InsufficientStorage(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.InsufficientStorage); - } - - /// - /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. - /// Corresponds to HTTP status code 508 Loop Detected. - /// - public static Result LoopDetected(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.LoopDetected); - } - - /// - /// Returns a result indicating further extensions to the request are required for the server to fulfill it. - /// Corresponds to HTTP status code 510 Not Extended. - /// - public static Result NotExtended(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.NotExtended); - } - - /// - /// Returns a result indicating the client needs to authenticate to gain network access. - /// Corresponds to HTTP status code 511 Network Authentication Required. - /// - public static Result NetworkAuthenticationRequired(params string[] messages) { - return new Result(false, new List(messages), HttpStatusCode.NetworkAuthenticationRequired); - } + /// + /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. + /// Corresponds to HTTP status code 500 Internal Server Error. + /// + public static Result InternalServerError(List messages) { + return new Result(false, messages, HttpStatusCode.InternalServerError); } - public partial class Result : Result { + /// + /// Returns a result indicating the server does not support the functionality required to fulfill the request. + /// Corresponds to HTTP status code 501 Not Implemented. + /// + public static Result NotImplemented(string message) => + NotImplemented(new List { message }); - /// - /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. - /// Corresponds to HTTP status code 500 Internal Server Error. - /// - public static Result InternalServerError(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.InternalServerError); - } + /// + /// Returns a result indicating the server does not support the functionality required to fulfill the request. + /// Corresponds to HTTP status code 501 Not Implemented. + /// + public static Result NotImplemented(List messages) { + return new Result(false, messages, HttpStatusCode.NotImplemented); + } - /// - /// Returns a result indicating the server does not support the functionality required to fulfill the request. - /// Corresponds to HTTP status code 501 Not Implemented. - /// - public static Result NotImplemented(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.NotImplemented); - } + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. + /// Corresponds to HTTP status code 502 Bad Gateway. + /// + public static Result BadGateway(string message) => + BadGateway(new List { message }); - /// - /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. - /// Corresponds to HTTP status code 502 Bad Gateway. - /// - public static Result BadGateway(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.BadGateway); - } + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. + /// Corresponds to HTTP status code 502 Bad Gateway. + /// + public static Result BadGateway(List messages) { + return new Result(false, messages, HttpStatusCode.BadGateway); + } - /// - /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. - /// Corresponds to HTTP status code 503 Service Unavailable. - /// - public static Result ServiceUnavailable(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.ServiceUnavailable); - } + /// + /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. + /// Corresponds to HTTP status code 503 Service Unavailable. + /// + public static Result ServiceUnavailable(string message) => + ServiceUnavailable(new List { message }); - /// - /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. - /// Corresponds to HTTP status code 504 Gateway Timeout. - /// - public static Result GatewayTimeout(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.GatewayTimeout); - } + /// + /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. + /// Corresponds to HTTP status code 503 Service Unavailable. + /// + public static Result ServiceUnavailable(List messages) { + return new Result(false, messages, HttpStatusCode.ServiceUnavailable); + } - /// - /// Returns a result indicating the server does not support the HTTP protocol version used in the request. - /// Corresponds to HTTP status code 505 HTTP Version Not Supported. - /// - public static Result HttpVersionNotSupported(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.HttpVersionNotSupported); - } + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. + /// Corresponds to HTTP status code 504 Gateway Timeout. + /// + public static Result GatewayTimeout(string message) => + GatewayTimeout(new List { message }); - /// - /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. - /// Corresponds to HTTP status code 506 Variant Also Negotiates. - /// - public static Result VariantAlsoNegotiates(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.VariantAlsoNegotiates); - } + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. + /// Corresponds to HTTP status code 504 Gateway Timeout. + /// + public static Result GatewayTimeout(List messages) { + return new Result(false, messages, HttpStatusCode.GatewayTimeout); + } - /// - /// Returns a result indicating the server is unable to store the representation needed to complete the request. - /// Corresponds to HTTP status code 507 Insufficient Storage. - /// - public static Result InsufficientStorage(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.InsufficientStorage); - } + /// + /// Returns a result indicating the server does not support the HTTP protocol version used in the request. + /// Corresponds to HTTP status code 505 HTTP Version Not Supported. + /// + public static Result HttpVersionNotSupported(string message) => + HttpVersionNotSupported(new List { message }); - /// - /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. - /// Corresponds to HTTP status code 508 Loop Detected. - /// - public static Result LoopDetected(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.LoopDetected); - } + /// + /// Returns a result indicating the server does not support the HTTP protocol version used in the request. + /// Corresponds to HTTP status code 505 HTTP Version Not Supported. + /// + public static Result HttpVersionNotSupported(List messages) { + return new Result(false, messages, HttpStatusCode.HttpVersionNotSupported); + } - /// - /// Returns a result indicating further extensions to the request are required for the server to fulfill it. - /// Corresponds to HTTP status code 510 Not Extended. - /// - public static Result NotExtended(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.NotExtended); - } + /// + /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. + /// Corresponds to HTTP status code 506 Variant Also Negotiates. + /// + public static Result VariantAlsoNegotiates(string message) => + VariantAlsoNegotiates(new List { message }); - /// - /// Returns a result indicating the client needs to authenticate to gain network access. - /// Corresponds to HTTP status code 511 Network Authentication Required. - /// - public static Result NetworkAuthenticationRequired(T? value, params string[] messages) { - return new Result(value, false, new List(messages), HttpStatusCode.NetworkAuthenticationRequired); - } + /// + /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. + /// Corresponds to HTTP status code 506 Variant Also Negotiates. + /// + public static Result VariantAlsoNegotiates(List messages) { + return new Result(false, messages, HttpStatusCode.VariantAlsoNegotiates); + } + + /// + /// Returns a result indicating the server is unable to store the representation needed to complete the request. + /// Corresponds to HTTP status code 507 Insufficient Storage. + /// + public static Result InsufficientStorage(string message) => + InsufficientStorage(new List { message }); + + /// + /// Returns a result indicating the server is unable to store the representation needed to complete the request. + /// Corresponds to HTTP status code 507 Insufficient Storage. + /// + public static Result InsufficientStorage(List messages) { + return new Result(false, messages, HttpStatusCode.InsufficientStorage); + } + + /// + /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. + /// Corresponds to HTTP status code 508 Loop Detected. + /// + public static Result LoopDetected(string message) => + LoopDetected(new List { message }); + + /// + /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. + /// Corresponds to HTTP status code 508 Loop Detected. + /// + public static Result LoopDetected(List messages) { + return new Result(false, messages, HttpStatusCode.LoopDetected); + } + + /// + /// Returns a result indicating further extensions to the request are required for the server to fulfill it. + /// Corresponds to HTTP status code 510 Not Extended. + /// + public static Result NotExtended(string message) => + NotExtended(new List { message }); + + /// + /// Returns a result indicating further extensions to the request are required for the server to fulfill it. + /// Corresponds to HTTP status code 510 Not Extended. + /// + public static Result NotExtended(List messages) { + return new Result(false, messages, HttpStatusCode.NotExtended); + } + + /// + /// Returns a result indicating the client needs to authenticate to gain network access. + /// Corresponds to HTTP status code 511 Network Authentication Required. + /// + public static Result NetworkAuthenticationRequired(string message) => + NetworkAuthenticationRequired(new List { message }); + + /// + /// Returns a result indicating the client needs to authenticate to gain network access. + /// Corresponds to HTTP status code 511 Network Authentication Required. + /// + public static Result NetworkAuthenticationRequired(List messages) { + return new Result(false, messages, HttpStatusCode.NetworkAuthenticationRequired); + } +} + +public partial class Result : Result { + + /// + /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. + /// Corresponds to HTTP status code 500 Internal Server Error. + /// + public static Result InternalServerError(T? value, string message) => + InternalServerError(value, new List { message }); + + /// + /// Returns a result indicating the server encountered an unexpected condition that prevented it from fulfilling the request. + /// Corresponds to HTTP status code 500 Internal Server Error. + /// + public static Result InternalServerError(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.InternalServerError); + } + + /// + /// Returns a result indicating the server does not support the functionality required to fulfill the request. + /// Corresponds to HTTP status code 501 Not Implemented. + /// + public static Result NotImplemented(T? value, string message) => + NotImplemented(value, new List { message }); + + /// + /// Returns a result indicating the server does not support the functionality required to fulfill the request. + /// Corresponds to HTTP status code 501 Not Implemented. + /// + public static Result NotImplemented(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.NotImplemented); + } + + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. + /// Corresponds to HTTP status code 502 Bad Gateway. + /// + public static Result BadGateway(T? value, string message) => + BadGateway(value, new List { message }); + + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, received an invalid response from the upstream server. + /// Corresponds to HTTP status code 502 Bad Gateway. + /// + public static Result BadGateway(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.BadGateway); + } + + /// + /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. + /// Corresponds to HTTP status code 503 Service Unavailable. + /// + public static Result ServiceUnavailable(T? value, string message) => + ServiceUnavailable(value, new List { message }); + + /// + /// Returns a result indicating the server is currently unable to handle the request due to temporary overload or maintenance of the server. + /// Corresponds to HTTP status code 503 Service Unavailable. + /// + public static Result ServiceUnavailable(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.ServiceUnavailable); + } + + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. + /// Corresponds to HTTP status code 504 Gateway Timeout. + /// + public static Result GatewayTimeout(T? value, string message) => + GatewayTimeout(value, new List { message }); + + /// + /// Returns a result indicating the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. + /// Corresponds to HTTP status code 504 Gateway Timeout. + /// + public static Result GatewayTimeout(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.GatewayTimeout); + } + + /// + /// Returns a result indicating the server does not support the HTTP protocol version used in the request. + /// Corresponds to HTTP status code 505 HTTP Version Not Supported. + /// + public static Result HttpVersionNotSupported(T? value, string message) => + HttpVersionNotSupported(value, new List { message }); + + /// + /// Returns a result indicating the server does not support the HTTP protocol version used in the request. + /// Corresponds to HTTP status code 505 HTTP Version Not Supported. + /// + public static Result HttpVersionNotSupported(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.HttpVersionNotSupported); + } + + /// + /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. + /// Corresponds to HTTP status code 506 Variant Also Negotiates. + /// + public static Result VariantAlsoNegotiates(T? value, string message) => + VariantAlsoNegotiates(value, new List { message }); + + /// + /// Returns a result indicating the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process. + /// Corresponds to HTTP status code 506 Variant Also Negotiates. + /// + public static Result VariantAlsoNegotiates(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.VariantAlsoNegotiates); + } + + /// + /// Returns a result indicating the server is unable to store the representation needed to complete the request. + /// Corresponds to HTTP status code 507 Insufficient Storage. + /// + public static Result InsufficientStorage(T? value, string message) => + InsufficientStorage(value, new List { message }); + + /// + /// Returns a result indicating the server is unable to store the representation needed to complete the request. + /// Corresponds to HTTP status code 507 Insufficient Storage. + /// + public static Result InsufficientStorage(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.InsufficientStorage); + } + + /// + /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. + /// Corresponds to HTTP status code 508 Loop Detected. + /// + public static Result LoopDetected(T? value, string message) => + LoopDetected(value, new List { message }); + + /// + /// Returns a result indicating the server detected an infinite loop while processing a request with depth: infinity. Usually encountered in WebDAV scenarios. + /// Corresponds to HTTP status code 508 Loop Detected. + /// + public static Result LoopDetected(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.LoopDetected); + } + + /// + /// Returns a result indicating further extensions to the request are required for the server to fulfill it. + /// Corresponds to HTTP status code 510 Not Extended. + /// + public static Result NotExtended(T? value, string message) => + NotExtended(value, new List { message }); + + /// + /// Returns a result indicating further extensions to the request are required for the server to fulfill it. + /// Corresponds to HTTP status code 510 Not Extended. + /// + public static Result NotExtended(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.NotExtended); + } + + /// + /// Returns a result indicating the client needs to authenticate to gain network access. + /// Corresponds to HTTP status code 511 Network Authentication Required. + /// + public static Result NetworkAuthenticationRequired(T? value, string message) => + NetworkAuthenticationRequired(value, new List { message }); + + /// + /// Returns a result indicating the client needs to authenticate to gain network access. + /// Corresponds to HTTP status code 511 Network Authentication Required. + /// + public static Result NetworkAuthenticationRequired(T? value, List messages) { + return new Result(value, false, messages, HttpStatusCode.NetworkAuthenticationRequired); } } diff --git a/src/MaksIT.Results/Result.Succes.cs b/src/MaksIT.Results/Result.Succes.cs index 0180ba3..8880f21 100644 --- a/src/MaksIT.Results/Result.Succes.cs +++ b/src/MaksIT.Results/Result.Succes.cs @@ -1,169 +1,309 @@ using System.Net; -namespace MaksIT.Results { - public partial class Result { +namespace MaksIT.Results; - /// - /// Returns a result indicating the request was successful and the server returned the requested data. - /// Corresponds to HTTP status code 200 OK. - /// - public static Result Ok(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.OK); - } +public partial class Result { - /// - /// Returns a result indicating the request was successful and a new resource was created. - /// Corresponds to HTTP status code 201 Created. - /// - public static Result Created(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.Created); - } + /// + /// Returns a result indicating the request was successful and the server returned the requested data. + /// Corresponds to HTTP status code 200 OK. + /// + public static Result Ok(string message) => + Ok(new List { message }); - /// - /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. - /// Corresponds to HTTP status code 202 Accepted. - /// - public static Result Accepted(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.Accepted); - } - - /// - /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. - /// Corresponds to HTTP status code 203 Non-Authoritative Information. - /// - public static Result NonAuthoritativeInformation(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.NonAuthoritativeInformation); - } - - /// - /// Returns a result indicating the request was successful but there is no content to send in the response. - /// Corresponds to HTTP status code 204 No Content. - /// - public static Result NoContent(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.NoContent); - } - - /// - /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. - /// Corresponds to HTTP status code 205 Reset Content. - /// - public static Result ResetContent(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.ResetContent); - } - - /// - /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. - /// Corresponds to HTTP status code 206 Partial Content. - /// - public static Result PartialContent(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.PartialContent); - } - - /// - /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. - /// Corresponds to HTTP status code 207 Multi-Status. - /// - public static Result MultiStatus(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.MultiStatus); - } - - /// - /// Returns a result indicating the request was successful and the information has already been reported in a previous response. - /// Corresponds to HTTP status code 208 Already Reported. - /// - public static Result AlreadyReported(params string[] messages) { - return new Result(true, new List(messages), HttpStatusCode.AlreadyReported); - } - - /// - /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. - /// Corresponds to HTTP status code 226 IM Used. - /// - public static Result IMUsed(params string[] messages) { - return new Result(true, new List(messages), (HttpStatusCode)226); // 226 is the official status code for IM Used - } + /// + /// Returns a result indicating the request was successful and the server returned the requested data. + /// Corresponds to HTTP status code 200 OK. + /// + public static Result Ok(List messages) { + return new Result(true, messages, HttpStatusCode.OK); } - public partial class Result : Result { - /// - /// Returns a result indicating the request was successful and the server returned the requested data. - /// Corresponds to HTTP status code 200 OK. - /// - public static Result Ok(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.OK); - } + /// + /// Returns a result indicating the request was successful and a new resource was created. + /// Corresponds to HTTP status code 201 Created. + /// + public static Result Created(string message) => + Created(new List { message }); - /// - /// Returns a result indicating the request was successful and a new resource was created. - /// Corresponds to HTTP status code 201 Created. - /// - public static Result Created(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.Created); - } + /// + /// Returns a result indicating the request was successful and a new resource was created. + /// Corresponds to HTTP status code 201 Created. + /// + public static Result Created(List messages) { + return new Result(true, messages, HttpStatusCode.Created); + } - /// - /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. - /// Corresponds to HTTP status code 202 Accepted. - /// - public static Result Accepted(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.Accepted); - } + /// + /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. + /// Corresponds to HTTP status code 202 Accepted. + /// + public static Result Accepted(string message) => + Accepted(new List { message }); - /// - /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. - /// Corresponds to HTTP status code 203 Non-Authoritative Information. - /// - public static Result NonAuthoritativeInformation(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.NonAuthoritativeInformation); - } + /// + /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. + /// Corresponds to HTTP status code 202 Accepted. + /// + public static Result Accepted(List messages) { + return new Result(true, messages, HttpStatusCode.Accepted); + } - /// - /// Returns a result indicating the request was successful but there is no content to send in the response. - /// Corresponds to HTTP status code 204 No Content. - /// - public static Result NoContent(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.NoContent); - } + /// + /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. + /// Corresponds to HTTP status code 203 Non-Authoritative Information. + /// + public static Result NonAuthoritativeInformation(string message) => + NonAuthoritativeInformation(new List { message }); - /// - /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. - /// Corresponds to HTTP status code 205 Reset Content. - /// - public static Result ResetContent(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.ResetContent); - } + /// + /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. + /// Corresponds to HTTP status code 203 Non-Authoritative Information. + /// + public static Result NonAuthoritativeInformation(List messages) { + return new Result(true, messages, HttpStatusCode.NonAuthoritativeInformation); + } - /// - /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. - /// Corresponds to HTTP status code 206 Partial Content. - /// - public static Result PartialContent(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.PartialContent); - } + /// + /// Returns a result indicating the request was successful but there is no content to send in the response. + /// Corresponds to HTTP status code 204 No Content. + /// + public static Result NoContent(string message) => + ResetContent(new List { message }); - /// - /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. - /// Corresponds to HTTP status code 207 Multi-Status. - /// - public static Result MultiStatus(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.MultiStatus); - } + /// + /// Returns a result indicating the request was successful but there is no content to send in the response. + /// Corresponds to HTTP status code 204 No Content. + /// + public static Result NoContent(List messages) { + return new Result(true, messages, HttpStatusCode.NoContent); + } - /// - /// Returns a result indicating the request was successful and the information has already been reported in a previous response. - /// Corresponds to HTTP status code 208 Already Reported. - /// - public static Result AlreadyReported(T? value, params string[] messages) { - return new Result(value, true, new List(messages), HttpStatusCode.AlreadyReported); - } + /// + /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. + /// Corresponds to HTTP status code 205 Reset Content. + /// + public static Result ResetContent(string message) => + ResetContent(new List { message }); - /// - /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. - /// Corresponds to HTTP status code 226 IM Used. - /// - public static Result IMUsed(T? value, params string[] messages) { - return new Result(value, true, new List(messages), (HttpStatusCode)226); // 226 is the official status code for IM Used - } + /// + /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. + /// Corresponds to HTTP status code 205 Reset Content. + /// + public static Result ResetContent(List messages) { + return new Result(true, messages, HttpStatusCode.ResetContent); + } + + /// + /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. + /// Corresponds to HTTP status code 206 Partial Content. + /// + public static Result PartialContent(string message) => + PartialContent(new List { message }); + + /// + /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. + /// Corresponds to HTTP status code 206 Partial Content. + /// + public static Result PartialContent(List messages) { + return new Result(true, messages, HttpStatusCode.PartialContent); + } + + /// + /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. + /// Corresponds to HTTP status code 207 Multi-Status. + /// + public static Result MultiStatus(string message) => + MultiStatus(new List { message }); + + /// + /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. + /// Corresponds to HTTP status code 207 Multi-Status. + /// + public static Result MultiStatus(List messages) { + return new Result(true, messages, HttpStatusCode.MultiStatus); + } + + /// + /// Returns a result indicating the request was successful and the information has already been reported in a previous response. + /// Corresponds to HTTP status code 208 Already Reported. + /// + public static Result AlreadyReported(string message) => + AlreadyReported(new List { message }); + + /// + /// Returns a result indicating the request was successful and the information has already been reported in a previous response. + /// Corresponds to HTTP status code 208 Already Reported. + /// + public static Result AlreadyReported(List messages) { + return new Result(true, messages, HttpStatusCode.AlreadyReported); + } + + /// + /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. + /// Corresponds to HTTP status code 226 IM Used. + /// + public static Result IMUsed(string message) => + IMUsed(new List { message }); + + /// + /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. + /// Corresponds to HTTP status code 226 IM Used. + /// + public static Result IMUsed(List messages) { + return new Result(true, messages, (HttpStatusCode)226); // 226 is the official status code for IM Used + } +} +public partial class Result : Result { + + /// + /// Returns a result indicating the request was successful and the server returned the requested data. + /// Corresponds to HTTP status code 200 OK. + /// + public static Result Ok(T? value, string message) => + Ok(value, new List { message }); + + /// + /// Returns a result indicating the request was successful and the server returned the requested data. + /// Corresponds to HTTP status code 200 OK. + /// + public static Result Ok(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.OK); + } + + /// + /// Returns a result indicating the request was successful and a new resource was created. + /// Corresponds to HTTP status code 201 Created. + /// + public static Result Created(T? value, string message) => + Created(value, new List { message }); + + /// + /// Returns a result indicating the request was successful and a new resource was created. + /// Corresponds to HTTP status code 201 Created. + /// + public static Result Created(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.Created); + } + + /// + /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. + /// Corresponds to HTTP status code 202 Accepted. + /// + public static Result Accepted(T? value, string message) => + Accepted(value, new List { message }); + + /// + /// Returns a result indicating the request has been accepted for processing, but the processing is not yet complete. + /// Corresponds to HTTP status code 202 Accepted. + /// + public static Result Accepted(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.Accepted); + } + + /// + /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. + /// Corresponds to HTTP status code 203 Non-Authoritative Information. + /// + public static Result NonAuthoritativeInformation(T? value, string message) => + NonAuthoritativeInformation(value, new List { message }); + + /// + /// Returns a result indicating the request was successful but the response contains metadata from a source other than the origin server. + /// Corresponds to HTTP status code 203 Non-Authoritative Information. + /// + public static Result NonAuthoritativeInformation(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.NonAuthoritativeInformation); + } + + /// + /// Returns a result indicating the request was successful but there is no content to send in the response. + /// Corresponds to HTTP status code 204 No Content. + /// + public static Result NoContent(T? value, string message) => + NoContent(value, new List { message }); + + /// + /// Returns a result indicating the request was successful but there is no content to send in the response. + /// Corresponds to HTTP status code 204 No Content. + /// + public static Result NoContent(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.NoContent); + } + + /// + /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. + /// Corresponds to HTTP status code 205 Reset Content. + /// + public static Result ResetContent(T? value, string message) => + ResetContent(value, new List { message }); + + /// + /// Returns a result indicating the request was successful, but the user-agent should reset the document view that caused the request. + /// Corresponds to HTTP status code 205 Reset Content. + /// + public static Result ResetContent(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.ResetContent); + } + + /// + /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. + /// Corresponds to HTTP status code 206 Partial Content. + /// + public static Result PartialContent(T? value, string message) => + PartialContent(value, new List { message }); + + /// + /// Returns a result indicating the request was successful and the server is delivering only part of the resource due to a range header sent by the client. + /// Corresponds to HTTP status code 206 Partial Content. + /// + public static Result PartialContent(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.PartialContent); + } + + /// + /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. + /// Corresponds to HTTP status code 207 Multi-Status. + /// + public static Result MultiStatus(T? value, string message) => + MultiStatus(value, new List { message }); + + /// + /// Returns a result indicating the request was successful and the response contains multiple status codes, typically used for WebDAV. + /// Corresponds to HTTP status code 207 Multi-Status. + /// + public static Result MultiStatus(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.MultiStatus); + } + + /// + /// Returns a result indicating the request was successful and the information has already been reported in a previous response. + /// Corresponds to HTTP status code 208 Already Reported. + /// + public static Result AlreadyReported(T? value, string message) => + AlreadyReported(value, new List { message }); + + /// + /// Returns a result indicating the request was successful and the information has already been reported in a previous response. + /// Corresponds to HTTP status code 208 Already Reported. + /// + public static Result AlreadyReported(T? value, List messages) { + return new Result(value, true, messages, HttpStatusCode.AlreadyReported); + } + + /// + /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. + /// Corresponds to HTTP status code 226 IM Used. + /// + public static Result IMUsed(T? value, string message) => + IMUsed(value, new List { message }); + + /// + /// Returns a result indicating the request was successful and the server fulfilled the request for the resource using the delta encoding method. + /// Corresponds to HTTP status code 226 IM Used. + /// + public static Result IMUsed(T? value, List messages) { + return new Result(value, true, messages, (HttpStatusCode)226); // 226 is the official status code for IM Used } } diff --git a/src/MaksIT.Results/Result.cs b/src/MaksIT.Results/Result.cs index 523c26e..8d14638 100644 --- a/src/MaksIT.Results/Result.cs +++ b/src/MaksIT.Results/Result.cs @@ -1,81 +1,88 @@ using Microsoft.AspNetCore.Mvc; using System.Net; -namespace MaksIT.Results { +namespace MaksIT.Results; - public partial class Result { - public bool IsSuccess { get; } - public List Messages { get; } - public HttpStatusCode StatusCode { get; } +public partial class Result { + public bool IsSuccess { get; } + public List Messages { get; } + public HttpStatusCode StatusCode { get; } - protected Result(bool isSuccess, List messages, HttpStatusCode statusCode) { - IsSuccess = isSuccess; - Messages = messages ?? new List(); - StatusCode = statusCode; - } - - /// - /// Converts the current Result{T} to a non-generic Result. - /// - /// A non-generic Result object. - public Result ToResult() { - return new Result(IsSuccess, Messages, StatusCode); - } - - /// - /// Converts the current Result to an IActionResult. - /// - /// IActionResult that represents the HTTP response. - public virtual IActionResult ToActionResult() { - if (IsSuccess) { - return new StatusCodeResult((int)StatusCode); - } - else { - var problemDetails = new ProblemDetails { - Status = (int)StatusCode, - Title = "An error occurred", - Detail = string.Join("; ", Messages), - Instance = null // You can customize the instance URI if needed - }; - return new ObjectResult(problemDetails) { StatusCode = (int)StatusCode }; - } - } + protected Result(bool isSuccess, List messages, HttpStatusCode statusCode) { + IsSuccess = isSuccess; + Messages = messages ?? new List(); + StatusCode = statusCode; } - public partial class Result : Result { - public T? Value { get; } + /// + /// Converts the current Result{T} to a non-generic Result. + /// + /// A non-generic Result object. + public Result ToResult() { + return new Result(IsSuccess, Messages, StatusCode); + } - protected Result(T? value, bool isSuccess, List messages, HttpStatusCode statusCode) - : base(isSuccess, messages, statusCode) { - Value = value; + /// + /// Converts this Result into a Result of another type while retaining the same success status, messages, and status code. + /// + /// The target type for the Result. + /// The new value of type U for the converted Result. + /// A Result of type U. + public Result ToResultOfType(U? value) { + return new Result(value, IsSuccess, Messages, StatusCode); + } + + /// + /// Converts the current Result to an IActionResult. + /// + /// IActionResult that represents the HTTP response. + public virtual IActionResult ToActionResult() { + if (IsSuccess) { + return new StatusCodeResult((int)StatusCode); } - - /// - /// Creates a new by applying a transformation function to the current value. - /// - /// The type of the new value. - /// A function that transforms the current value to the new value, which can be null. - /// A new object containing the transformed value, along with the original success status, messages, and status code. - public Result WithNewValue(Func newValueFunc) { - return new Result(newValueFunc(Value), IsSuccess, Messages, StatusCode); - } - - - - /// - /// Converts the current Result to an IActionResult. - /// - /// IActionResult that represents the HTTP response. - public override IActionResult ToActionResult() { - if (IsSuccess) { - if (Value is not null) { - return new ObjectResult(Value) { StatusCode = (int)StatusCode }; - } - return base.ToActionResult(); - } - else { - return base.ToActionResult(); - } + else { + var problemDetails = new ProblemDetails { + Status = (int)StatusCode, + Title = "An error occurred", + Detail = string.Join("; ", Messages), + Instance = null // You can customize the instance URI if needed + }; + return new ObjectResult(problemDetails) { StatusCode = (int)StatusCode }; + } + } +} + +public partial class Result : Result { + public T? Value { get; } + + public Result(T? value, bool isSuccess, List messages, HttpStatusCode statusCode) + : base(isSuccess, messages, statusCode) { + Value = value; + } + + /// + /// Converts this Result to a Result while retaining success status, messages, and status code. + /// + /// The target type for the Result. + /// A function to transform the current value to a new value of type U. + /// A Result containing the transformed value. + public Result ToResultOfType(Func newValueFunc) { + return new Result(newValueFunc(Value), IsSuccess, Messages, StatusCode); + } + + /// + /// Converts the current Result to an IActionResult. + /// + /// IActionResult that represents the HTTP response. + public override IActionResult ToActionResult() { + if (IsSuccess) { + if (Value is not null) { + return new ObjectResult(Value) { StatusCode = (int)StatusCode }; + } + return base.ToActionResult(); + } + else { + return base.ToActionResult(); } } }