93 lines
1.7 KiB
C#
93 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using SoftwareContracts.BindingModels;
|
|
using SoftwareContracts.BusinessLogicsContracts;
|
|
using SoftwareContracts.SearchModels;
|
|
using SoftwareContracts.ViewModels;
|
|
|
|
namespace SoftwareRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class TestController : Controller
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly ITestLogic _test;
|
|
public TestController(ITestLogic test, ILogger<Controller> logger)
|
|
{
|
|
_logger = logger;
|
|
_test = test;
|
|
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<TestViewModel>? GetTestList()
|
|
{
|
|
try
|
|
{
|
|
return _test.ReadList(null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения списка тестов");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public TestViewModel? GetTest(int printedId)
|
|
{
|
|
try
|
|
{
|
|
return _test.ReadElement(new TestSearchModel { Id = printedId });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка получения теста по id={Id}", printedId);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateTest(TestBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_test.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка создания теста");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void UpdateTest(TestBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_test.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка обновления теста");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void DeleteTest(TestBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_test.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Ошибка удаления теста");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|