use enum for compat api status codes

This commit is contained in:
13xforever
2025-05-11 01:17:55 +05:00
parent 973a60c7e2
commit 86d3c4cdc8
6 changed files with 23 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ using NLog;
namespace CompatApiClient;
using ReturnCodeType = Dictionary<int, (bool displayResults, bool overrideAll, bool displayFooter, string info)>;
using ReturnCodeType = Dictionary<CompatApiStatus, (bool displayResults, bool overrideAll, bool displayFooter, string info)>;
public static class ApiConfig
{
@@ -22,12 +22,12 @@ public static class ApiConfig
public static readonly ReturnCodeType ReturnCodes = new()
{
[0] = (true, false, true, "Results successfully retrieved."),
[1] = (false, false, true, "No results."),
[2] = (true, false, true, "No match was found, displaying results for: ***{0}***."),
[-1] = (false, true, false, "{0}: Internal error occurred, please contact Ani and Nicba1010"),
[-2] = (false, true, false, "{0}: API is undergoing maintenance, please try again later."),
[-3] = (false, false, false, "Illegal characters found, please try again with a different search term."),
[CompatApiStatus.Success] = (true, false, true, "Results successfully retrieved."),
[CompatApiStatus.NoResults] = (false, false, true, "No results."),
[CompatApiStatus.NoExactMatch] = (true, false, true, "No match was found, displaying results for: ***{0}***."),
[CompatApiStatus.InternalError] = (false, true, false, "{0}: Internal error occurred, please contact Ani and Nicba1010"),
[CompatApiStatus.Maintenance] = (false, true, false, "{0}: API is undergoing maintenance, please try again later."),
[CompatApiStatus.IllegalQuery] = (false, false, false, "Illegal characters found, please try again with a different search term."),
};
public static readonly List<int> ResultAmount = [25, 50, 100, 200];

View File

@@ -0,0 +1,11 @@
namespace CompatApiClient;
public enum CompatApiStatus: short
{
IllegalQuery = -3,
Maintenance = -2,
InternalError = -1,
Success = 0,
NoResults = 1,
NoExactMatch = 2,
}

View File

@@ -7,7 +7,7 @@ namespace CompatApiClient.POCOs;
public class CompatResult
{
public int ReturnCode;
public CompatApiStatus ReturnCode;
public string SearchTerm;
public Dictionary<string, TitleInfo> Results;

View File

@@ -146,7 +146,7 @@ internal static partial class CompatList
var result = new CompatResult
{
RequestBuilder = requestBuilder,
ReturnCode = 0,
ReturnCode = CompatApiStatus.Success,
SearchTerm = requestBuilder.Search,
Results = matches.ToDictionary(i => i.thumb.ProductCode, i => new TitleInfo
{

View File

@@ -106,7 +106,7 @@ internal static partial class IsTheGamePlayableHandler
var status = await searchCompatListTask.ConfigureAwait(false);
status = status?.Append(localList);
if (status is null
|| status.ReturnCode != 0 && status.ReturnCode != 2
|| status.ReturnCode is not CompatApiStatus.Success and not CompatApiStatus.NoExactMatch
|| status.Results.Count is 0)
return (null, null);

View File

@@ -127,13 +127,13 @@ internal static partial class ProductCodeLookup
var localList = await CompatList.GetLocalCompatResultAsync(requestBuilder).ConfigureAwait(false);
var status = await searchCompatListTask.ConfigureAwait(false);
result = status?.Append(localList);
if (result?.ReturnCode == -2)
if (result?.ReturnCode is CompatApiStatus.Maintenance)
return (
await TitleInfo.Maintenance.AsEmbedAsync(code).ConfigureAwait(false),
result
);
if (result?.ReturnCode == -1)
if (result?.ReturnCode is CompatApiStatus.InternalError)
return (
await TitleInfo.CommunicationError.AsEmbedAsync(code).ConfigureAwait(false),
result