ПРОВЕРЯЮ ЧЕРЕЗ SWAGGER

This commit is contained in:
ujijrujijr 2024-04-28 21:00:55 +04:00
parent ea3aa4bf96
commit 3751080250
15 changed files with 212 additions and 35 deletions

View File

@ -27,7 +27,8 @@ namespace ComputerShopBusinessLogic.BusinessLogics
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
//model.UserId = -1 для swagger, чтобы можно было считать все заказы всех пользователей
var list = (model == null || model.UserId == -1) ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
@ -73,11 +74,6 @@ namespace ComputerShopBusinessLogic.BusinessLogics
public bool Create(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен)
{
_logger.LogWarning("Invalid order status");
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
@ -102,14 +98,6 @@ namespace ComputerShopBusinessLogic.BusinessLogics
_logger.LogWarning("Update operation failed");
return false;
}
//!!!ПРОВЕРИТЬ
//if (model.Status != null & ChangeStatus(model, order.Status))
//{
// ordee.DateCreate[model.DateCreate;
// return true;
//}
//model.Status = order.Status;
//model.Sum = order.Sum;
return true;
}

View File

@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -24,7 +25,8 @@ namespace ComputerShopBusinessLogic.BusinessLogics
public List<RequestViewModel>? ReadList(RequestSearchModel? model)
{
var list = model == null ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model);
//model.UserId = -1 для swagger, чтобы можно было считать все заявки всех пользователей
var list = (model == null || model.UserId == -1) ? _requestStorage.GetFullList() : _requestStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList requests return null list");
@ -73,6 +75,13 @@ namespace ComputerShopBusinessLogic.BusinessLogics
return true;
}
//!!!ПРОВЕРИТЬ
public bool ConnectRequestAssembly(int requestId, int assemblyId)
{
_logger.LogInformation("Connect Assembly {rId} with request {aId}", requestId, assemblyId);
return _requestStorage.ConnectRequestAssembly(requestId, assemblyId);
}
public bool Delete(RequestBindingModel model)
{
CheckModel(model, false);

View File

@ -28,8 +28,8 @@ namespace ComputerShopBusinessLogic.BusinessLogics
//!!!ИЛИ СОЗДАТЬ ОТДЕЛЬНЫЙ МЕТОД ReadListUser
public List<ShipmentViewModel> ReadList(ShipmentSearchModel? model)
{
_logger.LogInformation("ReadList. ShipmentId:{Id}", model?.Id);
var list = model == null ? _shipmentStorage.GetFullList() : _shipmentStorage.GetFilteredList(model);
//model.UserId = -1 для swagger, чтобы можно было считать все партии товаров всех пользователей
var list = (model == null || model.UserId == -1) ? _shipmentStorage.GetFullList() : _shipmentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");

View File

@ -17,5 +17,6 @@ namespace ComputerShopContracts.BusinessLogicContracts
bool Create(RequestBindingModel model);
bool Update(RequestBindingModel model);
bool Delete(RequestBindingModel model);
bool ConnectRequestAssembly(int requestId, int assemblyId);
}
}

View File

@ -12,7 +12,7 @@ namespace ComputerShopContracts.SearchModels
public int? Id { get; set; }
public string? Login { get; set; }
//!!!ПОИСК ПО ПАРОЛЮ НЕ СТАЛ ДОБАВЛЯТЬ, ИБО СТРАННО
public string Password { get; set; }
public string? Email { get; set; }
public UserRole? Role { get; set; }

View File

@ -17,5 +17,6 @@ namespace ComputerShopContracts.StorageContracts
RequestViewModel? Insert(RequestBindingModel model);
RequestViewModel? Update(RequestBindingModel model);
RequestViewModel? Delete(RequestBindingModel model);
bool ConnectRequestAssembly(int requestId, int assemblyId);
}
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -23,7 +24,7 @@ namespace ComputerShopContracts.ViewModels
public int? AssemblyId { get; set; }
//!!!МБ НАДО БУДЕТ ПРИВЯЗЫВАТЬ НАЗВАНИЕ СБОРКИ И Т.Д. ДЛЯ ОТЧЁТОВ
public IAssemblyModel? Assembly { get; set; }
public Dictionary<int, IOrderModel> RequestOrders { get; set; } = new();

View File

