diff options
Diffstat (limited to 'DSACore/Controllers')
-rw-r--r-- | DSACore/Controllers/CommandsController.cs | 17 | ||||
-rw-r--r-- | DSACore/Controllers/LobbyController.cs | 32 | ||||
-rw-r--r-- | DSACore/Controllers/TokensController.cs | 25 |
3 files changed, 64 insertions, 10 deletions
diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs index 5f27f63..b6e0be2 100644 --- a/DSACore/Controllers/CommandsController.cs +++ b/DSACore/Controllers/CommandsController.cs @@ -1,23 +1,21 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using DSACore.Models; using DSACore.Models.Network; +using DSALib.Commands; +using DSALib.Models.Network; using Microsoft.AspNetCore.Mvc; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace DSACore.Controllers { - [Route("api/[controller]")] + [Route("dsa/[controller]")] public class CommandsController : Controller { // GET: api/<controller> [HttpGet] public string Get() { - return "Dies ist die supa dolle Web Api"; + return "Usage: post the command to execute"; } // GET api/<controller>/5 @@ -29,17 +27,16 @@ namespace DSACore.Controllers // POST api/<controller>/Felis [HttpPost] - public string Post([FromBody]Command cmd) + public string Post([FromBody] Command cmd) { try { - return Commands.CommandHandler.ExecuteCommand(cmd).message; + return CommandHandler.ExecuteCommand(cmd).message; } catch (Exception e) { return $"Ein Fehler ist aufgetreten: \n {e.Message}"; } - } /* @@ -56,4 +53,4 @@ namespace DSACore.Controllers { }*/ } -} +}
\ No newline at end of file diff --git a/DSACore/Controllers/LobbyController.cs b/DSACore/Controllers/LobbyController.cs new file mode 100644 index 0000000..7890b4f --- /dev/null +++ b/DSACore/Controllers/LobbyController.cs @@ -0,0 +1,32 @@ +using System; +using DSACore.Models.Network; +using DSALib.Commands; +using DSALib.Models.Network; +using Microsoft.AspNetCore.Mvc; + +namespace DSACore.Controllers +{ + public class ScribbleController : Controller + { + [Route("[controller]")] + // GET: api/<controller> + [HttpGet] + public string Get() + { + return "Usage: get /tokens/{Token}"; + } + + [HttpPost] + public string Post([FromBody] Command cmd) + { + try + { + return CommandHandler.ExecuteCommand(cmd).message; + } + catch (Exception e) + { + return $"Ein Fehler ist aufgetreten: \n {e.Message}"; + } + } + } +}
\ No newline at end of file diff --git a/DSACore/Controllers/TokensController.cs b/DSACore/Controllers/TokensController.cs new file mode 100644 index 0000000..a85cabe --- /dev/null +++ b/DSACore/Controllers/TokensController.cs @@ -0,0 +1,25 @@ +using DSACore.Hubs; +using Microsoft.AspNetCore.Mvc; + +namespace DSACore.Controllers +{ + [Route("lobby/[controller]")] + [ApiController] + public class TokensController : Controller + { + // GET + [HttpGet("{token}")] + public ActionResult<string> Get(string token) + { + if (!int.TryParse(token, out var intToken)) + return BadRequest("The token has to be a 32 bit unsigned integer"); + + if (intToken == 42) return Ok("Scribble"); + + if (!Users.Tokens.Exists(x => x.GetHashCode() == intToken)) return NotFound(); + + var group = Users.Tokens.Find(x => x.GetHashCode() == intToken); + return Ok(group.Group); + } + } +}
\ No newline at end of file |