< Summary - Estud

Information
Class: Estud.Back.Features.Notifications.GetInstitutionNotifications.GetInstitutionNotificationsService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Notifications/GetInstitutionNotifications/GetInstitutionNotificationsService.cs
Tag: 114_29044117136
Line coverage
0%
Covered lines: 0
Uncovered lines: 51
Coverable lines: 51
Total lines: 64
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%620%

File(s)

/home/runner/work/syki/syki/Back/Features/Notifications/GetInstitutionNotifications/GetInstitutionNotificationsService.cs

#LineLine coverage
 1using Dapper;
 2
 3namespace Estud.Back.Features.Notifications.GetInstitutionNotifications;
 4
 05public class GetInstitutionNotificationsService(EstudDbContext ctx) : IEstudService
 6{
 7    public async Task<OneOf<GetInstitutionNotificationsOut, EstudError>> Get(GetInstitutionNotificationsIn data)
 8    {
 09        var connection = await ctx.GetOpenConnectionAsync();
 10
 011        var sql = @"
 012            SELECT
 013                n.id,
 014                n.title,
 015                n.created_at,
 016                n.description,
 017                COUNT(un.user_id) AS recipients,
 018                COUNT(un.viewed_at) AS viewed,
 019                COUNT(*) OVER() AS total_rows
 020            FROM
 021                estud.notifications n
 022            LEFT JOIN
 023                estud.user_notifications un ON un.notification_id = n.id
 024            WHERE
 025                n.institution_id = @InstitutionId
 026                AND n.notification_type = @NotificationType
 027            GROUP BY
 028                n.id, n.title, n.description, n.created_at
 029            ORDER BY
 030                n.created_at DESC
 031            LIMIT @PageSize
 032            OFFSET @Offset
 033        ";
 34
 035        var parameters = new
 036        {
 037            data.PageSize,
 038            ctx.RequestUser.InstitutionId,
 039            Offset = (data.Page - 1) * data.PageSize,
 040            NotificationType = (int)NotificationType.Custom,
 041        };
 42
 043        var rows = (await connection.QueryAsync<InstitutionNotificationRow>(sql, parameters)).ToList();
 44
 045        var items = rows.ConvertAll(r => new GetInstitutionNotificationsItemOut
 046        {
 047            Id = r.Id,
 048            Title = r.Title,
 049            Viewed = r.Viewed,
 050            CreatedAt = r.CreatedAt,
 051            Recipients = r.Recipients,
 052            Description = r.Description,
 053            ViewRate = r.Recipients > 0 ? Math.Round(100M * (1M * r.Viewed / (1M * r.Recipients)), 2) : 0,
 054        });
 55
 056        return new GetInstitutionNotificationsOut
 057        {
 058            Items = items,
 059            Page = data.Page,
 060            PageSize = data.PageSize,
 061            Total = rows.FirstOrDefault()?.TotalRows ?? 0,
 062        };
 063    }
 64}