This commit is contained in:
Michael Green
2025-01-07 12:40:26 +11:00
parent 202c2c0b62
commit 7c327eeb3e
5 changed files with 65 additions and 263 deletions

View File

@@ -41,260 +41,6 @@ namespace gaseous_server.Controllers
_signInManager = signInManager;
}
[MapToApiVersion("1.0")]
[HttpGet]
[ProducesResponseType(typeof(List<gaseous_server.Models.Game>), StatusCodes.Status200OK)]
public async Task<ActionResult> Game(
string name = "",
string platform = "",
string genre = "",
string gamemode = "",
string playerperspective = "",
string theme = "",
int minrating = -1,
int maxrating = -1,
bool sortdescending = false)
{
return Ok(GetGames(name, platform, genre, gamemode, playerperspective, theme, minrating, maxrating, "Adult", true, true, sortdescending));
}
public static List<gaseous_server.Models.Game> GetGames(
string name = "",
string platform = "",
string genre = "",
string gamemode = "",
string playerperspective = "",
string theme = "",
int minrating = -1,
int maxrating = -1,
string ratinggroup = "Adult",
bool includenullrating = true,
bool sortbynamethe = false,
bool sortdescending = false)
{
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 (minrating != -1)
{
string ratingTempMinVal = "totalRating >= @totalMinRating";
whereParams.Add("@totalMinRating", minrating);
havingClauses.Add(ratingTempMinVal);
}
if (maxrating != -1)
{
string ratingTempMaxVal = "totalRating <= @totalMaxRating";
whereParams.Add("@totalMaxRating", maxrating);
havingClauses.Add(ratingTempMaxVal);
}
if (platform.Length > 0)
{
tempVal = "view_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);
}
if (genre.Length > 0)
{
tempVal = "Relation_Game_Genres.GenresId IN (";
string[] genreClauseItems = genre.Split(",");
for (int i = 0; i < genreClauseItems.Length; i++)
{
if (i > 0)
{
tempVal += " AND ";
}
string genreLabel = "@Genre" + i;
tempVal += genreLabel;
whereParams.Add(genreLabel, genreClauseItems[i]);
}
tempVal += ")";
whereClauses.Add(tempVal);
}
if (gamemode.Length > 0)
{
tempVal = "Relation_Game_GameModes.GameModesId IN (";
string[] gameModeClauseItems = gamemode.Split(",");
for (int i = 0; i < gameModeClauseItems.Length; i++)
{
if (i > 0)
{
tempVal += " AND ";
}
string gameModeLabel = "@GameMode" + i;
tempVal += gameModeLabel;
whereParams.Add(gameModeLabel, gameModeClauseItems[i]);
}
tempVal += ")";
whereClauses.Add(tempVal);
}
if (playerperspective.Length > 0)
{
tempVal = "Relation_Game_PlayerPerspectives.PlayerPerspectivesId IN (";
string[] playerPerspectiveClauseItems = playerperspective.Split(",");
for (int i = 0; i < playerPerspectiveClauseItems.Length; i++)
{
if (i > 0)
{
tempVal += " AND ";
}
string playerPerspectiveLabel = "@PlayerPerspective" + i;
tempVal += playerPerspectiveLabel;
whereParams.Add(playerPerspectiveLabel, playerPerspectiveClauseItems[i]);
}
tempVal += ")";
whereClauses.Add(tempVal);
}
if (theme.Length > 0)
{
tempVal = "Relation_Game_Themes.ThemesId IN (";
string[] themeClauseItems = theme.Split(",");
for (int i = 0; i < themeClauseItems.Length; i++)
{
if (i > 0)
{
tempVal += " AND ";
}
string themeLabel = "@Theme" + i;
tempVal += themeLabel;
whereParams.Add(themeLabel, themeClauseItems[i]);
}
tempVal += ")";
whereClauses.Add(tempVal);
}
if (ratinggroup.Length > 0)
{
List<long> AgeClassificationsList = new List<long>();
foreach (string ratingGroup in ratinggroup.Split(','))
{
AgeGroups.AgeRestrictionGroupings ageRestriction = (AgeGroups.AgeRestrictionGroupings)Enum.Parse(typeof(AgeGroups.AgeRestrictionGroupings), ratingGroup);
if (AgeGroups.AgeGroupings.ContainsKey(ageRestriction))
{
List<AgeGroups.AgeGroupItem> ageGroups = AgeGroups.AgeGroupings[ageRestriction];
foreach (AgeGroups.AgeGroupItem ageGroup in ageGroups)
{
AgeClassificationsList.AddRange(ageGroup.AgeGroupItemValues);
}
}
}
if (AgeClassificationsList.Count > 0)
{
tempVal = "(view_AgeRatings.Rating IN (";
for (int i = 0; i < AgeClassificationsList.Count; i++)
{
if (i > 0)
{
tempVal += ", ";
}
string themeLabel = "@Rating" + i;
tempVal += themeLabel;
whereParams.Add(themeLabel, AgeClassificationsList[i]);
}
tempVal += ")";
tempVal += " OR ";
if (includenullrating == true)
{
tempVal += "view_AgeRatings.Rating IS NULL";
}
else
{
tempVal += "view_AgeRatings.Rating IS NOT NULL";
}
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 += " AND ";
}
whereClause += whereClauses[i];
}
}
// build having clause
if (havingClauses.Count > 0)
{
havingClause = "HAVING ";
for (int i = 0; i < havingClauses.Count; i++)
{
if (i > 0)
{
havingClause += " AND ";
}
havingClause += havingClauses[i];
}
}
// order by clause
string orderByField = "Name";
if (sortbynamethe == true)
{
orderByField = "NameThe";
}
string orderByClause = "ORDER BY `" + orderByField + "` ASC";
if (sortdescending == true)
{
orderByClause = "ORDER BY `" + orderByField + "` DESC";
}
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
string sql = "SELECT DISTINCT view_Games_Roms.GameId AS ROMGameId, Game.*, case when Game.`Name` like 'The %' then CONCAT(trim(substr(Game.`Name` from 4)), ', The') else Game.`Name` end as NameThe FROM view_Games_Roms LEFT JOIN Game ON Game.Id = view_Games_Roms.GameId LEFT JOIN Relation_Game_Genres ON Game.Id = Relation_Game_Genres.GameId LEFT JOIN Relation_Game_GameModes ON Game.Id = Relation_Game_GameModes.GameId LEFT JOIN Relation_Game_PlayerPerspectives ON Game.Id = Relation_Game_PlayerPerspectives.GameId LEFT JOIN Relation_Game_Themes ON Game.Id = Relation_Game_Themes.GameId LEFT JOIN (SELECT Relation_Game_AgeRatings.GameId, AgeRating.* FROM Relation_Game_AgeRatings JOIN AgeRating ON Relation_Game_AgeRatings.AgeRatingsId = AgeRating.Id) view_AgeRatings ON Game.Id = view_AgeRatings.GameId " + whereClause + " " + havingClause + " " + orderByClause;
List<gaseous_server.Models.Game> RetVal = new List<gaseous_server.Models.Game>();
DataTable dbResponse = db.ExecuteCMD(sql, whereParams);
foreach (DataRow dr in dbResponse.Rows)
{
//RetVal.Add(Classes.Metadata.Games.GetGame((long)dr["ROMGameId"], false, false));
RetVal.Add(Classes.Metadata.Games.GetGame(dr));
}
return RetVal;
}
[MapToApiVersion("1.0")]
[MapToApiVersion("1.1")]
[HttpGet]
@@ -1046,6 +792,27 @@ namespace gaseous_server.Controllers
}
}
[MapToApiVersion("1.0")]
[MapToApiVersion("1.1")]
[HttpGet]
[Route("{MetadataMapId}/metadata")]
[ProducesResponseType(typeof(List<MetadataMap.MetadataMapItem>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult> GameMetadataSources(long MetadataMapId)
{
try
{
List<MetadataMap.MetadataMapItem> metadataMapItems = Classes.MetadataManagement.GetMetadataMap(MetadataMapId).MetadataMapItems;
// return metadataMapItems after first removing any items where sourceType = "TheGamesDb"
return Ok(metadataMapItems.Where(x => x.SourceType != HasheousClient.Models.MetadataSources.TheGamesDb).ToList());
}
catch
{
return NotFound();
}
}
[MapToApiVersion("1.0")]
[MapToApiVersion("1.1")]
[HttpGet]

View File

@@ -553,8 +553,6 @@ FROM
Favourites ON Game.MetadataMapId = Favourites.GameId AND Favourites.UserId = @userid " + whereClause + " " + havingClause + " " + orderByClause;
List<Games.MinimalGameItem> RetVal = new List<Games.MinimalGameItem>();
Console.WriteLine(sql);
DataTable dbResponse = db.ExecuteCMD(sql, whereParams, new Database.DatabaseMemoryCacheOptions(CacheEnabled: true, ExpirationSeconds: 60));
// get count

View File

@@ -104,12 +104,26 @@
<div class="section-header">Similar Games</div>
<div id="gamesummarysimilarcontent" class="section-body"></div>
</div>
<div id="gamesmetadataprovider" class="section" style="display: none;">
<div id="gamesmetadataprovidercontent" class="section-body">
<table style="width: 100%;">
<tr>
<td style="width: 40px;">
<img src="/images/IGDB_logo.svg" class="metadata-attribution-icon"
id="metadata-attribution-icon" />
</td>
<td>
<span id="metadata-attribution-text">Game data provided by IGDB</span>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- page code -->
<script type="text/javascript">
// setup the page
SetupPage();
</script>
<!-- page code -->
<script type="text/javascript">
// setup the page
SetupPage();
</script>

View File

@@ -16,6 +16,22 @@ function SetupPage() {
// populate games page
gameData = result;
switch (gameData.metadataSource) {
case "IGDB":
let attributionSection = document.getElementById('gamesmetadataprovider');
attributionSection.style.display = 'block';
let attributionIcon = document.getElementById('metadata-attribution-icon');
attributionIcon.setAttribute('src', '/images/IGDB_Logo.svg');
let attributionText = document.getElementById('metadata-attribution-text');
attributionText.innerHTML = 'This game\'s metadata is provided by IGDB. <a href="https://www.igdb.com/games/' + gameData.slug + '" class="romlink" target="_blank" rel="noopener noreferrer">Source Page</a>';
break;
default:
break;
}
// get name
var gameTitleLabel = document.getElementById('gametitle_label');
gameTitleLabel.innerHTML = result.name;
@@ -27,7 +43,7 @@ function SetupPage() {
if (gameData.total_rating_count) {
var criticscorelabel = document.getElementById('gametitle_criticrating_label');
criticscorelabel.innerHTML = '<img src="/images/IGDB_logo.svg" style="filter: invert(100%); height: 13px; margin-bottom: -5px;" /><span style="font-size: 10px;"> User Rating<br />' + "based on " + gameData.total_rating_count + " votes</span>"
criticscorelabel.innerHTML = '<span style="font-size: 10px;"> User Rating<br />' + "based on " + gameData.total_rating_count + " votes</span>"
}
}

View File

@@ -3044,4 +3044,11 @@ button:not(.select2-selection__choice__remove):not(.select2-selection__clear):no
max-width: 160px;
width: 160px;
white-space: normal;
}
.metadata-attribution-icon {
width: 30px;
height: 30px;
margin-right: 5px;
filter: invert(1);
}