Beispiel #1
0
        public async Task <Result <WalletDocument> > HandleAsync(
            GetWalletQuery query,
            CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(query, nameof(query));
            cancellationToken.ThrowIfCancellationRequested();

            var userId = _userContext.UserId;
            var wallet = await _readOnlyRepository.GetAsync(query.Id, userId, cancellationToken);

            return(wallet is null
                ? Result.Failed <WalletDocument>((int)HttpStatusCode.NotFound, "Wallet not found.")
                : Result.Ok(_mapper.Map(wallet)));
        }
Beispiel #2
0
        public async Task <Result <BucketDocument> > HandleAsync(GetBucketQuery query, CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(query, nameof(query));
            cancellationToken.ThrowIfCancellationRequested();

            var userId = _userContext.UserId;
            var bucket = await _readOnlyRepository.GetAsync(p => p.Id == query.Id && p.UserId == userId, cancellationToken);

            if (bucket is null)
            {
                return(Result.Failed <BucketDocument>((int)HttpStatusCode.NotFound, "Bucket not found."));
            }

            var document = _mapperDefinition.Map(bucket);

            return(Result.Ok(document));
        }
Beispiel #3
0
        public async Task <Result <int> > HandleAsync(CreateWalletCommand command, CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(command, nameof(command));
            cancellationToken.ThrowIfCancellationRequested();

            if (await _currencyRepository.ExistAsync(command.CurrencyId, cancellationToken) == false)
            {
                return(this.NotFound("Currency not found."));
            }

            var domainWallet = _walletMapper.Map(command);

            domainWallet.UserId = _userContext.UserId;
            domainWallet        = await _repository.CreateAsync(domainWallet, cancellationToken);

            return(this.Ok(domainWallet.Id));
        }
        public async Task <Result <int> > HandleAsync(CreateBucketCommand command, CancellationToken cancellationToken = default)
        {
            Assert.IsNotNull(command, nameof(command));
            cancellationToken.ThrowIfCancellationRequested();

            if (await _currencyRepository.ExistAsync(command.CurrencyId, cancellationToken) == false)
            {
                return(this.NotFound("Currency not found."));
            }

            var userId = _userContext.UserId;

            var bucketDomain = _mapperDefinition.Map(command);

            bucketDomain.UserId = userId;
            bucketDomain        = await _bucketRepository.CreateAsync(bucketDomain, cancellationToken);

            return(this.Ok(bucketDomain.Id));
        }