| | | 1 | | using ArturRios.Data.Relational.Core.Interfaces; |
| | | 2 | | using ArturRios.Heimdall.Domain.Entities; |
| | | 3 | | using Microsoft.EntityFrameworkCore; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Command.Services; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// The reads UC-60 and UC-61 share: the caller's own open invitation, and the inviter who should hear the |
| | | 9 | | /// answer. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class InviteeInvitationLookup |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// The open invitation <paramref name="invitationId" />, with its invitee, if and only if it was made to |
| | | 15 | | /// the caller; otherwise <c>null</c>. An unknown id, an ended or expired invitation and somebody else's |
| | | 16 | | /// all give <c>null</c>, so inviter, invitee and outsider cannot tell them apart (AF-60a, AF-61a). |
| | | 17 | | /// </summary> |
| | | 18 | | public static async Task<(Person Invitee, ScopeOwnerInvitation Invitation)?> FindAsync( |
| | | 19 | | IAsyncReadOnlyRepository<Person, long> personReader, |
| | | 20 | | IAsyncReadOnlyRepository<ScopeOwnerInvitation, long> invitationReader, |
| | | 21 | | Guid actingPersonId, |
| | | 22 | | Guid invitationId, |
| | | 23 | | DateTime now, |
| | | 24 | | CancellationToken cancellationToken) |
| | | 25 | | { |
| | 33 | 26 | | var invitee = await personReader.Query() |
| | 33 | 27 | | .FirstOrDefaultAsync(x => x.PublicId == actingPersonId, cancellationToken); |
| | | 28 | | |
| | 33 | 29 | | if (invitee is null) |
| | | 30 | | { |
| | 0 | 31 | | return null; |
| | | 32 | | } |
| | | 33 | | |
| | 33 | 34 | | var invitation = await invitationReader.Query() |
| | 33 | 35 | | .Where(x => x.PublicId == invitationId && x.InviteePersonId == invitee.Id) |
| | 33 | 36 | | .Where(ScopeOwnerInvitation.OpenAt(now)) |
| | 33 | 37 | | .FirstOrDefaultAsync(cancellationToken); |
| | | 38 | | |
| | 33 | 39 | | return invitation is null ? null : (invitee, invitation); |
| | 33 | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// The inviter, when there is still somebody to tell: not cleared by anonymisation or a hard delete, not |
| | | 44 | | /// logically deleted or anonymised, and not processing-restricted, since a restricted person is mailed |
| | | 45 | | /// nothing (NFR-24, AF-51c). <c>null</c> means no answer notice is sent. |
| | | 46 | | /// </summary> |
| | | 47 | | public static async Task<Person?> InviterToTellAsync( |
| | | 48 | | IAsyncReadOnlyRepository<Person, long> personReader, |
| | | 49 | | ScopeOwnerInvitation invitation, |
| | | 50 | | CancellationToken cancellationToken) |
| | | 51 | | { |
| | 15 | 52 | | if (invitation.InvitedByPersonId is not { } inviterId) |
| | | 53 | | { |
| | 3 | 54 | | return null; |
| | | 55 | | } |
| | | 56 | | |
| | 12 | 57 | | return await personReader.Query() |
| | 12 | 58 | | .FirstOrDefaultAsync(x => x.Id == inviterId && !x.IsDeleted && x.AnonymisedAt == null && |
| | 12 | 59 | | x.ProcessingRestrictedAt == null, cancellationToken); |
| | 15 | 60 | | } |
| | | 61 | | } |