diff --git a/CFLookup/ApiController.cs b/CFLookup/ApiController.cs new file mode 100644 index 0000000..f3b5ede --- /dev/null +++ b/CFLookup/ApiController.cs @@ -0,0 +1,45 @@ +using CurseForge.APIClient; +using Microsoft.AspNetCore.Mvc; +using StackExchange.Redis; + +namespace CFLookup +{ + [Route("api/[controller]")] + [ApiController] + public class ApiController : ControllerBase + { + private readonly ILogger _logger; + private readonly ApiClient _cfApiClient; + private readonly IDatabase _redis; + + public ApiController(ILogger logger, ApiClient cfApiClient, ConnectionMultiplexer connectionMultiplexer) + { + _logger = logger; + _cfApiClient = cfApiClient; + _redis = connectionMultiplexer.GetDatabase(5); + } + + [HttpGet("/{game}/{category}/{slug}.json")] + public async Task GetSlugProject(string game, string category, string slug) + { + try + { + var gameInfo = await SharedMethods.GetGameInfo(_redis, _cfApiClient); + var categoryInfo = await SharedMethods.GetCategoryInfo(_redis, _cfApiClient, gameInfo, game); + + var searchForSlug = await SharedMethods.SearchForSlug(_redis, _cfApiClient, gameInfo, categoryInfo, game, category, slug); + + if (searchForSlug == null) + { + return NotFound(); + } + + return new JsonResult(searchForSlug); + } + catch + { + return NotFound(); + } + } + } +} diff --git a/CFLookup/Program.cs b/CFLookup/Program.cs index b38143b..41aaf8c 100644 --- a/CFLookup/Program.cs +++ b/CFLookup/Program.cs @@ -1,8 +1,10 @@ using CFLookup; +#if !DEBUG using CFLookup.Jobs; using Hangfire; using Hangfire.Dashboard.BasicAuthorization; using Hangfire.Redis.StackExchange; +#endif using Microsoft.AspNetCore.ResponseCompression; using Microsoft.Data.SqlClient; using StackExchange.Redis; @@ -10,7 +12,7 @@ public class Program { - public static IServiceProvider ServiceProvider { get; set; } + public static IServiceProvider ServiceProvider { get; set; } private static async Task Main(string[] args) {