Skip to content

Commit

Permalink
Add refresh products route
Browse files Browse the repository at this point in the history
  • Loading branch information
ptlthg committed Dec 24, 2024
1 parent 5d64518 commit 3cb8c60
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions EliteAPI/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Web;
using Asp.Versioning;
using AutoMapper;
using EliteAPI.Background.Discord;
using EliteAPI.Data;
using EliteAPI.Models.DTOs.Outgoing;
using EliteAPI.Models.Entities.Accounts;
Expand All @@ -11,6 +12,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Quartz;
using StackExchange.Redis;

namespace EliteAPI.Controllers;
Expand All @@ -23,6 +25,7 @@ public class ProductController(
IMonetizationService monetizationService,
IConnectionMultiplexer redis,
IObjectStorageService objectStorageService,
ISchedulerFactory schedulerFactory,
IMapper mapper)
: ControllerBase
{
Expand Down Expand Up @@ -81,6 +84,26 @@ public async Task<ActionResult<List<ProductDto>>> GetAllProductsAdmin()
.ToListAsync();
}

/// <summary>
/// Refresh all products
/// </summary>
/// <returns></returns>
[Authorize(ApiUserPolicies.Admin)]
[HttpPost]
[Route("/[controller]s/refresh")]
[Route("/v{version:apiVersion}/[controller]s/refresh")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<List<ProductDto>>> RefreshProductsAdmin()
{
var db = redis.GetDatabase();
await db.KeyDeleteAsync("bot:products");

var scheduler = await schedulerFactory.GetScheduler();
await scheduler.TriggerJob(RefreshProductsBackgroundJob.Key);

return Ok();
}

/// <summary>
/// Get a product
/// </summary>
Expand Down

0 comments on commit 3cb8c60

Please sign in to comment.