diff options
author | uzvkl <dennis.kobert@student.kit.edu> | 2019-06-11 23:33:41 +0200 |
---|---|---|
committer | uzvkl <dennis.kobert@student.kit.edu> | 2019-06-11 23:33:41 +0200 |
commit | af74efccf8d21e6151022b71f3cacd3fa83024ee (patch) | |
tree | 20f383065d5cadea36e8d11d4bb3b35eca99f691 /DSACore/Controllers | |
parent | e6181c24124d97f2fbc932b8a68311e625463156 (diff) |
Seperate the Core from dsa gamelogic
Diffstat (limited to 'DSACore/Controllers')
-rw-r--r-- | DSACore/Controllers/CommandsController.cs | 56 | ||||
-rw-r--r-- | DSACore/Controllers/LobbyController.cs | 32 | ||||
-rw-r--r-- | DSACore/Controllers/TokensController.cs | 25 | ||||
-rw-r--r-- | DSACore/Controllers/ValuesController.cs | 45 |
4 files changed, 158 insertions, 0 deletions
diff --git a/DSACore/Controllers/CommandsController.cs b/DSACore/Controllers/CommandsController.cs new file mode 100644 index 0000000..b6e0be2 --- /dev/null +++ b/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/<controller> + [HttpGet] + public string Get() + { + return "Usage: post the command to execute"; + } + + // GET api/<controller>/5 + /*[HttpGet("{id}")] + public string Get(int id) + { + return "value"; + }*/ + + // POST api/<controller>/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/<controller>/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api/<controller>/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + }*/ + } +}
\ 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 diff --git a/DSACore/Controllers/ValuesController.cs b/DSACore/Controllers/ValuesController.cs new file mode 100644 index 0000000..eb08898 --- /dev/null +++ b/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<IEnumerable<string>> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult<string> 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) + { + } + } +} |