@ -148,5 +148,20 @@ namespace ComputerShopDatabaseImplement.Implements
}
return null;
}
//!!!ПРОВЕРИТЬ
public bool ConnectRequestAssembly(int requestId, int assemblyId)
{
using var context = new ComputerShopDatabase();
var request = context.Requests.FirstOrDefault(x => x.Id == requestId);
var assembly = context.Assemblies.FirstOrDefault(x => x.Id == assemblyId);
if (request == null || assembly == null)
{
return false;
}
request.ConnectAssembly(context, assemblyId);
context.SaveChanges();
return true;
}
}
}

View File

@ -36,11 +36,19 @@ namespace ComputerShopDatabaseImplement.Implements
//id, почта и логин уникальны, можно получать по ним
public UserViewModel? GetElement(UserSearchModel model)
{
//!!!МБ ЭТУ ПРОВЕРКУ УБРАТЬ
if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
using var context = new ComputerShopDatabase();
//Поиск пользователя при входе в систему по логину, паролю и его роли (чтобы не могли войти в аккаунты другой роли)
if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password) && model.Role.HasValue)
{
return context.Users.FirstOrDefault(x => x.Login == model.Login && x.Password == model.Password && x.Role == model.Role)?.GetViewModel;
}
//!!!НИЖЕ МБ НЕ НАДО
//Получение по логину (пользователей с таким логином будет 1 или 0)
if (!string.IsNullOrEmpty(model.Login))
{

View File

@ -77,21 +77,32 @@ namespace ComputerShopDatabaseImplement.Models
if (model == null) {
return;
}
if (model.DateRequest != null)
{
DateRequest = model.DateRequest;
}
using var context = new ComputerShopDatabase();
DateRequest = model.DateRequest;
AssemblyId = model.AssemblyId.HasValue ? model.AssemblyId : AssemblyId;
Assembly = model.AssemblyId.HasValue ? context.Assemblies.First(x => x.Id == model.AssemblyId) : Assembly;
ClientFIO = model.ClientFIO;
//if (model.AssemblyId.HasValue && model.AssemblyId > 0)
//{
// AssemblyId = model.AssemblyId;
// Assembly = context.Assemblies.FirstOrDefault(x => x.Id == model.AssemblyId);
//}
if (!string.IsNullOrEmpty(model.ClientFIO))
{
ClientFIO = model.ClientFIO;
}
context.SaveChanges();
}
//!!!МБ ТУТ НЕ ВСЁ НАДО ПРИСВАИВАТЬ
//!!!МБ ТУТ НАДО ПРИСВАИВАТЬ ЗНАЧЕНИЕ Assembly
public RequestViewModel GetViewModel => new()
{
Id = Id,
UserId = UserId,
AssemblyId = AssemblyId,
Assembly = Assembly,
DateRequest = DateRequest,
ClientFIO = ClientFIO
ClientFIO = ClientFIO,
RequestOrders = RequestOrders
};
@ -122,5 +133,12 @@ namespace ComputerShopDatabaseImplement.Models
}
_requestOrders = null;
}
//!!!ПРОВЕРИТЬ
public void ConnectAssembly(ComputerShopDatabase context, int assemblyId)
{
AssemblyId = assemblyId;
Assembly = context.Assemblies.First(x => x.Id == assemblyId);
}
}
}

View File

