Skip to content

Commit

Permalink
feat: Added endpoint to fetch slug-URL as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Jun 25, 2024
1 parent 13f6b17 commit cf8fa11
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 45 additions & 0 deletions CFLookup/ApiController.cs
Original file line number Diff line number Diff line change
@@ -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<ApiController> _logger;
private readonly ApiClient _cfApiClient;
private readonly IDatabase _redis;

public ApiController(ILogger<ApiController> logger, ApiClient cfApiClient, ConnectionMultiplexer connectionMultiplexer)
{
_logger = logger;
_cfApiClient = cfApiClient;
_redis = connectionMultiplexer.GetDatabase(5);
}

[HttpGet("/{game}/{category}/{slug}.json")]
public async Task<IActionResult> 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();
}
}
}
}
4 changes: 3 additions & 1 deletion CFLookup/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
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;
using System.IO.Compression;

public class Program
{
public static IServiceProvider ServiceProvider { get; set; }
public static IServiceProvider ServiceProvider { get; set; }

Check warning on line 15 in CFLookup/Program.cs

View workflow job for this annotation

GitHub Actions / generate

Non-nullable property 'ServiceProvider' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

private static async Task Main(string[] args)

Check warning on line 17 in CFLookup/Program.cs

View workflow job for this annotation

GitHub Actions / generate

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
Expand Down

0 comments on commit cf8fa11

Please sign in to comment.