< Summary

Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 104
Line coverage: 95%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: CreateFromDtoInternal(...)100%11100%
File 2: CreateFromDto(...)100%11100%
File 2: FromInstantToZonedDateTime(...)100%210%

File(s)

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/obj/Debug/net10.0/generated/Riok.Mapperly/Riok.Mapperly.MapperGenerator/AddAuthorInputMapper.g.cs

#LineLine coverage
 1// <auto-generated />
 2#nullable enable
 3namespace Api.Works.Mutations
 4{
 5    public static partial class AddAuthorInputMapper
 6    {
 7        [global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.3.1.0")]
 8        private static partial global::Api.Works.Models.Author CreateFromDtoInternal(global::Api.Works.Mutations.AddAuth
 19        {
 110            var target = new global::Api.Works.Models.Author()
 111            {
 112                DisplayName = w.DisplayName,
 113                PenNames = w.PenNames,
 114            };
 115            target.Id = id;
 116            target.MetadataAddedAt = metadataAddedAt;
 117            target.MetadataUpdatedAt = metadataUpdatedAt;
 118            target.FirstName = w.FirstName;
 119            target.LastName = w.LastName;
 120            return target;
 121        }
 22    }
 23}

/home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Works/Mutations/AddAuthorMutation.cs

#LineLine coverage
 1// SPDX-FileCopyrightText: 2026 Alper Çelik <alper@alper-celik.dev>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5// Mostly Ai Generated - Start
 6using Api.Auth.Handlers;
 7using Api.Auth.Models;
 8using Api.Auth.Utils;
 9using Api.Database;
 10using Api.Database.Utils;
 11using Api.Utils;
 12using Api.Works.Models;
 13using Api.Works.Queries;
 14using FluentValidation;
 15using NodaTime;
 16using Riok.Mapperly.Abstractions;
 17
 18namespace Api.Works.Mutations;
 19
 20[MutationType]
 21public static partial class AddAuthorMutations
 22{
 23    [PermissionCheckAuthorize(UserPermissionBits.AuthorWrite)]
 24    public static async Task<AddAuthorPayload> AddAuthorAsync(
 25        [Service] PGContext db,
 26        [Service] ICurrentUserId userId,
 27        [Service] IEFTransactionDIAccessorService txGetter,
 28        AddAuthorInput input,
 29        CancellationToken ct
 30    )
 31    {
 32        var tx = await txGetter.BeginOrGetTransactionAsync();
 33
 34        var author = AddAuthorInputMapper.CreateFromDto(input, userId.Id!.Value, Now());
 35
 36        await db.AddAsync(author, cancellationToken: ct);
 37        await db.SaveChangesAsync(cancellationToken: ct);
 38
 39        await tx.CommitAsync(ct);
 40        return new AddAuthorPayload(AuthorMapper.ToDto(author));
 41    }
 42}
 43
 44public record AddAuthorPayload(Queries.Author Author);
 45
 46public record AddAuthorInput
 47{
 48    public string? FirstName { get; init; }
 49
 50    public string? LastName { get; init; }
 51
 52    public required string DisplayName { get; init; }
 53
 54    public required List<string> PenNames { get; init; } = [];
 55}
 56
 57[Mapper]
 58public static partial class AddAuthorInputMapper
 59{
 60    [MapperIgnoreTarget(nameof(Models.Author.RowVersion))]
 61    private static partial Models.Author CreateFromDtoInternal(
 62        AddAuthorInput w,
 63        Guid id,
 64        Instant metadataAddedAt,
 65        Instant metadataUpdatedAt
 66    );
 67
 68    public static Models.Author CreateFromDto(AddAuthorInput w, Guid ownerId, Instant now)
 169    {
 170        var id = Guid.CreateVersion7().WithPostfix(Models.Author.IdPostfix);
 171        var author = CreateFromDtoInternal(w, id, now, now);
 172        author.OwnerId = ownerId;
 73
 174        return author;
 175    }
 76
 77    [UserMapping(Default = true)]
 78    public static ZonedDateTime FromInstantToZonedDateTime(Instant i) =>
 079        MapperUtils.FromInstantToZonedDateTime(i);
 80}
 81// Mostly Ai Generated - End