diff --git a/Hospital/HospitalRestApi/Controllers/DescriptionProcedureController.cs b/Hospital/HospitalRestApi/Controllers/DescriptionProcedureController.cs new file mode 100644 index 0000000..213a8ac --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/DescriptionProcedureController.cs @@ -0,0 +1,99 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class DescriptionProcedureController : Controller + { + + private readonly ILogger _logger; + private readonly IDescriptionProcedureLogic _guidance; + + public DescriptionProcedureController(ILogger logger, + IDescriptionProcedureLogic guidance) + { + _logger = logger; + _guidance = guidance; + } + [HttpGet] + public DescriptionProcedureViewModel GetGuidance(int guidanceId) + { + try + { + var elem = _guidance.ReadElement(new DescriptionProcedureSearchModel { Id = guidanceId }); + return elem; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения рекомендации по id={Id}", guidanceId); + throw; + } + } + [HttpGet] + public List? GetGuidances(int? serviceId = null) + { + try + { + if (!serviceId.HasValue) + return _guidance.ReadList(null); + return _guidance.ReadList(new DescriptionProcedureSearchModel + { + DescriptionProcedureId = serviceId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка рекомендааций услуги id ={ Id}", serviceId); + throw; + } + } + + [HttpPost] + public void CreateGuidance(DescriptionProcedureBindingModel model) + { + try + { + _guidance.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания рекомендации"); + throw; + } + } + + [HttpPost] + public bool UpdateGuidance(DescriptionProcedureBindingModel model) + { + try + { + return _guidance.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить рекомендацию"); + throw; + } + } + + [HttpPost] + public bool DeleteGuidance(DescriptionProcedureBindingModel model) + { + try + { + return _guidance.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления рекомендации"); + throw; + } + } + } +} diff --git a/Hospital/HospitalRestApi/Controllers/ProcedureController.cs b/Hospital/HospitalRestApi/Controllers/ProcedureController.cs new file mode 100644 index 0000000..336de66 --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/ProcedureController.cs @@ -0,0 +1,105 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ProcedureController : Controller + { + + private readonly ILogger _logger; + private readonly IProcedureLogic _service; + public ProcedureController(ILogger logger, IProcedureLogic service) + { + _logger = logger; + _service = service; + } + + [HttpGet] + public Tuple>? GetService(int serviceId) + { + try + { + var elem = _service.ReadElement(new ProcedureSearchModel { Id = serviceId }); + if (elem == null) + return null; + var res = Tuple.Create(elem, elem.ProcedureMedicines.Select(x => x.Value.Name).ToList()); + res.Item1.ProcedureMedicines = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения услуги по id={Id}", serviceId); + throw; + } + } + [HttpGet] + public List GetServices(int? pharmacistId = null) + { + try + { + List res; + if (!pharmacistId.HasValue) + res = _service.ReadList(null); + else + res = _service.ReadList(new ProcedureSearchModel { PharmacistId = pharmacistId }); + foreach (var service in res) + service.ProcedureMedicines = null; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка услуг"); + throw; + } + } + [HttpPost] + public bool CreateService(ProcedureBindingModel model) + { + try + { + return _service.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать услугу"); + throw; + } + } + + [HttpPost] + public bool UpdateService(ProcedureBindingModel model) + { + try + { + return _service.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить услугу"); + throw; + } + } + + [HttpPost] + public bool DeleteService(ProcedureBindingModel model) + { + try + { + return _service.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления услуги"); + throw; + } + } + + + } +}