< Summary - Syki

Information
Class: Syki.Back.Features.Adm.GetDomainEvents.GetDomainEventsService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Adm/GetDomainEvents/GetDomainEventsService.cs
Tag: 4_16869239191
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 54
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
Get()0%4260%

File(s)

/home/runner/work/syki/syki/Back/Features/Adm/GetDomainEvents/GetDomainEventsService.cs

#LineLine coverage
 1using Dapper;
 2using Npgsql;
 3
 4namespace Syki.Back.Features.Adm.GetDomainEvents;
 5
 06public class GetDomainEventsService(NpgsqlDataSource dataSource) : IAdmService
 7{
 8    public async Task<List<DomainEventTableOut>> Get(DomainEventTableFilterIn filters)
 9    {
 010        await using var connection = await dataSource.OpenConnectionAsync();
 11
 12        const string sql = @"
 13            SELECT
 14                e.id,
 15                e.type,
 16                e.status,
 17                e.occurred_at,
 18                e.processed_at,
 19                ARRAY_AGG(t.status ORDER BY t.created_at) AS commands
 20            FROM
 21                syki.domain_events e
 22            LEFT JOIN
 23                syki.commands t ON t.event_id = e.id
 24            WHERE
 25                (@Type IS NULL OR e.type = @Type)
 26                    AND
 27                (@Status IS NULL OR e.status = @Status)
 28                    AND
 29                (@InstitutionId IS NULL OR e.institution_id = @InstitutionId)
 30            GROUP BY
 31                e.id
 32            ORDER BY
 33                e.occurred_at DESC
 34        ";
 35
 036        var parameters = new
 037        {
 038            filters.Type,
 039            filters.InstitutionId,
 040            Status = filters.Status?.ToString(),
 041        };
 42
 043        var events = (await connection.QueryAsync<DomainEventTableOut>(sql, parameters)).ToList();
 44
 045        if (filters.Commands != null)
 46        {
 047            events = events.Where(x => x.Commands.Contains(filters.Commands.Value)).ToList();
 48        }
 49
 050        events.ForEach(x => x.Description = x.Type.ToDomainEventDescription());
 51
 052        return events;
 053    }
 54}