< Summary

Information
Class: Api.Works.Mutations.AddAuthorPayload
Assembly: Api
File(s): /home/runner/work/ProjectRead.ing/ProjectRead.ing/Api/Works/Mutations/AddAuthorMutation.cs
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 81
Line coverage: 100%
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
.ctor(...)100%11100%

File(s)

/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
 144public 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)
 69    {
 70        var id = Guid.CreateVersion7().WithPostfix(Models.Author.IdPostfix);
 71        var author = CreateFromDtoInternal(w, id, now, now);
 72        author.OwnerId = ownerId;
 73
 74        return author;
 75    }
 76
 77    [UserMapping(Default = true)]
 78    public static ZonedDateTime FromInstantToZonedDateTime(Instant i) =>
 79        MapperUtils.FromInstantToZonedDateTime(i);
 80}
 81// Mostly Ai Generated - End

Methods/Properties

.ctor(Api.Works.Queries.Author)