< Summary

Information
Class: OzonOrdersWeb.WebServices.Orders.OrdersIndexPageDetailsService
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Orders/OrdersIndexPageDetailsService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 39
Coverable lines: 39
Total lines: 111
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
LoadOrderDetailsForPageAsync()0%7280%
PopulateUniqueCountsAsync()100%210%
ApplyDbPagination(...)0%2040%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Orders/OrdersIndexPageDetailsService.cs

#LineLine coverage
 1using OServices.FiltersServices.FilterModels;
 2using OzonDomains.Models;
 3using OzonDomains.Models.AccessControl;
 4using OzonOrdersWeb.ViewModels.OrderViewModels;
 5using Services.DataServices;
 6using Services.OzonWebhookServices;
 7
 8namespace OzonOrdersWeb.WebServices.Orders;
 9
 10public interface IOrdersIndexPageDetailsService
 11{
 12    Task LoadOrderDetailsForPageAsync(
 13        IReadOnlyList<Order> ordersForPage,
 14        AccessProfile? accessProfile,
 15        CancellationToken cancellationToken = default);
 16
 17    Task PopulateUniqueCountsAsync(
 18        OrderPageViewModel<Order, OrderFilterModel> viewModel,
 19        IReadOnlyList<Order> ordersForPage,
 20        bool includeArchived,
 21        CancellationToken cancellationToken = default);
 22
 23    void ApplyDbPagination(
 24        OrderPageViewModel<Order, OrderFilterModel> viewModel,
 25        int totalOrdersCount,
 26        int page,
 27        int pageSize,
 28        bool disablePagination = false);
 29}
 30
 31public sealed class OrdersIndexPageDetailsService : IOrdersIndexPageDetailsService
 32{
 33    private readonly OrdersDataServices _orderServices;
 34    private readonly IOrderReturnInfoService _returnInfoService;
 35    private readonly IOzonPostingCancellationService _cancellationService;
 36    private readonly IOrderSupplierStateInfoService _supplierStateInfoService;
 37    private readonly IOrderProblemInfoService _problemInfoService;
 38
 039    public OrdersIndexPageDetailsService(
 040        OrdersDataServices orderServices,
 041        IOrderReturnInfoService returnInfoService,
 042        IOzonPostingCancellationService cancellationService,
 043        IOrderSupplierStateInfoService supplierStateInfoService,
 044        IOrderProblemInfoService problemInfoService)
 45    {
 046        _orderServices = orderServices;
 047        _returnInfoService = returnInfoService;
 048        _cancellationService = cancellationService;
 049        _supplierStateInfoService = supplierStateInfoService;
 050        _problemInfoService = problemInfoService;
 051    }
 52
 53    public async Task LoadOrderDetailsForPageAsync(
 54        IReadOnlyList<Order> ordersForPage,
 55        AccessProfile? accessProfile,
 56        CancellationToken cancellationToken = default)
 57    {
 058        if (ordersForPage.Count == 0)
 59        {
 060            return;
 61        }
 62
 063        await _orderServices.LoadOrderExtensionsForOrders(ordersForPage.ToList());
 064        await _orderServices.LoadOrderItemsForOrders(ordersForPage.ToList());
 65
 066        if (accessProfile?.AvailableOrderColumns?.Contains("Себестоимость") == true)
 67        {
 068            await _orderServices.LoadExtraExpensesForOrders(ordersForPage.ToList());
 69        }
 70
 071        await _returnInfoService.PopulateForOrdersAsync(ordersForPage, cancellationToken);
 072        await _cancellationService.PopulateLatestForOrdersAsync(ordersForPage, cancellationToken);
 073        await _supplierStateInfoService.PopulateForOrdersAsync(ordersForPage, cancellationToken);
 074        await _problemInfoService.PopulateForOrdersAsync(ordersForPage, cancellationToken);
 075    }
 76
 77    public async Task PopulateUniqueCountsAsync(
 78        OrderPageViewModel<Order, OrderFilterModel> viewModel,
 79        IReadOnlyList<Order> ordersForPage,
 80        bool includeArchived,
 81        CancellationToken cancellationToken = default)
 82    {
 83        _ = cancellationToken;
 084        viewModel.UniqueArticles = await _orderServices.GetArticleCountsForOrdersAsync(
 085            ordersForPage.ToList(), includeArchived);
 086        viewModel.UniqueDeliveryCitys = await _orderServices.GetDeliveryCityCountsForOrdersAsync(
 087            ordersForPage.ToList(), includeArchived);
 088        viewModel.UniqueNumbers = await _orderServices.GetShipmentBaseCountsForOrdersAsync(
 089            ordersForPage.ToList(), includeArchived);
 090    }
 91
 92    public void ApplyDbPagination(
 93        OrderPageViewModel<Order, OrderFilterModel> viewModel,
 94        int totalOrdersCount,
 95        int page,
 96        int pageSize,
 97        bool disablePagination = false)
 98    {
 099        if (totalOrdersCount <= 0)
 100        {
 0101            viewModel.PageNumber = 1;
 0102            viewModel.TotalPages = 1;
 0103            return;
 104        }
 105
 0106        viewModel.PageNumber = page;
 0107        viewModel.TotalPages = disablePagination
 0108            ? 1
 0109            : (int)Math.Ceiling(totalOrdersCount / (double)pageSize);
 0110    }
 111}