Radicade Public Code

This commit is contained in:
JogmansonReal
2026-10-16 23:33:13 -07:00
commit 55175acdf6
832 changed files with 363261 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System.Text.Json;
using RadicadeServer.DB;
using RadicadeServer.Extensions;
using RadicadeServer.Utils;
namespace RadicadeServer.API.Progression.Challenges.V2;
[Route("api/challenge/v2")]
[Route("econ/api/challenge/v2")]
[Authorize]
public class ChallengeV2(RecDBContext db) : Controller
{
[HttpGet("getCurrent")]
public async Task<IActionResult> GetCurrent()
{
var playerId = User.GetUserId();
if (playerId == null) return Unauthorized();
return Ok(await WeeklyChallenges.GetAsync(db, playerId.Value, DateTime.UtcNow));
}
[HttpPost("updateProgress")]
[RequestSizeLimit(32768)]
public async Task<IActionResult> UpdateProgress()
{
var playerId = User.GetUserId();
if (playerId == null) return Unauthorized();
var fields = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
try
{
if (Request.HasFormContentType)
foreach (var field in await Request.ReadFormAsync()) fields[field.Key] = field.Value.ToString();
else
{
using var json = await JsonDocument.ParseAsync(Request.Body);
if (json.RootElement.ValueKind != JsonValueKind.Object) return BadRequest();
foreach (var field in json.RootElement.EnumerateObject()) fields[field.Name] = field.Value.ToString();
}
}
catch (Exception ex) when (ex is JsonException or InvalidDataException) { return BadRequest(); }
if (!fields.TryGetValue("ChallengeMapId", out var mapRaw) || !int.TryParse(mapRaw, out var mapId)
|| !fields.TryGetValue("ChallengeId", out var idRaw) || !int.TryParse(idRaw, out var challengeId)
|| !fields.TryGetValue("Complete", out var completeRaw) || !bool.TryParse(completeRaw, out var complete)
|| !fields.TryGetValue("Config", out var config)) return BadRequest();
var error = await WeeklyChallenges.UpdateAsync(db, playerId.Value, mapId, challengeId, config, complete, DateTime.UtcNow);
if (error == "stale_challenge_map") return Conflict(new { error });
return error == null ? Ok() : BadRequest(new { error });
}
}