Multiworld

This commit is contained in:
2025-03-13 21:51:53 -05:00
parent 13042ec841
commit fd2e8190c3
9 changed files with 262 additions and 39 deletions

View File

@@ -4,6 +4,7 @@
using ALttPRandomizer.Settings;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Threading.Tasks;
public class SeedController : Controller {
@@ -32,6 +33,21 @@
}
}
[Route("/multiworld")]
[HttpPost]
public async Task<ActionResult> GenerateMultiworld([FromBody] IList<SeedSettings> settings) {
if (!ModelState.IsValid) {
return BadRequest(ModelState);
}
try {
var id = await this.RandomizeService.RandomizeMultiworld(settings);
var url = string.Format("/multi/{0}", id);
return Accepted(url, id);
} catch (InvalidSettingsException ex) {
return BadRequest(ex.Message);
}
}
[Route("/seed/{id}")]
[HttpGet]
public async Task<ActionResult> GetSeed(string id) {
@@ -50,5 +66,24 @@
this.Logger.LogWarning("Unexpected result from SeedService: {@result}", result);
return StatusCode(500);
}
[Route("/multi/{id}")]
[HttpGet]
public async Task<ActionResult> GetMulti(string id) {
var result = await this.SeedService.GetMulti(id);
if (result.TryGetValue("status", out var responseCode)) {
switch (responseCode) {
case 200:
return Ok(result);
case 404:
return NotFound(result);
case 409:
return Conflict(result);
}
}
this.Logger.LogWarning("Unexpected result from SeedService: {@result}", result);
return StatusCode(500);
}
}
}