From a27ebbf0aef5dbc36f3486307ed25068789e2cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Mon, 4 Dec 2023 17:06:17 +0100 Subject: [PATCH] Implemented HTTP Routing into Controller --- .../DatabaseController.cs | 139 +++++++++++++++--- 1 file changed, 119 insertions(+), 20 deletions(-) diff --git a/WD7UVN_HFT_2023241.Endpoint/DatabaseController.cs b/WD7UVN_HFT_2023241.Endpoint/DatabaseController.cs index c60b7db..d7e3716 100644 --- a/WD7UVN_HFT_2023241.Endpoint/DatabaseController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/DatabaseController.cs @@ -1,10 +1,14 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ApplicationModels; using WD7UVN_HFT_2023241.Logic; +using System.Linq; +using WD7UVN_HFT_2023241.Models; +using System.Collections; namespace WD7UVN_HFT_2023241.Endpoint { [ApiController] - [Route("api/[controller]")] + [Route("api/database")] public class DatabaseController : ControllerBase { public ILogicServices LogicServices { get; set; } @@ -14,29 +18,124 @@ namespace WD7UVN_HFT_2023241.Endpoint this.LogicServices = LogicServices; } - [HttpGet] - public IActionResult Get() + [HttpGet("Employees")] + public IQueryable ReadAllEmployees() { - // Accessing individual query parameters - //string paramValue = HttpContext.Request.Query["tableName"]; - - // Retrieving all query parameters - var queryParams = HttpContext.Request.Query; - - foreach (var param in queryParams) - { - string paramName = param.Key; - string paramVal = param.Value; - - // Perform operations with paramName and paramVal - - } + return LogicServices.CRUDOperations.ReadAllEmployees(); } - [HttpPost] - public IActionResult Post([FromBody] string value) + [HttpGet("Services")] + public IQueryable ReadAllServices() { - return Ok($"Received POST request with value: {value}"); + return LogicServices.CRUDOperations.ReadAllServices(); + } + + [HttpGet("MaintainerTeams")] + public IQueryable ReadAllMaintainerTeams() + { + return LogicServices.CRUDOperations.ReadAllMaintainerTeams(); + } + + [HttpGet("Customer")] + public IQueryable ReadAllCustomers() + { + return LogicServices.CRUDOperations.ReadAllCustomers(); + } + + [HttpGet("MaintainerTeam/{id}")] + public MaintainerTeam ReadMaintainerTeam(int id) + { + return LogicServices.CRUDOperations.ReadMaintainerTeam(id); + } + + [HttpGet("Service/{id}")] + public Service ReadService(int id) + { + return LogicServices.CRUDOperations.ReadService(id); + } + + [HttpGet("Customer/{id}")] + public Customer ReadCustomer(int id) + { + return LogicServices.CRUDOperations.ReadCustomer(id); + } + + [HttpGet("Employee/{id}")] + public Employee ReadEmployee(int id) + { + return LogicServices.CRUDOperations.ReadEmployee(id); + } + + [HttpPut("Employee")] + public void PutEmployee([FromBody] Employee e) + { + LogicServices.CRUDOperations.CreateEmployee(e); + } + + [HttpPut("Customer")] + public void PutCustomer([FromBody] Customer c) + { + LogicServices.CRUDOperations.CreateCustomer(c); + } + + [HttpPut("Service")] + public void PutService([FromBody] Service s) + { + LogicServices.CRUDOperations.CreateService(s); + } + + [HttpPut("MaintainerTeam")] + public void PutMaintainerTeam([FromBody] MaintainerTeam m) + { + LogicServices.CRUDOperations.CreateMaintainerTeam(m); + } + + [HttpPost("Employee")] + public void UpdateEmployee([FromBody] Employee e) + { + LogicServices.CRUDOperations.UpdateEmployee(e); + } + + [HttpPost("Customer")] + public void UpdateCustomer([FromBody] Customer c) + { + LogicServices.CRUDOperations.UpdateCustomer(c); + } + + [HttpPost("Service")] + public void UpdateService([FromBody] Service s) + { + LogicServices.CRUDOperations.UpdateService(s); + } + + [HttpPost("MaintainerTeam")] + public void UpdateMaintainerTeam([FromBody] MaintainerTeam m) + { + LogicServices.CRUDOperations.UpdateMaintainerTeam(m); + } + + [HttpDelete("Employee")] + public void DeleteEmployee([FromBody] int id) + { + LogicServices.CRUDOperations.DeleteEmployee(id); + } + + [HttpDelete("MaintainerTeam")] + public void DeleteMaintainerTeam([FromBody] int id) + { + LogicServices.CRUDOperations.DeleteMaintainerTeam(id); + } + + [HttpDelete("Service")] + public void DeleteService([FromBody] int id) + { + LogicServices.CRUDOperations.DeleteEmployee(id); + } + + [HttpDelete("Customer")] + public void DeleteCustomer([FromBody] int id) + { + LogicServices.CRUDOperations.DeleteEmployee(id); } } }