@ -34,7 +34,7 @@ namespace ComputerShopDatabaseImplement.Models
private Dictionary<int, IOrderModel>? _shipmentOrders = null;
[NotMapped]
public Dictionary<int, IOrderModel>? ShipmentOrders
public Dictionary<int, IOrderModel> ShipmentOrders
{
get
{
@ -58,6 +58,7 @@ namespace ComputerShopDatabaseImplement.Models
{
Id = model.Id,
UserId = model.UserId,
User = context.Users.First(x => x.Id == model.UserId),
ProviderName = model.ProviderName,
DateShipment = model.DateShipment,
Orders = model.ShipmentOrders.Select(x => new ShipmentOrder
@ -69,8 +70,18 @@ namespace ComputerShopDatabaseImplement.Models
//!!!МБ ТУТ КАКИЕ-ТО ДРУГИЕ ПОЛЯ НАДО БУДЕТ ОБНОВЛЯТЬ
public void Update(ShipmentBindingModel model)
{
ProviderName = model.ProviderName;
DateShipment = model.DateShipment;
if (model == null)
{
return;
}
if (!string.IsNullOrEmpty(model.ProviderName))
{
ProviderName = model.ProviderName;
}
if (model.DateShipment != null)
{
DateShipment = model.DateShipment;
}
}
//!!!МБ ТУТ ЕЩЁ ЧТО-ТО ПРИСВАИВАТЬ
public ShipmentViewModel GetViewModel => new()

View File

@ -2,6 +2,7 @@
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using ComputerShopDatabaseImplement.Models;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
@ -36,6 +37,26 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
/// <summary>
/// Получение заказов по id пользователя (полный список, кот. будет выводиться)
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public List<OrderViewModel>? GetOrders(int? userId)
{
try
{
return _logic.ReadList(new OrderSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model)
{

View File

@ -19,6 +19,8 @@ namespace ComputerShopRestApi.Controllers
_logger = logger;
_logic = logic;
}
[HttpGet]
public RequestViewModel? GetRequest(int id)
{
@ -35,6 +37,27 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
/// <summary>
/// Получение заявок по id пользователя (полный список, кот. будет выводиться)
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public List<RequestViewModel>? GetRequests(int userId)
{
try
{
return _logic.ReadList(new RequestSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateRequest(RequestBindingModel model)
{
@ -48,6 +71,23 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
//!!!ПРОВЕРИТЬ
[HttpPost]
public void ConnectRequestAssembly(int requestId, int assemblyId)
{
try
{
_logic.ConnectRequestAssembly(requestId, assemblyId);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка связывания заявки со сборкой");
throw;
}
}
[HttpPost]
public void UpdateRequest(RequestBindingModel model)
{
@ -61,7 +101,10 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
//!!!мб HttpPut
[HttpDelete]
public void DeleteRequest(RequestBindingModel model)
{

View File

@ -21,6 +21,7 @@ namespace ComputerShopRestApi.Controllers
_logic = logic;
}
[HttpGet]
public ShipmentViewModel? GetShipment(int id)
{
@ -37,6 +38,27 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
/// <summary>
/// Получение партий по id пользователя (полный список, кот. будет выводиться)
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public List<ShipmentViewModel>? GetShipments(int userId)
{
try
{
return _logic.ReadList(new ShipmentSearchModel { UserId = userId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateShipment(ShipmentBindingModel model)
{
@ -50,6 +72,7 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
[HttpPost]
public void UpdateShipment(ShipmentBindingModel model)
{
@ -63,7 +86,7 @@ namespace ComputerShopRestApi.Controllers
throw;
}
}
//!!!мб HttpPut
[HttpDelete]
public void DeleteShipment(ShipmentBindingModel model)
{

View File

@ -2,6 +2,7 @@
using ComputerShopContracts.BusinessLogicContracts;
using ComputerShopContracts.SearchModels;
using ComputerShopContracts.ViewModels;
using ComputerShopDataModels.Enums;
using Microsoft.AspNetCore.Mvc;
namespace ComputerShopRestApi.Controllers
@ -18,17 +19,18 @@ namespace ComputerShopRestApi.Controllers
_logic = logic;
_logger = logger;
}
//!!!мб тут нужен пароль
[HttpGet]
public UserViewModel? Login(string login, string password)
public UserViewModel? LoginImplementer(string login, string password)
{
try
{
return _logic.ReadElement(new UserSearchModel
{
Login = login,
Email = login
Password = password,
Role = UserRole.Исполнитель
});
}
catch (Exception ex)
@ -38,11 +40,47 @@ namespace ComputerShopRestApi.Controllers
}
}
[HttpPost]
public void Register(UserBindingModel model)
[HttpGet]
public UserViewModel? LoginGuarantor(string login, string password)
{
try
{
return _logic.ReadElement(new UserSearchModel
{
Login = login,
Password = password,
Role = UserRole.Поручитель
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа в систему");
throw;
}
}
//!!!мб не тут надо присваивать роль
[HttpPost]
public void RegisterImplementer(UserBindingModel model)
{
try
{
model.Role = UserRole.Исполнитель;
_logic.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка регистрации");
throw;
}
}
[HttpPost]
public void RegisterGuarantor(UserBindingModel model)
{
try
{
model.Role = UserRole.Поручитель;
_logic.Create(model);
}
catch (Exception ex)