Files
2026-07-23 18:21:43 -07:00

79 lines
2.5 KiB
C#

using DeluxeBackend.Models;
using DeluxeBackend.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using static DeluxeBackend.Enums;
namespace DeluxeBackend.Controllers.Api
{
[Route("api/[controller]")]
[ApiController]
public class CampusCardController : ControllerBase
{
private readonly IJwtService jwt;
private readonly ILiteDbService db;
private readonly INotificationService ws;
private readonly DiscordBotService bot;
public CampusCardController(IJwtService _jwt, ILiteDbService _db, INotificationService _ws, DiscordBotService _bot)
{
jwt = _jwt;
db = _db;
ws = _ws;
bot = _bot;
}
[HttpPost("v1/UpdateAndGetSubscription")]
[Authorize(Roles = "gameClient")]
public async Task<IActionResult> UpdateAndGetSubscription()
{
Account? account = await jwt.GetLogin(User);
if (account == null)
{
return NotFound("User not found in database");
}
bool isActive = false;
if (account.DiscordId.HasValue)
{
isActive = await bot.HasUserBoostedGuild(account.DiscordId.Value);
}
if (isActive)
{
return Ok(new
{
CanBuySubscription = false,
PlatformAccountSubscribedPlayerId = 0,
Subscription = new
{
CreatedAt = DateTime.MinValue.ToString("O"),
ExpirationDate = DateTime.MaxValue.ToString("O"),
IsActive = true,
IsAutoRenewing = true,
Level = 0,
ModifiedAt = DateTime.MinValue.ToString("O"),
Period = 0,
PlatformId = "1",
PlatformPurchaseId = "0",
PlatformType = (int)PlatformType.RecNet,
RecNetPlayerId = account.Id,
SubscriptionId = 0
}
});
}
else
{
return Ok(new
{
CanBuySubscription = false,
PlatformAccountSubscribedPlayerId = 0,
Subscription = (string?)null
});
}
}
}
}