-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added endpoint to fetch slug-URL as JSON
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters