Ejemplo n.º 1
0
        public async Task <IActionResult> RemoveService(
            [FromServices] ICommandHandlerResolver bus,
            [FromServices] ApiProjectionsContext context,
            [FromCommandId] Guid commandId,
            [FromRoute] string secondLevelDomain,
            [FromRoute] string topLevelDomain,
            [FromRoute] Guid?serviceId,
            CancellationToken cancellationToken = default)
        {
            var request = new RemoveServiceRequest
            {
                SecondLevelDomain = secondLevelDomain,
                TopLevelDomain    = topLevelDomain,
                ServiceId         = serviceId
            };

            // TODO: We can check in the eventstore if those aggregates even exist
            await new RemoveServiceRequestValidator()
            .ValidateAndThrowAsync(request, cancellationToken: cancellationToken);

            var command = RemoveServiceRequestMapping.Map(request);

            return(Accepted(
                       $"/v1/domains/{command.DomainName}/services",
                       new LastObservedPositionResponse(
                           await bus.Dispatch(
                               commandId,
                               command,
                               GetMetadata(),
                               cancellationToken))));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ListServices(
            [FromServices] ApiProjectionsContext context,
            [FromRoute] string secondLevelDomain,
            [FromRoute] string topLevelDomain,
            CancellationToken cancellationToken = default)
        {
            var request = new ListServicesRequest
            {
                SecondLevelDomain = secondLevelDomain,
                TopLevelDomain    = topLevelDomain,
            };

            await new ListServicesRequestValidator()
            .ValidateAndThrowAsync(request, cancellationToken: cancellationToken);

            var domain = await FindDomainAsync(context, secondLevelDomain, topLevelDomain, cancellationToken);

            return(Ok(
                       new DomainServiceListResponse(domain)
            {
                Services = domain
                           .Services
                           .Select(x => new DomainServiceListItemResponse(domain, x))
                           .ToList()
            }));
        }
        public async Task <IActionResult> AddGoogleSuiteService(
            [FromServices] ICommandHandlerResolver bus,
            [FromServices] ApiProjectionsContext context,
            [FromCommandId] Guid commandId,
            [FromRoute] string secondLevelDomain,
            [FromRoute] string topLevelDomain,
            [FromBody] AddGoogleSuiteServiceRequest request,
            CancellationToken cancellationToken = default)
        {
            if (request != null)
            {
                request.SecondLevelDomain = secondLevelDomain;
                request.TopLevelDomain    = topLevelDomain;
            }

            // TODO: We can check in the eventstore if those aggregates even exist
            await new AddGoogleSuiteServiceRequestValidator()
            .ValidateAndThrowAsync(request, cancellationToken: cancellationToken);

            var command = AddGoogleSuiteServiceRequestMapping.Map(
                new DomainName(
                    new SecondLevelDomain(secondLevelDomain),
                    TopLevelDomain.FromValue(topLevelDomain)),
                request);

            return(Accepted(
                       $"/v1/domains/{command.DomainName}/services/{command.ServiceId}",
                       new LastObservedPositionResponse(
                           await bus.Dispatch(
                               commandId,
                               command,
                               GetMetadata(),
                               cancellationToken))));
        }
Ejemplo n.º 4
0
        private static async Task <object[]> AllRecords(this ApiProjectionsContext context)
        {
            var records = new List <object>();

            records.AddRange(await context.AccountDetails.ToArrayAsync());
            records.AddRange(await context.AccountList.ToArrayAsync());

            return(records.ToArray());
        }
        private static async Task <object[]> AllRecords(this ApiProjectionsContext context)
        {
            var records = new List <object>();

#if (!ExcludeExampleAggregate)
            records.AddRange(await context.ExampleAggregateDetails.ToArrayAsync());
            records.AddRange(await context.ExampleAggregateList.ToArrayAsync());
#endif

            return(records.ToArray());
        }
        private static async Task <ExampleAggregateDetail> FindExampleAggregateAsync(
            ApiProjectionsContext context,
            Guid exampleAggregateId,
            CancellationToken cancellationToken)
        {
            var exampleAggregate = await context
                                   .ExampleAggregateDetails
                                   .FindAsync(new object[] { exampleAggregateId }, cancellationToken);

            if (exampleAggregate == null)
            {
                throw new ApiException(ExampleAggregateNotFoundResponseExamples.Message, StatusCodes.Status404NotFound);
            }

            return(exampleAggregate);
        }
Ejemplo n.º 7
0
        private static async Task <AccountDetail> FindAccountAsync(
            ApiProjectionsContext context,
            Guid accountId,
            CancellationToken cancellationToken)
        {
            var account = await context
                          .AccountDetails
                          .FindAsync(new object[] { accountId }, cancellationToken);

            if (account == null)
            {
                throw new ApiException(AccountNotFoundResponseExamples.Message, StatusCodes.Status404NotFound);
            }

            return(account);
        }
Ejemplo n.º 8
0
        private static async Task <DomainDetail> FindDomainAsync(
            ApiProjectionsContext context,
            string secondLevelDomain,
            string topLevelDomain,
            CancellationToken cancellationToken)
        {
            var domain = await context
                         .DomainDetails
                         .FindAsync(new object[] { $"{secondLevelDomain}.{topLevelDomain}" }, cancellationToken);

            if (domain == null)
            {
                throw new ApiException(DomainNotFoundResponseExamples.Message, StatusCodes.Status404NotFound);
            }

            return(domain);
        }
        public async Task <IActionResult> DetailExampleAggregate(
            [FromServices] ApiProjectionsContext context,
            [FromRoute] Guid exampleAggregateId,
            CancellationToken cancellationToken = default)
        {
            var request = new DetailExampleAggregateRequest
            {
                Id = exampleAggregateId,
            };

            await new DetailExampleAggregateRequestValidator()
            .ValidateAndThrowAsync(request, cancellationToken: cancellationToken);

            var exampleAggregate = await FindExampleAggregateAsync(context, request.Id.Value, cancellationToken);

            return(Ok(
                       new ExampleAggregateDetailResponse(exampleAggregate)));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> DetailAccount(
            [FromServices] ApiProjectionsContext context,
            [FromRoute] Guid accountId,
            CancellationToken cancellationToken = default)
        {
            var request = new DetailAccountRequest
            {
                Id = accountId,
            };

            await new DetailAccountRequestValidator()
            .ValidateAndThrowAsync(request, cancellationToken: cancellationToken);

            var account = await FindAccountAsync(context, request.Id.Value, cancellationToken);

            return(Ok(
                       new AccountDetailResponse(account)));
        }
Ejemplo n.º 11
0
        public static async Task <AccountList> FindAndUpdateAccountList(
            this ApiProjectionsContext context,
            Guid accountId,
            Action <AccountList> updateFunc,
            CancellationToken ct)
        {
            var account = await context
                          .AccountList
                          .FindAsync(accountId, cancellationToken : ct);

            if (account == null)
            {
                throw DatabaseItemNotFound(accountId);
            }

            updateFunc(account);

            return(account);
        }
Ejemplo n.º 12
0
        public static async Task <DomainList> FindAndUpdateDomainList(
            this ApiProjectionsContext context,
            string domainName,
            Action <DomainList> updateFunc,
            CancellationToken ct)
        {
            var domain = await context
                         .DomainList
                         .FindAsync(domainName, cancellationToken : ct);

            if (domain == null)
            {
                throw DatabaseItemNotFound(domainName);
            }

            updateFunc(domain);

            return(domain);
        }
        public static async Task <OrganisationList> FindAndUpdateOrganisationList(
            this ApiProjectionsContext context,
            string ovoNumber,
            Action <OrganisationList> updateFunc,
            CancellationToken ct)
        {
            var organisation = await context
                               .OrganisationList
                               .FindAsync(ovoNumber, cancellationToken : ct);

            if (organisation == null)
            {
                throw DatabaseItemNotFound(ovoNumber);
            }

            updateFunc(organisation);

            return(organisation);
        }
        public static async Task <ExampleAggregateDetail> FindAndUpdateExampleAggregateDetail(
            this ApiProjectionsContext context,
            Guid exampleAggregateId,
            Action <ExampleAggregateDetail> updateFunc,
            CancellationToken ct)
        {
            var exampleAggregate = await context
                                   .ExampleAggregateDetails
                                   .FindAsync(exampleAggregateId, cancellationToken : ct);

            if (exampleAggregate == null)
            {
                throw DatabaseItemNotFound(exampleAggregateId);
            }

            updateFunc(exampleAggregate);

            return(exampleAggregate);
        }
Ejemplo n.º 15
0
        private static async Task <ServiceDetail> FindServiceAsync(
            ApiProjectionsContext context,
            Guid?serviceId,
            CancellationToken cancellationToken)
        {
            if (!serviceId.HasValue)
            {
                throw new ApiException(ServiceNotFoundResponseExamples.Message, StatusCodes.Status404NotFound);
            }

            var service = await context
                          .ServiceDetails
                          .FindAsync(new object[] { serviceId.Value }, cancellationToken);

            if (service == null)
            {
                throw new ApiException(ServiceNotFoundResponseExamples.Message, StatusCodes.Status404NotFound);
            }

            return(service);
        }
        public async Task <IActionResult> ListExampleAggregates(
            [FromServices] ApiProjectionsContext context,
            CancellationToken cancellationToken = default)
        {
            var filtering  = Request.ExtractFilteringRequest <ExampleAggregateListFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var pagedExampleAggregates = new ExampleAggregateListQuery(context)
                                         .Fetch(filtering, sorting, pagination);

            Response.AddPagedQueryResultHeaders(pagedExampleAggregates);

            return(Ok(
                       new ExampleAggregateListResponse
            {
                ExampleAggregates = await pagedExampleAggregates
                                    .Items
                                    .Select(x => new ExampleAggregateListItemResponse(x))
                                    .ToListAsync(cancellationToken)
            }));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> DetailService(
            [FromServices] ApiProjectionsContext context,
            [FromRoute] string secondLevelDomain,
            [FromRoute] string topLevelDomain,
            [FromRoute] Guid?serviceId,
            CancellationToken cancellationToken = default)
        {
            var request = new DetailServiceRequest
            {
                SecondLevelDomain = secondLevelDomain,
                TopLevelDomain    = topLevelDomain,
            };

            await new DetailServiceRequestValidator()
            .ValidateAndThrowAsync(request, cancellationToken: cancellationToken);

            var service = await FindServiceAsync(context, serviceId, cancellationToken);

            await FindDomainAsync(context, secondLevelDomain, topLevelDomain, cancellationToken);

            return(Ok(
                       new DomainServiceDetailResponse(service)));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> ListDomains(
            [FromServices] ApiProjectionsContext context,
            CancellationToken cancellationToken = default)
        {
            // TODO: Add support for eventual consistency

            var filtering  = Request.ExtractFilteringRequest <DomainListFilter>();
            var sorting    = Request.ExtractSortingRequest();
            var pagination = Request.ExtractPaginationRequest();

            var pagedDomains = new DomainListQuery(context)
                               .Fetch(filtering, sorting, pagination);

            Response.AddPagedQueryResultHeaders(pagedDomains);

            return(Ok(
                       new DomainListResponse
            {
                Domains = await pagedDomains
                          .Items
                          .Select(x => new DomainListItemResponse(x))
                          .ToListAsync(cancellationToken)
            }));
        }
Ejemplo n.º 19
0
 public AccountListQuery(ApiProjectionsContext context) => _context = context;
 public ExampleAggregateListQuery(ApiProjectionsContext context) => _context = context;
Ejemplo n.º 21
0
 public DomainListQuery(ApiProjectionsContext context) => _context = context;
Ejemplo n.º 22
0
 public OrganisationListQuery(ApiProjectionsContext context) => _context = context;