From 9922e61b441d52cdd513b6c9b13dfa1fe8e464c2 Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:37:21 +1100 Subject: [PATCH] Deprecate API v1 - API v1.1 is now default (#469) --- .../Controllers/V1.0/AccountController.cs | 2 +- .../V1.0/BackgroundTasksController.cs | 2 +- .../Controllers/V1.0/BiosController.cs | 2 +- .../Controllers/V1.0/CollectionsController.cs | 16 +++---- .../Controllers/V1.0/FilterController.cs | 6 +-- .../Controllers/V1.0/GamesController.cs | 44 ++++++++++--------- .../Controllers/V1.0/LibraryController.cs | 2 +- .../Controllers/V1.0/LogsController.cs | 2 +- .../V1.0/PlatformMapsController.cs | 2 +- .../Controllers/V1.0/PlatformsController.cs | 2 +- .../Controllers/V1.0/RomsController.cs | 2 +- .../Controllers/V1.0/SearchController.cs | 2 +- .../Controllers/V1.0/SignaturesController.cs | 2 +- .../Controllers/V1.0/SystemController.cs | 2 +- .../V1.1/StateManagerController.cs | 2 +- .../Controllers/V1.1/StatisticsController.cs | 4 +- gaseous-server/Program.cs | 14 ++++-- 17 files changed, 59 insertions(+), 49 deletions(-) diff --git a/gaseous-server/Controllers/V1.0/AccountController.cs b/gaseous-server/Controllers/V1.0/AccountController.cs index 92a23f7..e39a30a 100644 --- a/gaseous-server/Controllers/V1.0/AccountController.cs +++ b/gaseous-server/Controllers/V1.0/AccountController.cs @@ -15,7 +15,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] public class AccountController : Controller diff --git a/gaseous-server/Controllers/V1.0/BackgroundTasksController.cs b/gaseous-server/Controllers/V1.0/BackgroundTasksController.cs index 73e4351..1e12fd6 100644 --- a/gaseous-server/Controllers/V1.0/BackgroundTasksController.cs +++ b/gaseous-server/Controllers/V1.0/BackgroundTasksController.cs @@ -10,7 +10,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize(Roles = "Admin,Gamer,Player")] public class BackgroundTasksController : Controller diff --git a/gaseous-server/Controllers/V1.0/BiosController.cs b/gaseous-server/Controllers/V1.0/BiosController.cs index 6dc01f8..05063a7 100644 --- a/gaseous-server/Controllers/V1.0/BiosController.cs +++ b/gaseous-server/Controllers/V1.0/BiosController.cs @@ -12,7 +12,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] public class BiosController : Controller diff --git a/gaseous-server/Controllers/V1.0/CollectionsController.cs b/gaseous-server/Controllers/V1.0/CollectionsController.cs index a5abb8a..e5eacd6 100644 --- a/gaseous-server/Controllers/V1.0/CollectionsController.cs +++ b/gaseous-server/Controllers/V1.0/CollectionsController.cs @@ -14,7 +14,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] public class CollectionsController : Controller @@ -29,7 +29,7 @@ namespace gaseous_server.Controllers _userManager = userManager; _signInManager = signInManager; } - + /// /// Gets all ROM collections /// @@ -145,7 +145,7 @@ namespace gaseous_server.Controllers } catch (Exception ex) { - return NotFound(ex); + return NotFound(ex); } } else @@ -212,7 +212,7 @@ namespace gaseous_server.Controllers public async Task NewCollectionAsync(Classes.Collections.CollectionItem Item) { var user = await _userManager.GetUserAsync(User); - + if (user != null) { try @@ -246,7 +246,7 @@ namespace gaseous_server.Controllers public async Task EditCollection(long CollectionId, Classes.Collections.CollectionItem Item) { var user = await _userManager.GetUserAsync(User); - + if (user != null) { try @@ -277,10 +277,10 @@ namespace gaseous_server.Controllers [Route("{CollectionId}/AlwaysInclude")] [ProducesResponseType(typeof(Classes.Collections.CollectionItem), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task EditCollectionAlwaysInclude(long CollectionId, [FromQuery]bool Rebuild, [FromBody]Collections.CollectionItem.AlwaysIncludeItem Inclusion) + public async Task EditCollectionAlwaysInclude(long CollectionId, [FromQuery] bool Rebuild, [FromBody] Collections.CollectionItem.AlwaysIncludeItem Inclusion) { var user = await _userManager.GetUserAsync(User); - + if (user != null) { try @@ -326,7 +326,7 @@ namespace gaseous_server.Controllers public async Task DeleteCollection(long CollectionId) { var user = await _userManager.GetUserAsync(User); - + if (user != null) { try diff --git a/gaseous-server/Controllers/V1.0/FilterController.cs b/gaseous-server/Controllers/V1.0/FilterController.cs index 30a54b0..d2f7493 100644 --- a/gaseous-server/Controllers/V1.0/FilterController.cs +++ b/gaseous-server/Controllers/V1.0/FilterController.cs @@ -15,7 +15,7 @@ using Asp.Versioning; namespace gaseous_server.Controllers { [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] [ApiController] @@ -23,7 +23,7 @@ namespace gaseous_server.Controllers { private readonly UserManager _userManager; private readonly SignInManager _signInManager; - + public FilterController( UserManager userManager, SignInManager signInManager) @@ -40,7 +40,7 @@ namespace gaseous_server.Controllers public async Task FilterAsync() { var user = await _userManager.GetUserAsync(User); - + return Ok(Filters.Filter(user.SecurityProfile.AgeRestrictionPolicy.MaximumAgeRestriction, user.SecurityProfile.AgeRestrictionPolicy.IncludeUnrated)); } } diff --git a/gaseous-server/Controllers/V1.0/GamesController.cs b/gaseous-server/Controllers/V1.0/GamesController.cs index 2482dcc..12582f1 100644 --- a/gaseous-server/Controllers/V1.0/GamesController.cs +++ b/gaseous-server/Controllers/V1.0/GamesController.cs @@ -22,7 +22,7 @@ using Asp.Versioning; namespace gaseous_server.Controllers { [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] [ApiController] @@ -30,7 +30,7 @@ namespace gaseous_server.Controllers { private readonly UserManager _userManager; private readonly SignInManager _signInManager; - + public GamesController( UserManager userManager, SignInManager signInManager @@ -53,7 +53,7 @@ namespace gaseous_server.Controllers int minrating = -1, int maxrating = -1, bool sortdescending = false) - { + { return Ok(GetGames(name, platform, genre, gamemode, playerperspective, theme, minrating, maxrating, "Adult", true, true, sortdescending)); } @@ -473,14 +473,15 @@ namespace gaseous_server.Controllers try { IGDB.Models.Artwork artworkObject = Artworks.GetArtwork(ArtworkId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), true); - - if (artworkObject != null) { + + if (artworkObject != null) + { //string coverFilePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Artwork", size.ToString(), artworkObject.ImageId + ".jpg"); string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Artwork"); Communications comms = new Communications(); - Task ImgFetch = comms.GetSpecificImageFromServer(basePath, artworkObject.ImageId, size, new List{ Communications.IGDBAPI_ImageSize.original }); + Task ImgFetch = comms.GetSpecificImageFromServer(basePath, artworkObject.ImageId, size, new List { Communications.IGDBAPI_ImageSize.original }); string coverFilePath = ImgFetch.Result; @@ -578,13 +579,14 @@ namespace gaseous_server.Controllers { IGDB.Models.Cover cover = Classes.Metadata.Covers.GetCover(gameObject.Cover.Id, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), false); string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Covers"); - + Communications comms = new Communications(); - Task ImgFetch = comms.GetSpecificImageFromServer(basePath, cover.ImageId, size, new List{ Communications.IGDBAPI_ImageSize.cover_big, Communications.IGDBAPI_ImageSize.original }); + Task ImgFetch = comms.GetSpecificImageFromServer(basePath, cover.ImageId, size, new List { Communications.IGDBAPI_ImageSize.cover_big, Communications.IGDBAPI_ImageSize.original }); string coverFilePath = ImgFetch.Result; - if (System.IO.File.Exists(coverFilePath)) { + if (System.IO.File.Exists(coverFilePath)) + { string filename = cover.ImageId + ".jpg"; string filepath = coverFilePath; byte[] filedata = System.IO.File.ReadAllBytes(filepath); @@ -627,7 +629,7 @@ namespace gaseous_server.Controllers if (gameObject != null) { var user = await _userManager.GetUserAsync(User); - + if (user != null) { Favourites favourites = new Favourites(); @@ -664,7 +666,7 @@ namespace gaseous_server.Controllers if (gameObject != null) { var user = await _userManager.GetUserAsync(User); - + if (user != null) { Favourites favourites = new Favourites(); @@ -796,7 +798,8 @@ namespace gaseous_server.Controllers companyData.Add("company", company); return Ok(companyData); - } else + } + else { return NotFound(); } @@ -895,7 +898,7 @@ namespace gaseous_server.Controllers foreach (long icId in gameObject.ReleaseDates.Ids) { ReleaseDate releaseDate = Classes.Metadata.ReleaseDates.GetReleaseDates(icId); - + rdObjects.Add(releaseDate); } } @@ -923,7 +926,7 @@ namespace gaseous_server.Controllers public async Task GameRomAsync(long GameId, int pageNumber = 0, int pageSize = 0, long PlatformId = -1, string NameSearch = "") { var user = await _userManager.GetUserAsync(User); - + try { Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); @@ -1113,7 +1116,7 @@ namespace gaseous_server.Controllers public async Task GameRomGroupAsync(long GameId, long RomGroupId) { var user = await _userManager.GetUserAsync(User); - + try { Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); @@ -1144,7 +1147,7 @@ namespace gaseous_server.Controllers public async Task GetGameRomGroupAsync(long GameId) { var user = await _userManager.GetUserAsync(User); - + try { Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); @@ -1204,7 +1207,7 @@ namespace gaseous_server.Controllers public async Task GameRomGroupMembersAsync(long GameId, long RomGroupId, [FromBody] List RomIds) { var user = await _userManager.GetUserAsync(User); - + try { Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); @@ -1386,9 +1389,10 @@ namespace gaseous_server.Controllers public async Task GameScreenshot(long GameId, long ScreenshotId) { try - { + { IGDB.Models.Game gameObject = Classes.Metadata.Games.GetGame(GameId, false, false, false); - if (gameObject != null) { + if (gameObject != null) + { IGDB.Models.Screenshot screenshotObject = Screenshots.GetScreenshot(ScreenshotId, Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), false); if (screenshotObject != null) { @@ -1428,7 +1432,7 @@ namespace gaseous_server.Controllers string basePath = Path.Combine(Config.LibraryConfiguration.LibraryMetadataDirectory_Game(gameObject), "Screenshots"); Communications comms = new Communications(); - Task ImgFetch = comms.GetSpecificImageFromServer(basePath, screenshotObject.ImageId, Size, new List{ Communications.IGDBAPI_ImageSize.original }); + Task ImgFetch = comms.GetSpecificImageFromServer(basePath, screenshotObject.ImageId, Size, new List { Communications.IGDBAPI_ImageSize.original }); string coverFilePath = ImgFetch.Result; diff --git a/gaseous-server/Controllers/V1.0/LibraryController.cs b/gaseous-server/Controllers/V1.0/LibraryController.cs index 59211f1..5c10904 100644 --- a/gaseous-server/Controllers/V1.0/LibraryController.cs +++ b/gaseous-server/Controllers/V1.0/LibraryController.cs @@ -11,7 +11,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize(Roles = "Admin")] public class LibraryController : Controller diff --git a/gaseous-server/Controllers/V1.0/LogsController.cs b/gaseous-server/Controllers/V1.0/LogsController.cs index 172bc20..73a94d1 100644 --- a/gaseous-server/Controllers/V1.0/LogsController.cs +++ b/gaseous-server/Controllers/V1.0/LogsController.cs @@ -11,7 +11,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize(Roles = "Admin")] public class LogsController : Controller diff --git a/gaseous-server/Controllers/V1.0/PlatformMapsController.cs b/gaseous-server/Controllers/V1.0/PlatformMapsController.cs index 2e48460..e02997b 100644 --- a/gaseous-server/Controllers/V1.0/PlatformMapsController.cs +++ b/gaseous-server/Controllers/V1.0/PlatformMapsController.cs @@ -19,7 +19,7 @@ using Asp.Versioning; namespace gaseous_server.Controllers { [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [ApiController] [Authorize] diff --git a/gaseous-server/Controllers/V1.0/PlatformsController.cs b/gaseous-server/Controllers/V1.0/PlatformsController.cs index d91236c..31ab4f4 100644 --- a/gaseous-server/Controllers/V1.0/PlatformsController.cs +++ b/gaseous-server/Controllers/V1.0/PlatformsController.cs @@ -18,7 +18,7 @@ using Asp.Versioning; namespace gaseous_server.Controllers { [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] [ApiController] diff --git a/gaseous-server/Controllers/V1.0/RomsController.cs b/gaseous-server/Controllers/V1.0/RomsController.cs index a6fe557..b28b130 100644 --- a/gaseous-server/Controllers/V1.0/RomsController.cs +++ b/gaseous-server/Controllers/V1.0/RomsController.cs @@ -19,7 +19,7 @@ using Asp.Versioning; namespace gaseous_server.Controllers { [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] [ApiController] diff --git a/gaseous-server/Controllers/V1.0/SearchController.cs b/gaseous-server/Controllers/V1.0/SearchController.cs index 6a3e46b..bf746db 100644 --- a/gaseous-server/Controllers/V1.0/SearchController.cs +++ b/gaseous-server/Controllers/V1.0/SearchController.cs @@ -18,7 +18,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] public class SearchController : Controller diff --git a/gaseous-server/Controllers/V1.0/SignaturesController.cs b/gaseous-server/Controllers/V1.0/SignaturesController.cs index 3a87437..44b2749 100644 --- a/gaseous-server/Controllers/V1.0/SignaturesController.cs +++ b/gaseous-server/Controllers/V1.0/SignaturesController.cs @@ -17,7 +17,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]/[action]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] public class SignaturesController : Controller diff --git a/gaseous-server/Controllers/V1.0/SystemController.cs b/gaseous-server/Controllers/V1.0/SystemController.cs index 5abc6f6..c3563d5 100644 --- a/gaseous-server/Controllers/V1.0/SystemController.cs +++ b/gaseous-server/Controllers/V1.0/SystemController.cs @@ -19,7 +19,7 @@ namespace gaseous_server.Controllers { [ApiController] [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [Authorize] public class SystemController : Controller diff --git a/gaseous-server/Controllers/V1.1/StateManagerController.cs b/gaseous-server/Controllers/V1.1/StateManagerController.cs index ba311c9..39c3fe9 100644 --- a/gaseous-server/Controllers/V1.1/StateManagerController.cs +++ b/gaseous-server/Controllers/V1.1/StateManagerController.cs @@ -11,7 +11,7 @@ using System.IO.Compression; namespace gaseous_server.Controllers.v1_1 { [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [ApiController] public class StateManagerController : ControllerBase diff --git a/gaseous-server/Controllers/V1.1/StatisticsController.cs b/gaseous-server/Controllers/V1.1/StatisticsController.cs index 22ac5a2..4395cff 100644 --- a/gaseous-server/Controllers/V1.1/StatisticsController.cs +++ b/gaseous-server/Controllers/V1.1/StatisticsController.cs @@ -9,10 +9,10 @@ using Asp.Versioning; namespace gaseous_server.Controllers.v1_1 { [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("1.0")] + [ApiVersion("1.0", Deprecated = true)] [ApiVersion("1.1")] [ApiController] - public class StatisticsController: ControllerBase + public class StatisticsController : ControllerBase { private readonly UserManager _userManager; private readonly SignInManager _signInManager; diff --git a/gaseous-server/Program.cs b/gaseous-server/Program.cs index 4c8f5b8..37a8c32 100644 --- a/gaseous-server/Program.cs +++ b/gaseous-server/Program.cs @@ -136,7 +136,7 @@ builder.Services.AddControllers(options => }); builder.Services.AddApiVersioning(config => { - config.DefaultApiVersion = new ApiVersion(1, 0); + config.DefaultApiVersion = new ApiVersion(1, 1); config.AssumeDefaultVersionWhenUnspecified = true; config.ReportApiVersions = true; config.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader(), @@ -207,6 +207,9 @@ builder.Services.AddSwaggerGen(options => // using System.Reflection; var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); + + // sort the endpoints + options.OrderActionsBy((apiDesc) => $"{apiDesc.RelativePath}_{apiDesc.HttpMethod}"); } ); builder.Services.AddHostedService(); @@ -271,9 +274,12 @@ app.UseSwaggerUI(options => var descriptions = app.DescribeApiVersions(); foreach (var description in descriptions) { - var url = $"/swagger/{description.GroupName}/swagger.json"; - var name = description.GroupName.ToUpperInvariant(); - options.SwaggerEndpoint(url, name); + if (description.IsDeprecated == false) + { + var url = $"/swagger/{description.GroupName}/swagger.json"; + var name = description.GroupName.ToUpperInvariant(); + options.SwaggerEndpoint(url, name); + } } } );