< Summary

Information
Class: OzonOrdersWeb.WebServices.Orders.Grid.OrdersGridRowHydrator
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Orders/Grid/OrdersGridRowHydrator.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 66
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
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%
HydrateAsync()0%7280%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/WebServices/Orders/Grid/OrdersGridRowHydrator.cs

#LineLine coverage
 1using System.Security.Claims;
 2using Services.DataServices;
 3using Services.LabelServices;
 4
 5namespace OzonOrdersWeb.WebServices.Orders.Grid;
 6
 7public interface IOrdersGridRowHydrator
 8{
 9    /// <summary>
 10    /// Готовые строки грида по списку Id — тем же конвейером, что и блоки списка (детали, этикетки, гейтинг колонок).
 11    /// Недоступные пользователю Id (RLS, профиль доступа) молча отбрасываются.
 12    /// </summary>
 13    Task<List<OrderGridRowDto>> HydrateAsync(IReadOnlyList<int> ids, ClaimsPrincipal principal, CancellationToken cancel
 14}
 15
 16/// <summary>Точечная гидрация строк (дельта автообновления, карточка заказа) — только доступные пользователю заказы.</s
 17public sealed class OrdersGridRowHydrator : IOrdersGridRowHydrator
 18{
 19    private readonly IOrdersIndexQueryService _queryService;
 20    private readonly IOrdersIndexPageDetailsService _pageDetailsService;
 21    private readonly IOrdersGridQueryService _gridQueryService;
 22    private readonly IOrdersGridScopedQuery _scoped;
 23    private readonly ILabelExistenceService _labelExistenceService;
 24
 025    public OrdersGridRowHydrator(
 026        IOrdersIndexQueryService queryService,
 027        IOrdersIndexPageDetailsService pageDetailsService,
 028        IOrdersGridQueryService gridQueryService,
 029        IOrdersGridScopedQuery scoped,
 030        ILabelExistenceService labelExistenceService)
 31    {
 032        _queryService = queryService;
 033        _pageDetailsService = pageDetailsService;
 034        _gridQueryService = gridQueryService;
 035        _scoped = scoped;
 036        _labelExistenceService = labelExistenceService;
 037    }
 38
 39    public async Task<List<OrderGridRowDto>> HydrateAsync(IReadOnlyList<int> ids, ClaimsPrincipal principal, Cancellatio
 40    {
 041        if (ids.Count == 0)
 42        {
 043            return [];
 44        }
 45
 046        var user = await _scoped.ResolveUserAsync(principal);
 047        if (user is null)
 48        {
 049            return [];
 50        }
 51
 52        // RLS: чужие Id отбрасываем до загрузки — карточка и дельта не должны раскрывать недоступные заказы.
 053        var accessible = await _scoped.FilterAccessibleAsync(user, ids, includeArchived: true, cancellationToken);
 054        if (accessible.Count == 0)
 55        {
 056            return [];
 57        }
 58
 059        var allowed = new HashSet<string>(await _gridQueryService.GetAllowedColumnsAsync(principal, cancellationToken), 
 060        var orders = await _queryService.LoadByIdsPreservingOrderAsync(accessible, includeArchived: true);
 061        await _pageDetailsService.LoadOrderDetailsForPageAsync(orders, user.Profile, cancellationToken);
 062        var shipmentNumbers = orders.Select(o => o.ShipmentNumber).Where(n => !string.IsNullOrWhiteSpace(n)).Distinct().
 063        var labels = shipmentNumbers.Count > 0 ? await _labelExistenceService.CheckBatchAsync(shipmentNumbers) : null;
 064        return OrderGridRowMapper.MapBlock(orders, allowed, labels, groupByShipment: false);
 065    }
 66}