поручитель делает рест апи и думает о суициде

This commit is contained in:
antoc0der 2024-04-27 15:49:58 +04:00
parent e2394534a9
commit d0053dbe7b
19 changed files with 707 additions and 12 deletions

View File

@ -0,0 +1,64 @@
using Microsoft.AspNetCore.Mvc;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class DoctorController : Controller
{
private readonly ILogger _logger;
private readonly IDoctorLogic _logic;
public DoctorController(IDoctorLogic logic, ILogger<DoctorController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
public DoctorViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new DoctorSearchModel
{
Login = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
[HttpPost]
public void Register(DoctorBindingModel model)
{
try
{
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void UpdateData(DoctorBindingModel model)
{
try
{
_logic.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
}
}

View File

@ -0,0 +1,95 @@
using Microsoft.AspNetCore.Mvc;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class DrugController : Controller
{
private readonly ILogger _logger;
private readonly IDrugLogic _drug;
public DrugController(ILogger<DrugController> logger, IDrugLogic drug)
{
_logger = logger;
_drug = drug;
}
[HttpGet]
public Tuple<DrugViewModel, List<Tuple<string, int>>>? GetDrug(int drugId)
{
try
{
var elem = _drug.ReadElement(new DrugSearchModel { Id = drugId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.DrugMedications.Select(x => Tuple.Create(x.Value.Item1.MedicationName, x.Value.Item2)).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения услуги по id={Id}", drugId);
throw;
}
}
[HttpGet]
public List<DrugViewModel> GetDrugs(int purchaseId)
{
try
{
return _drug.ReadList(new DrugSearchModel { DoctorId = purchaseId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка услуг");
throw;
}
}
[HttpPost]
public bool CreateDrug(DrugBindingModel model)
{
try
{
return _drug.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать услугу");
throw;
}
}
[HttpPost]
public bool UpdateDrug(DrugBindingModel model)
{
try
{
model.DrugMedications = null!;
return _drug.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить услугу");
throw;
}
}
[HttpPost]
public bool DeleteDrug(DrugBindingModel model)
{
try
{
return _drug.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления услуги");
throw;
}
}
}
}

View File

@ -0,0 +1,92 @@
using Microsoft.AspNetCore.Mvc;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class MedicationController : Controller
{
private readonly ILogger _logger;
private readonly IMedicationLogic _medication;
public MedicationController(ILogger<MedicationController> logger, IMedicationLogic medication)
{
_logger = logger;
_medication = medication;
}
// а нужен ли он нам вообще
[HttpGet]
public Tuple<MedicationViewModel, List<string>>? GetMedication(int medicationId)
{
try
{
var elem = _medication.ReadElement(new MedicationSearchModel { Id = medicationId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.MedicationAnimals.Select(x => x.Value.AnimalName).ToList()); // возврат модели медикамента и всех животных, у которых есть этот медикамент
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения медикамента по id={Id}", medicationId);
throw;
}
}
[HttpGet]
public List<MedicationViewModel> GetMedications(int doctorId)
{
try
{
return _medication.ReadList(new MedicationSearchModel { DoctorId = doctorId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка медикаментов");
throw;
}
}
[HttpPost]
public bool CreateMedication(MedicationBindingModel model)
{
try
{
return _medication.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать медикамент");
throw;
}
}
[HttpPost]
public bool UpdateMedication(MedicationBindingModel model)
{
try
{
return _medication.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить магазин");
throw;
}
}
[HttpPost]
public bool DeleteMedication(MedicationBindingModel model)
{
try
{
return _medication.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления магазина");
throw;
}
}
}
}

View File

@ -0,0 +1,95 @@
using Microsoft.AspNetCore.Mvc;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ServiceController : Controller
{
private readonly ILogger _logger;
private readonly IServiceLogic _service;
public ServiceController(ILogger<ServiceController> logger, IServiceLogic service)
{
_logger = logger;
_service = service;
}
[HttpGet]
public Tuple<ServiceViewModel, List<Tuple<string, int>>>? GetService(int serviceId)
{
try
{
var elem = _service.ReadElement(new ServiceSearchModel { Id = serviceId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.ServiceMedications.Select(x => Tuple.Create(x.Value.Item1.MedicationName, x.Value.Item2)).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения услуги по id={Id}", serviceId);
throw;
}
}
[HttpGet]
public List<ServiceViewModel> GetServices(int doctorId)
{
try
{
return _service.ReadList(new ServiceSearchModel { DoctorId = doctorId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка услуг");
throw;
}
}
[HttpPost]
public bool CreateService(ServiceBindingModel model)
{
try
{
return _service.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать услугу");
throw;
}
}
[HttpPost]
public bool UpdateService(ServiceBindingModel model)
{
try
{
model.ServiceMedications = null!;
return _service.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить услугу");
throw;
}
}
[HttpPost]
public bool DeleteService(ServiceBindingModel model)
{
try
{
return _service.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления услуги");
throw;
}
}
}
}

View File

@ -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();

View File

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:43797",
"sslPort": 44312
}
},
"profiles": {
"VeterinaryRestApi": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7031;http://localhost:5156",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VeterinaryBusinessLogic\VeterinaryBusinessLogic.csproj" />
<ProjectReference Include="..\VeterinaryContracts\VeterinaryContracts.csproj" />
<ProjectReference Include="..\VeterinaryDatabaseImplement\VeterinaryDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,13 @@
namespace VeterinaryRestApi
{
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; }
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -0,0 +1,27 @@
@{
ViewData["Title"] = "CreateMedication";
}
<div class="text-center">
<h2 class="display-4">Создание медикамента</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8">
<input type="text" name="name" id="name" />
</div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8">
<input type="text" name="price" id="price" />
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btn btn-primary" />
</div>
</div>
</form>

View File

@ -0,0 +1,18 @@
@{
ViewData["Title"] = "DeleteMedication";
}
<div class="text-center">
<h2 class="display-4">Удаление медикамента</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Медикамент:</div>
<div class="col-8">
<select id="medication" name="medication" class="form-control" asp-items="@(new SelectList(@ViewBag.Medications, "Id", "MedicationName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4"></div>
<div class="col-8"><input type="submit" value="Удалить" class="btn btn-danger" /></div>
</div>
</form>

View File

@ -0,0 +1,20 @@
@{
ViewData["Title"] = "Enter";
}
<div class="text-center">
<h2 class="display-4">Вход в приложение</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Email:</div>
<div class="col-8"><input type="text" name="login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Вход" class="btn btnprimary" /></div>
</div>
</form>

View File

@ -1,8 +1,56 @@
@{
ViewData["Title"] = "Home Page";
@using VeterinaryContracts.ViewModels
@model List<MedicationViewModel>
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<h1 class="display-4">Медикаменты</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<p>
<a asp-action="CreateMedication">Создать медикамент</a>
<a asp-action="UpdateMedication">Обновить медикамент</a>
<a asp-action="DeleteMedication">Удалить медикамент</a>
</p>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Название
</th>
<th>
Цена
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem =>
item.Id)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.MedicationName)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Price)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -1,6 +1,28 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
@using VeterinaryContracts.ViewModels
<p>Use this page to detail your site's privacy policy.</p>
@model DoctorViewModel
@{
ViewData["Title"] = "Privacy Policy";
}
<div class="text-center">
<h2 class="display-4">Личные данные</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Login:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="fio" value="@Model.DoctorFIO" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,28 @@
@{
ViewData["Title"] = "Register";
}
<div class="text-center">
<h2 class="display-4">Регистрация</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Login:</div>
<div class="col-8"><input type="text" name="login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" /></div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="fio" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Регистрация"
class="btn btn-primary" />
</div>
</div>
</form>

View File

@ -0,0 +1,69 @@
@using VetClinicContracts.ViewModels;
@{
ViewData["Title"] = "UpdateMedicine";
}
<div class="text-center">
<h2 class="display-4">Редактирование медикамента</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Медикамент:</div>
<div class="col-8">
<select id="medicine" name="medicine" class="form-control" asp-items="@(new SelectList(@ViewBag.Medicines, "Id", "MedicineName"))"></select>
</div>
<div class="col-8">
<select id="animal" name="animal" class="form-control" asp-items="@(new SelectList(@ViewBag.Animals, "Id", "AnimalName"))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="name" id="name" class="form-control" /></div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8"><input type="number" id="price" name="price" class="form-control" /></div>
</div>
<table class="table">
<thead>
<tr>
<th>
Животное
</th>
</tr>
</thead>
<tbody id="table-elements">
</tbody>
</table>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
@section Scripts
{
<script>
function check() {
var medicine = $('#medicine').val();
if (medicine) {
$.ajax({
method: "GET",
url: "/Home/GetMedicine",
data: { medicineId: medicine },
success: function (result) {
$('#name').val(result.item1.medicineName);
$('#price').val(result.item1.price);
$('#table-elements').html(result.item2);
}
});
};
}
check();
$('#medicine').on('change', function () {
check();
});
</script>
}

View File

@ -20,10 +20,16 @@
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Index">Медикаменты</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
</ul>
</div>

View File

@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VeterinaryShowOwnerApp", "V
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryShowDoctorApp", "VeterinaryShowDoctorApp\VeterinaryShowDoctorApp.csproj", "{98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VeterinaryRestApi", "VeterinaryRestApi\VeterinaryRestApi.csproj", "{F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -51,6 +53,10 @@ Global
{98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98C3D76D-BEC8-4DEC-B79A-FC73C31BFE52}.Release|Any CPU.Build.0 = Release|Any CPU
{F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7EEDC4C-ECE3-438E-9A20-2AFF2B752136}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE