diff --git a/Hospital/Hospital.sln b/Hospital/Hospital.sln index 5f69030..648b369 100644 --- a/Hospital/Hospital.sln +++ b/Hospital/Hospital.sln @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HospitalDatabaseImplement", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PharmacistApp", "PharmacistApp\PharmacistApp.csproj", "{5CE4060B-0791-4F09-A52D-EF3EFF4EBF03}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalRestApi", "HospitalRestApi\HospitalRestApi.csproj", "{C524A697-427E-40BD-955C-334255D958B7}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HospitalDoctorApp", "HospitalDoctorApp\HospitalDoctorApp.csproj", "{0E3C0346-E31B-401F-8047-CE157D984F33}" EndProject Global @@ -51,6 +53,10 @@ Global {0E3C0346-E31B-401F-8047-CE157D984F33}.Debug|Any CPU.Build.0 = Debug|Any CPU {0E3C0346-E31B-401F-8047-CE157D984F33}.Release|Any CPU.ActiveCfg = Release|Any CPU {0E3C0346-E31B-401F-8047-CE157D984F33}.Release|Any CPU.Build.0 = Release|Any CPU + {C524A697-427E-40BD-955C-334255D958B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C524A697-427E-40BD-955C-334255D958B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C524A697-427E-40BD-955C-334255D958B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C524A697-427E-40BD-955C-334255D958B7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hospital/HospitalRestApi/Controllers/MedicineController.cs b/Hospital/HospitalRestApi/Controllers/MedicineController.cs new file mode 100644 index 0000000..6f49b64 --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/MedicineController.cs @@ -0,0 +1,107 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicContracts; +using HospitalContracts.SearchModels; +using HospitalContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + + +using HospitalDatabaseImplement.Models; + +namespace HospitalRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class MedicineController : Controller + { + private readonly ILogger _logger; + private readonly IMedicineLogic _medicine; + public MedicineController(ILogger logger, IMedicineLogic medicine) + { + _logger = logger; + _medicine = medicine; + } + + [HttpGet] + public Tuple>? GetMedicine(int medicineId) + { + try + { + var elem = _medicine.ReadElement(new MedicineSearchModel { Id = medicineId }); + if (elem == null) + return null; + var res = Tuple.Create(elem, elem.ProcedureMedicines.Select(x => x.Value.AnimalName).ToList()); + res.Item1.MedicineAnimals = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения медикамента по id={Id}", medicineId); + throw; + } + } + [HttpGet] + public List? GetMedicines(int? pharmacistId = null) + { + try + { + List res; + if (!pharmacistId.HasValue) + res = _medicine.ReadList(null); + else + res = _medicine.ReadList(new MedicineSearchModel { PharmacistId = pharmacistId }); + foreach (var medicine in res) + medicine.ProcedureMedicines = null!; + return res; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка медикаментов"); + throw; + } + } + [HttpPost] + public bool CreateMedicine(MedicineBindingModel model) + { + try + { + return _medicine.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось создать медикамент"); + throw; + } + } + + [HttpPost] + public bool UpdateMedicine(bool isConnection, MedicineBindingModel model) + { + try + { + if (!isConnection) + model.ProcedureMedicines = null!; + return _medicine.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить магазин"); + throw; + } + } + + [HttpPost] + public bool DeleteMedicine(MedicineBindingModel model) + { + try + { + return _medicine.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + throw; + } + } + } +} diff --git a/Hospital/HospitalRestApi/Controllers/PharmacistController.cs b/Hospital/HospitalRestApi/Controllers/PharmacistController.cs new file mode 100644 index 0000000..cb51d7f --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/PharmacistController.cs @@ -0,0 +1,67 @@ +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 PharmacistController : Controller + { + private readonly ILogger _logger; + private readonly IPharmacistLogic _logic; + public PharmacistController(IPharmacistLogic logic, ILogger + logger) + { + _logger = logger; + _logic = logic; + } + [HttpGet] + public PharmacistViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new PharmacistSearchModel + { + Login = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + [HttpPost] + public void Register(PharmacistBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + [HttpPost] + public void UpdateData(PharmacistBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + + } +} diff --git a/Hospital/HospitalRestApi/Controllers/WeatherForecastController.cs b/Hospital/HospitalRestApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..d68e80c --- /dev/null +++ b/Hospital/HospitalRestApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace HospitalRestApi.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalRestApi/HospitalRestApi.csproj b/Hospital/HospitalRestApi/HospitalRestApi.csproj new file mode 100644 index 0000000..a2bafdc --- /dev/null +++ b/Hospital/HospitalRestApi/HospitalRestApi.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Hospital/HospitalRestApi/Program.cs b/Hospital/HospitalRestApi/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/Hospital/HospitalRestApi/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Hospital/HospitalRestApi/Properties/launchSettings.json b/Hospital/HospitalRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..5cdbb8b --- /dev/null +++ b/Hospital/HospitalRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:20855", + "sslPort": 44330 + } + }, + "profiles": { + "HospitalRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7092;http://localhost:5092", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Hospital/HospitalRestApi/WeatherForecast.cs b/Hospital/HospitalRestApi/WeatherForecast.cs new file mode 100644 index 0000000..49438f4 --- /dev/null +++ b/Hospital/HospitalRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace HospitalRestApi +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/Hospital/HospitalRestApi/appsettings.Development.json b/Hospital/HospitalRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Hospital/HospitalRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Hospital/HospitalRestApi/appsettings.json b/Hospital/HospitalRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Hospital/HospitalRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}