2023-04-01 22:18:09 +04:00
|
|
|
|
using HardwareShopContracts.BindingModels;
|
|
|
|
|
using HardwareShopContracts.BusinessLogicsContracts;
|
|
|
|
|
using HardwareShopContracts.SearchModels;
|
|
|
|
|
using HardwareShopContracts.ViewModels;
|
2023-04-02 02:24:16 +04:00
|
|
|
|
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
2023-04-01 22:18:09 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace HardwareShopRestApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ClientController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
private readonly IUserLogic _logic;
|
|
|
|
|
|
2023-04-02 02:24:16 +04:00
|
|
|
|
private readonly IPurchaseLogic _purchaseLogic;
|
|
|
|
|
|
|
|
|
|
public ClientController(IUserLogic logic, IPurchaseLogic purchaseLogic, ILogger<ClientController> logger)
|
2023-04-01 22:18:09 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
2023-04-02 02:24:16 +04:00
|
|
|
|
_purchaseLogic = purchaseLogic;
|
2023-04-01 22:18:09 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2023-04-02 02:24:16 +04:00
|
|
|
|
public UserViewModel? Login(string email, string password)
|
2023-04-01 22:18:09 +04:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _logic.ReadElement(new UserSearchModel
|
|
|
|
|
{
|
2023-04-02 02:24:16 +04:00
|
|
|
|
Email = email,
|
2023-04-01 22:18:09 +04:00
|
|
|
|
Password = password
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка входа в систему");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Register(UserBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logic.Create(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка регистрации");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-02 02:24:16 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public List<PurchaseViewModel>? GetPurchases(int userId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return _purchaseLogic.ReadList(new PurchaseSearchModel { UserId = userId });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-01 22:18:09 +04:00
|
|
|
|
}
|
|
|
|
|
}
|