From c112adc4d304b7dcb8a445e093ca82c7fc76edc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Wed, 13 Dec 2023 22:04:06 +0100 Subject: [PATCH] Exception handling --- .../Controllers/CustomerController.cs | 27 ++++++++++++++----- .../Controllers/EmployeeController.cs | 27 ++++++++++++++----- .../Controllers/MaintainerTeamController.cs | 27 ++++++++++++++----- .../Controllers/ServiceController.cs | 23 +++++++++++++--- .../Controllers/SubOrdinateController.cs | 12 +++++++-- .../WhoIsResponsibleForServiceController.cs | 13 ++++++--- .../WhoMaintainsServiceController.cs | 12 +++++++-- .../Controllers/WhoUsesServiceController.cs | 12 +++++++-- .../WhoWorksInMaintainerTeamController.cs | 13 +++++++-- 9 files changed, 133 insertions(+), 33 deletions(-) diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/CustomerController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/CustomerController.cs index a1df1b5..50ecf79 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/CustomerController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/CustomerController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using WD7UVN_HFT_2023241.Logic; using System.Linq; using WD7UVN_HFT_2023241.Models; +using System; namespace WD7UVN_HFT_2023241.Endpoint { @@ -17,24 +18,38 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable ReadAllCustomers() + public IQueryable? ReadAllCustomers() { - return LogicServices.CRUDOperations.ReadAllCustomers(); + try + { + return LogicServices.CRUDOperations.ReadAllCustomers(); + } + catch (NullReferenceException) + { + return null; + } } [HttpGet("{id}")] - public Customer ReadCustomer(int id) + public Customer? ReadCustomer(int id) { - return LogicServices.CRUDOperations.ReadCustomer(id); + try + { + return LogicServices.CRUDOperations.ReadCustomer(id); + } + catch (NullReferenceException) + { + return null; + } } -[HttpPut()] + [HttpPut()] public void PutCustomer([FromBody] Customer e) { LogicServices.CRUDOperations.CreateCustomer(e); } -[HttpPost()] + [HttpPost()] public void UpdateCustomer([FromBody] Customer e) { LogicServices.CRUDOperations.UpdateCustomer(e); diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/EmployeeController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/EmployeeController.cs index 9e87735..ff96e00 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/EmployeeController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/EmployeeController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using WD7UVN_HFT_2023241.Logic; using System.Linq; +using System; using WD7UVN_HFT_2023241.Models; namespace WD7UVN_HFT_2023241.Endpoint @@ -17,24 +18,38 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable ReadAllEmployees() + public IQueryable? ReadAllEmployees() { - return LogicServices.CRUDOperations.ReadAllEmployees(); + try + { + return LogicServices.CRUDOperations.ReadAllEmployees(); + } + catch (NullReferenceException) + { + return null; + } } [HttpGet("{id}")] - public Employee ReadEmployee(int id) + public Employee? ReadEmployee(int id) { - return LogicServices.CRUDOperations.ReadEmployee(id); + try + { + return LogicServices.CRUDOperations.ReadEmployee(id); + } + catch (NullReferenceException) + { + return null; + } } -[HttpPut()] + [HttpPut()] public void PutEmployee([FromBody] Employee e) { LogicServices.CRUDOperations.CreateEmployee(e); } -[HttpPost()] + [HttpPost()] public void UpdateEmployee([FromBody] Employee e) { LogicServices.CRUDOperations.UpdateEmployee(e); diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/MaintainerTeamController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/MaintainerTeamController.cs index 85dab59..9bffdfd 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/MaintainerTeamController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/MaintainerTeamController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using WD7UVN_HFT_2023241.Logic; using System.Linq; +using System; using WD7UVN_HFT_2023241.Models; namespace WD7UVN_HFT_2023241.Endpoint @@ -17,24 +18,38 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable ReadAllMaintainerTeams() + public IQueryable? ReadAllMaintainerTeams() { - return LogicServices.CRUDOperations.ReadAllMaintainerTeams(); + try + { + return LogicServices.CRUDOperations.ReadAllMaintainerTeams(); + } + catch (NullReferenceException) + { + return null; + } } [HttpGet("{id}")] - public MaintainerTeam ReadMaintainerTeam(int id) + public MaintainerTeam? ReadMaintainerTeam(int id) { - return LogicServices.CRUDOperations.ReadMaintainerTeam(id); + try + { + return LogicServices.CRUDOperations.ReadMaintainerTeam(id); + } + catch (NullReferenceException) + { + return null; + } } -[HttpPut()] + [HttpPut()] public void PutMaintainerTeam([FromBody] MaintainerTeam e) { LogicServices.CRUDOperations.CreateMaintainerTeam(e); } -[HttpPost()] + [HttpPost()] public void UpdateMaintainerTeam([FromBody] MaintainerTeam e) { LogicServices.CRUDOperations.UpdateMaintainerTeam(e); diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/ServiceController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/ServiceController.cs index 43ea00b..9225b36 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/ServiceController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/ServiceController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using WD7UVN_HFT_2023241.Logic; using System.Linq; +using System; using WD7UVN_HFT_2023241.Models; namespace WD7UVN_HFT_2023241.Endpoint @@ -17,15 +18,29 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable ReadAllServices() + public IQueryable? ReadAllServices() { - return LogicServices.CRUDOperations.ReadAllServices(); + try + { + return LogicServices.CRUDOperations.ReadAllServices(); + } + catch (NullReferenceException) + { + return null; + } } [HttpGet("{id}")] - public Service ReadService(int id) + public Service? ReadService(int id) { - return LogicServices.CRUDOperations.ReadService(id); + try + { + return LogicServices.CRUDOperations.ReadService(id); + } + catch (NullReferenceException) + { + return null; + } } [HttpPut()] diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/SubOrdinateController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/SubOrdinateController.cs index 2261d22..17dce83 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/SubOrdinateController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/SubOrdinateController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using System; using WD7UVN_HFT_2023241.Logic; using System.Linq; using WD7UVN_HFT_2023241.Models; @@ -17,9 +18,16 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable GetSubordinates([FromQuery] int id) + public IQueryable? GetSubordinates([FromQuery] int id) { - return LogicServices.GetSubordinates(id); + try + { + return LogicServices.GetSubordinates(id); + } + catch (NullReferenceException) + { + return null; + } } } } diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoIsResponsibleForServiceController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoIsResponsibleForServiceController.cs index dee2422..d8c34ee 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoIsResponsibleForServiceController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoIsResponsibleForServiceController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; +using System; using WD7UVN_HFT_2023241.Logic; -using System.Linq; using WD7UVN_HFT_2023241.Models; namespace WD7UVN_HFT_2023241.Endpoint @@ -17,9 +17,16 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public Employee WhoIsResponsibleForService([FromQuery] int id) + public Employee? WhoIsResponsibleForService([FromQuery] int id) { - return LogicServices.WhoIsResponsibleForService(id); + try + { + return LogicServices.WhoIsResponsibleForService(id); + } + catch (NullReferenceException) + { + return null; + } } } } diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoMaintainsServiceController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoMaintainsServiceController.cs index 8700352..f393d92 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoMaintainsServiceController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoMaintainsServiceController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using System; using WD7UVN_HFT_2023241.Logic; using System.Linq; using WD7UVN_HFT_2023241.Models; @@ -17,9 +18,16 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable WhoUsesService([FromQuery] int id) + public IQueryable? WhoUsesService([FromQuery] int id) { - return LogicServices.WhoMaintainsService(id); + try + { + return LogicServices.WhoMaintainsService(id); + } + catch (NullReferenceException) + { + return null; + } } } } diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoUsesServiceController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoUsesServiceController.cs index 2c6feb3..772f931 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoUsesServiceController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoUsesServiceController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using WD7UVN_HFT_2023241.Logic; using System.Linq; +using System; using WD7UVN_HFT_2023241.Models; namespace WD7UVN_HFT_2023241.Endpoint @@ -17,9 +18,16 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable WhoUsesService([FromQuery] int id) + public IQueryable? WhoUsesService([FromQuery] int id) { - return LogicServices.WhoUsesService(id); + try + { + return LogicServices.WhoUsesService(id); + } + catch (NullReferenceException) + { + return null; + } } } } diff --git a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoWorksInMaintainerTeamController.cs b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoWorksInMaintainerTeamController.cs index beb464a..7fa6066 100644 --- a/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoWorksInMaintainerTeamController.cs +++ b/WD7UVN_HFT_2023241.Endpoint/Controllers/WhoWorksInMaintainerTeamController.cs @@ -1,7 +1,9 @@ using Microsoft.AspNetCore.Mvc; +using System; using WD7UVN_HFT_2023241.Logic; using System.Linq; using WD7UVN_HFT_2023241.Models; +using Microsoft.AspNetCore.Mvc.Diagnostics; namespace WD7UVN_HFT_2023241.Endpoint { @@ -17,9 +19,16 @@ namespace WD7UVN_HFT_2023241.Endpoint } [HttpGet()] - public IQueryable WhoWorksInMaintainerTeam([FromQuery] int id) + public IQueryable? WhoWorksInMaintainerTeam([FromQuery] int id) { - return LogicServices.WhoWorksInMaintainerTeam(id); + try + { + return LogicServices.WhoWorksInMaintainerTeam(id); + } + catch (NullReferenceException) + { + return null; + } } } }