public AcceptInviteValidator(IInviteRepository inviteRepository)
        {
            RuleFor(x => x.Id).NotEmpty().DependentRules(() =>
            {
                Invite invite = Invite.Null;

                RuleFor(x => x)
                .MustAsync(async(x, ct) =>
                {
                    invite = await inviteRepository.GetByIdAsync(x.Id, readOnly: true, ct);
                    return(!(invite is INullObject));
                })
                .WithMessage(x => $"Record not found for invite with given id {x.Id}.")
                .WithName("Id")
                .WithErrorCode(nameof(HttpStatusCode.NotFound))

                .Must(_ => invite.Status == InviteStatuses.Pending)
                .WithMessage("Invite must be on pending status to be accepted.")
                .WithName("Status")
                .WithErrorCode(nameof(HttpStatusCode.UnprocessableEntity))

                .Must(_ => !(invite.GetMember() is INullObject))
                .WithMessage($"Record not found for invited member with given id {invite.MemberId}.")
                .WithName("Member")
                .WithErrorCode(nameof(HttpStatusCode.NotFound))

                .Must(_ => !(invite.GetGuild() is INullObject))
                .WithMessage($"Record not found for inviting guild with given id {invite.GuildId}.")
                .WithName("Guild")
                .WithErrorCode(nameof(HttpStatusCode.NotFound));
            });
        }
Esempio n. 2
0
        public async Task <IApiResult> Handle(DenyInviteCommand command, CancellationToken cancellationToken)
        {
            var invite = await _inviteRepository.GetByIdAsync(command.Id, readOnly : false, cancellationToken);

            invite = _inviteRepository.Update(invite.BeDenied());

            return(new SuccessResult(invite));
        }
Esempio n. 3
0
        public CancelInviteValidator(IInviteRepository inviteRepository)
        {
            RuleFor(x => x.Id).NotEmpty().DependentRules(() =>
            {
                Invite invite = Invite.Null;

                RuleFor(x => x)
                .MustAsync(async(x, ct) =>
                {
                    invite = await inviteRepository.GetByIdAsync(x.Id, readOnly: true, ct);
                    return(!(invite is INullObject));
                })
                .WithMessage(x => $"Record not found for invite with given id {x.Id}.")
                .WithName(nameof(Invite.Id))
                .WithErrorCode(nameof(HttpStatusCode.NotFound))

                .Must(_ => invite.Status == InviteStatuses.Pending)
                .WithMessage("Invite must be on pending status to be canceled.")
                .WithName(nameof(invite.Status))
                .WithErrorCode(nameof(HttpStatusCode.UnprocessableEntity));
            });
        }
        public async Task <IActionResult> GetAsync(Guid id, CancellationToken cancellationToken)
        {
            var result = await _repository.GetByIdAsync(id, true, cancellationToken);

            return(result is NullInvite?this.NotFoundFor <Invite>(id) : Ok(result));
        }
Esempio n. 5
0
        public async Task <IApiResult> Handle(GetInviteCommand command, CancellationToken cancellationToken)
        {
            var invite = await _inviteRepository.GetByIdAsync(command.Id, true, cancellationToken);

            return(new SuccessResult(invite));
        }