Refactor endpoint services to accept narrow inputs

This commit is contained in:
2026-02-07 02:17:01 +01:00
parent 5b06e279f3
commit c765dd322b
10 changed files with 179 additions and 102 deletions

View File

@@ -1,27 +1,25 @@
using GameList.Contracts;
namespace GameList.Endpoints;
internal static class SuggestionValidator
{
public static async Task<string?> ValidateAsync(SuggestionRequest request, IHttpClientFactory httpFactory)
public static async Task<string?> ValidateAsync(SuggestionInput input, IHttpClientFactory httpFactory)
{
if (string.IsNullOrWhiteSpace(request.Name) || request.Name.Length > 100)
if (string.IsNullOrWhiteSpace(input.Name) || input.Name.Length > 100)
return "Name is required and must be <= 100 characters.";
if (!EndpointHelpers.IsValidImageUrl(request.ScreenshotUrl))
if (!EndpointHelpers.IsValidImageUrl(input.ScreenshotUrl))
return "Screenshot URL must be http(s) and end with an image file extension.";
if (!await EndpointHelpers.IsReachableImageAsync(request.ScreenshotUrl, httpFactory))
if (!await EndpointHelpers.IsReachableImageAsync(input.ScreenshotUrl, httpFactory))
return "Screenshot URL could not be validated as an image. Use a public image link (http/https, no redirects, max 5 MB).";
if (!EndpointHelpers.IsValidHttpUrl(request.GameUrl))
if (!EndpointHelpers.IsValidHttpUrl(input.GameUrl))
return "Game URL must be http or https.";
if (!EndpointHelpers.IsValidHttpUrl(request.YoutubeUrl))
if (!EndpointHelpers.IsValidHttpUrl(input.YoutubeUrl))
return "YouTube URL must be http or https.";
return ValidatePlayers(request.MinPlayers, request.MaxPlayers);
return ValidatePlayers(input.MinPlayers, input.MaxPlayers);
}
private static string? ValidatePlayers(int? minPlayers, int? maxPlayers)