feat: basic game query api support

This commit is contained in:
Michael Green
2023-05-29 22:43:59 +10:00
parent a6b0c85ad0
commit 0e70c9f999
2 changed files with 176 additions and 6 deletions

View File

@@ -187,18 +187,30 @@ namespace gaseous_server.Classes.Metadata
switch (subObjectTypeName)
{
case "platformfamily":
objectToStore = new IdentityOrValue<PlatformFamily>(id: (long)(int)dataRow[property.Name]);
case "collection":
objectToStore = new IdentityOrValue<Collection>(id: (long)dataRow[property.Name]);
break;
case "cover":
objectToStore = new IdentityOrValue<Cover>(id: (long)dataRow[property.Name]);
break;
case "franchise":
objectToStore = new IdentityOrValue<Franchise>(id: (long)dataRow[property.Name]);
break;
case "game":
objectToStore = new IdentityOrValue<Game>(id: (long)dataRow[property.Name]);
break;
case "platformfamily":
objectToStore = new IdentityOrValue<PlatformFamily>(id: (long)dataRow[property.Name]);
break;
case "platformlogo":
objectToStore = new IdentityOrValue<PlatformLogo>(id: (long)(int)dataRow[property.Name]);
objectToStore = new IdentityOrValue<PlatformLogo>(id: (long)dataRow[property.Name]);
break;
case "platformversioncompany":
objectToStore = new IdentityOrValue<PlatformVersionCompany>(id: (long)(int)dataRow[property.Name]);
objectToStore = new IdentityOrValue<PlatformVersionCompany>(id: (long)dataRow[property.Name]);
break;
}
if (objectToStore != null)
if (objectToStore != null)
{
property.SetValue(EndpointType, objectToStore);
}
@@ -211,7 +223,46 @@ namespace gaseous_server.Classes.Metadata
switch (subObjectTypeName)
{
case "platformversion":
case "agerating":
objectToStore = new IdentitiesOrValues<AgeRating>(ids: fromJsonObject);
break;
case "alternativename":
objectToStore = new IdentitiesOrValues<AlternativeName>(ids: fromJsonObject);
break;
case "artworks":
objectToStore = new IdentitiesOrValues<Artwork>(ids: fromJsonObject);
break;
case "game":
objectToStore = new IdentitiesOrValues<Game>(ids: fromJsonObject);
break;
case "externalgame":
objectToStore = new IdentitiesOrValues<ExternalGame>(ids: fromJsonObject);
break;
case "franchise":
objectToStore = new IdentitiesOrValues<Franchise>(ids: fromJsonObject);
break;
case "gameengine":
objectToStore = new IdentitiesOrValues<GameEngine>(ids: fromJsonObject);
break;
case "gamemode":
objectToStore = new IdentitiesOrValues<GameMode>(ids: fromJsonObject);
break;
case "gamevideo":
objectToStore = new IdentitiesOrValues<GameVideo>(ids: fromJsonObject);
break;
case "genre":
objectToStore = new IdentitiesOrValues<Genre>(ids: fromJsonObject);
break;
case "involvedcompany":
objectToStore = new IdentitiesOrValues<InvolvedCompany>(ids: fromJsonObject);
break;
case "multiplayermode":
objectToStore = new IdentitiesOrValues<MultiplayerMode>(ids: fromJsonObject);
break;
case "platform":
objectToStore = new IdentitiesOrValues<Platform>(ids: fromJsonObject);
break;
case "platformversion":
objectToStore = new IdentitiesOrValues<PlatformVersion>(ids: fromJsonObject);
break;
case "platformwebsite":
@@ -223,6 +274,21 @@ namespace gaseous_server.Classes.Metadata
case "platformversionreleasedate":
objectToStore = new IdentitiesOrValues<PlatformVersionReleaseDate>(ids: fromJsonObject);
break;
case "playerperspective":
objectToStore = new IdentitiesOrValues<PlayerPerspective>(ids: fromJsonObject);
break;
case "releasedate":
objectToStore = new IdentitiesOrValues<ReleaseDate>(ids: fromJsonObject);
break;
case "screenshot":
objectToStore = new IdentitiesOrValues<Screenshot>(ids: fromJsonObject);
break;
case "theme":
objectToStore = new IdentitiesOrValues<Theme>(ids: fromJsonObject);
break;
case "website":
objectToStore = new IdentitiesOrValues<Website>(ids: fromJsonObject);
break;
}
if (objectToStore != null)

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using gaseous_tools;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace gaseous_server.Controllers
{
[Route("api/v1/[controller]")]
[ApiController]
public class GamesController : ControllerBase
{
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public List<IGDB.Models.Game> Game(string name = "", string platform = "")
{
string whereClause = "";
string havingClause = "";
Dictionary<string, object> whereParams = new Dictionary<string, object>();
List<string> whereClauses = new List<string>();
List<string> havingClauses = new List<string>();
string tempVal = "";
if (name.Length > 0)
{
tempVal = "`name` LIKE @name";
whereParams.Add("@name", "%" + name + "%");
havingClauses.Add(tempVal);
}
if (platform.Length > 0)
{
tempVal = "games_roms.platformid IN (";
string[] platformClauseItems = platform.Split(",");
for (int i = 0; i < platformClauseItems.Length; i++)
{
if (i > 0)
{
tempVal += ", ";
}
string platformLabel = "@platform" + i;
tempVal += platformLabel;
whereParams.Add(platformLabel, platformClauseItems[i]);
}
tempVal += ")";
whereClauses.Add(tempVal);
}
// build where clause
if (whereClauses.Count > 0)
{
whereClause = "WHERE ";
for (int i = 0; i < whereClauses.Count; i++)
{
if (i > 0)
{
whereClause += ", ";
}
whereClause += whereClauses[i];
}
}
// build having clause
if (havingClauses.Count > 0)
{
havingClause = "HAVING ";
for (int i = 0; i < havingClauses.Count; i++)
{
if (i > 0)
{
havingClause += ", ";
}
havingClause += havingClauses[i];
}
}
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT DISTINCT games_roms.gameid AS ROMGameId, game.ageratings, game.aggregatedrating, game.aggregatedratingcount, game.alternativenames, game.artworks, game.bundles, game.category, game.collection, game.cover, game.dlcs, game.expansions, game.externalgames, game.firstreleasedate, game.`follows`, game.franchise, game.franchises, game.gameengines, game.gamemodes, game.genres, game.hypes, game.involvedcompanies, game.keywords, game.multiplayermodes, (CASE WHEN games_roms.gameid = 0 THEN games_roms.`name` ELSE game.`name` END) AS `name`, game.parentgame, game.platforms, game.playerperspectives, game.rating, game.ratingcount, game.releasedates, game.screenshots, game.similargames, game.slug, game.standaloneexpansions, game.`status`, game.storyline, game.summary, game.tags, game.themes, game.totalrating, game.totalratingcount, game.versionparent, game.versiontitle, game.videos, game.websites FROM gaseous.games_roms LEFT JOIN game ON game.id = games_roms.gameid " + whereClause + " " + havingClause + " ORDER BY `name`";
List<IGDB.Models.Game> RetVal = new List<IGDB.Models.Game>();
DataTable dbResponse = db.ExecuteCMD(sql, whereParams);
foreach (DataRow dr in dbResponse.Rows)
{
if ((long)dr["ROMGameId"] == 0)
{
// unknown game
}
else
{
// known game
RetVal.Add(Classes.Metadata.Games.GetGame((long)dr["ROMGameId"], false, false));
}
}
return RetVal;
}
}
}