From cea23267b8feda81274f99a7e18c2bcdce7c6e55 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Sat, 8 Jul 2023 15:42:55 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20added=20platform=20and=20game=20search?= =?UTF-8?q?=20functionality=20to=20support=20the=20=E2=80=9Cfix=20match?= =?UTF-8?q?=E2=80=9D=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/SearchController.cs | 68 +++++++++++++++++++ gaseous-server/wwwroot/pages/system.html | 3 + 2 files changed, 71 insertions(+) create mode 100644 gaseous-server/Controllers/SearchController.cs diff --git a/gaseous-server/Controllers/SearchController.cs b/gaseous-server/Controllers/SearchController.cs new file mode 100644 index 0000000..aff9151 --- /dev/null +++ b/gaseous-server/Controllers/SearchController.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using gaseous_tools; +using IGDB; +using IGDB.Models; +using Microsoft.AspNetCore.Mvc; +using static gaseous_server.Classes.Metadata.Games; +using static gaseous_tools.Config.ConfigFile; + +namespace gaseous_server.Controllers +{ + [ApiController] + [Route("api/v1/[controller]")] + public class SearchController : Controller + { + private static IGDBClient igdb = new IGDBClient( + // Found in Twitch Developer portal for your app + Config.IGDB.ClientId, + Config.IGDB.Secret + ); + + [HttpGet] + [Route("Platform")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + public async Task SearchPlatform(string SearchString) + { + List RetVal = await _SearchForPlatform(SearchString); + return Ok(RetVal); + } + + private static async Task> _SearchForPlatform(string SearchString) + { + string searchBody = ""; + searchBody += "fields abbreviation,alternative_name,category,checksum,created_at,generation,name,platform_family,platform_logo,slug,summary,updated_at,url,versions,websites; "; + searchBody += "where name ~ *\"" + SearchString + "\"*;"; + + // get Platform metadata + var results = await igdb.QueryAsync(IGDBClient.Endpoints.Platforms, query: searchBody); + + return results.ToList(); + } + + [HttpGet] + [Route("Game")] + [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + public async Task SearchGame(long PlatformId, string SearchString) + { + List RetVal = await _SearchForGame(PlatformId, SearchString); + return Ok(RetVal); + } + + private static async Task> _SearchForGame(long PlatformId, string SearchString) + { + string searchBody = ""; + searchBody += "fields cover,first_release_date,name,platforms,slug; "; + searchBody += "search \"" + SearchString + "\";"; + searchBody += "where platforms = (" + PlatformId + ");"; + + // get Platform metadata + var results = await igdb.QueryAsync(IGDBClient.Endpoints.Games, query: searchBody); + + return results.ToList(); + } + } +} + diff --git a/gaseous-server/wwwroot/pages/system.html b/gaseous-server/wwwroot/pages/system.html index d651cb2..ff4905f 100644 --- a/gaseous-server/wwwroot/pages/system.html +++ b/gaseous-server/wwwroot/pages/system.html @@ -40,6 +40,9 @@ case 'OrganiseLibrary': itemTypeName = "Organise library"; break; + case 'LibraryScan': + itemTypeName = "Library scan"; + break; default: itemTypeName = result[i].itemType; break;