From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/DSACore/Controllers/CommandsController.cs | 56 +++++++++++++++++++++++++++ dsa/DSACore/Controllers/LobbyController.cs | 32 +++++++++++++++ dsa/DSACore/Controllers/TokensController.cs | 25 ++++++++++++ dsa/DSACore/Controllers/ValuesController.cs | 45 +++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 dsa/DSACore/Controllers/CommandsController.cs create mode 100644 dsa/DSACore/Controllers/LobbyController.cs create mode 100644 dsa/DSACore/Controllers/TokensController.cs create mode 100644 dsa/DSACore/Controllers/ValuesController.cs (limited to 'dsa/DSACore/Controllers') diff --git a/dsa/DSACore/Controllers/CommandsController.cs b/dsa/DSACore/Controllers/CommandsController.cs new file mode 100644 index 0000000..b6e0be2 --- /dev/null +++ b/dsa/DSACore/Controllers/CommandsController.cs @@ -0,0 +1,56 @@ +using System; +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("dsa/[controller]")] + public class CommandsController : Controller + { + // GET: api/ + [HttpGet] + public string Get() + { + return "Usage: post the command to execute"; + } + + // GET api//5 + /*[HttpGet("{id}")] + public string Get(int id) + { + return "value"; + }*/ + + // POST api//Felis + [HttpPost] + public string Post([FromBody] Command cmd) + { + try + { + return CommandHandler.ExecuteCommand(cmd).message; + } + catch (Exception e) + { + return $"Ein Fehler ist aufgetreten: \n {e.Message}"; + } + } + +/* + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api//5 + [HttpDelete("{id}")] + public void Delete(int id) + { + }*/ + } +} \ No newline at end of file diff --git a/dsa/DSACore/Controllers/LobbyController.cs b/dsa/DSACore/Controllers/LobbyController.cs new file mode 100644 index 0000000..7890b4f --- /dev/null +++ b/dsa/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/ + [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/dsa/DSACore/Controllers/TokensController.cs b/dsa/DSACore/Controllers/TokensController.cs new file mode 100644 index 0000000..a85cabe --- /dev/null +++ b/dsa/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 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 diff --git a/dsa/DSACore/Controllers/ValuesController.cs b/dsa/DSACore/Controllers/ValuesController.cs new file mode 100644 index 0000000..eb08898 --- /dev/null +++ b/dsa/DSACore/Controllers/ValuesController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace DSACore.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + // GET api/values + [HttpGet] + public ActionResult> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} -- cgit v1.2.3-54-g00ecf