diff --git a/src/ReC.Domain/Constants/StatusExtensions.cs b/src/ReC.Domain/Constants/StatusExtensions.cs new file mode 100644 index 0000000..06c85df --- /dev/null +++ b/src/ReC.Domain/Constants/StatusExtensions.cs @@ -0,0 +1,32 @@ +using System.Net; + +namespace ReC.Domain.Constants; + +public static class StatusExtensions +{ + public static HttpStatusCode? ToHttpStatusCode(this Status status) + { + int code = (int)status; + + if (Enum.IsDefined(typeof(HttpStatusCode), code)) + { + return (HttpStatusCode)code; + } + + return null; + } + + public static bool IsSuccess(this HttpStatusCode code) + { + int value = (int)code; + return value >= 200 && value <= 299; + } + + public static bool IsSuccess(this Status status) + => status switch + { + Status.QuerySuccess => true, + Status.QueryFailed => false, + _ => status.ToHttpStatusCode() is HttpStatusCode httpStatus && httpStatus.IsSuccess() + }; +} \ No newline at end of file