mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user