From 3cb8c60fd91d19bcc65adec4662c49136ad2fc8f Mon Sep 17 00:00:00 2001 From: ptlthg <24925519+ptlthg@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:43:02 -0600 Subject: [PATCH] Add refresh products route --- EliteAPI/Controllers/ProductController.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/EliteAPI/Controllers/ProductController.cs b/EliteAPI/Controllers/ProductController.cs index 06a3455..9274e70 100644 --- a/EliteAPI/Controllers/ProductController.cs +++ b/EliteAPI/Controllers/ProductController.cs @@ -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; @@ -11,6 +12,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Quartz; using StackExchange.Redis; namespace EliteAPI.Controllers; @@ -23,6 +25,7 @@ public class ProductController( IMonetizationService monetizationService, IConnectionMultiplexer redis, IObjectStorageService objectStorageService, + ISchedulerFactory schedulerFactory, IMapper mapper) : ControllerBase { @@ -81,6 +84,26 @@ public async Task>> GetAllProductsAdmin() .ToListAsync(); } + /// + /// Refresh all products + /// + /// + [Authorize(ApiUserPolicies.Admin)] + [HttpPost] + [Route("/[controller]s/refresh")] + [Route("/v{version:apiVersion}/[controller]s/refresh")] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task>> RefreshProductsAdmin() + { + var db = redis.GetDatabase(); + await db.KeyDeleteAsync("bot:products"); + + var scheduler = await schedulerFactory.GetScheduler(); + await scheduler.TriggerJob(RefreshProductsBackgroundJob.Key); + + return Ok(); + } + /// /// Get a product ///