public virtual async Task <AggregateReRouteDto> CreateAsync(AggregateReRouteCreateDto input)
        {
            var aggregateNameExists = await _aggregateReRouteRepository
                                      .AggregateReRouteNameExistsAsync(input.Name);

            if (aggregateNameExists)
            {
                throw new UserFriendlyException(L["AggregateReRouteExists", input.Name]);
            }
            var aggregateRoute = ObjectMapper.Map <AggregateReRouteCreateDto, AggregateReRoute>(input);

            aggregateRoute.SetUpstream(input.UpstreamHost, input.UpstreamPathTemplate);
            foreach (var httpMethod in input.UpstreamHttpMethod)
            {
                aggregateRoute.AddUpstreamHttpMethod(httpMethod);
            }
            foreach (var routeKey in input.ReRouteKeys)
            {
                aggregateRoute.AddRouteKey(routeKey);
            }
            aggregateRoute = await _aggregateReRouteRepository.InsertAsync(aggregateRoute);

            await DistributedEventBus.PublishAsync(new ApigatewayConfigChangeEventData(aggregateRoute.AppId, "AggregateRoute", "Create"));

            return(ObjectMapper.Map <AggregateReRoute, AggregateReRouteDto>(aggregateRoute));
        }
Exemplo n.º 2
0
        public virtual async Task <AggregateReRouteDto> CreateAsync(AggregateReRouteCreateDto aggregateReRouteCreate)
        {
            var aggregateNameExists = await _aggregateReRouteRepository
                                      .AggregateReRouteNameExistsAsync(aggregateReRouteCreate.Name);

            if (aggregateNameExists)
            {
                throw new UserFriendlyException(L["AggregateReRouteExists", aggregateReRouteCreate.Name]);
            }
            var aggregateRoute = ObjectMapper.Map <AggregateReRouteCreateDto, AggregateReRoute>(aggregateReRouteCreate);

            aggregateRoute.SetUpstream(aggregateReRouteCreate.UpstreamHost, aggregateReRouteCreate.UpstreamPathTemplate);
            foreach (var httpMethod in aggregateReRouteCreate.UpstreamHttpMethod)
            {
                aggregateRoute.AddUpstreamHttpMethod(httpMethod);
            }
            foreach (var routeKey in aggregateReRouteCreate.ReRouteKeys)
            {
                aggregateRoute.AddRouteKey(routeKey);
            }
            aggregateRoute = await _aggregateReRouteRepository.InsertAsync(aggregateRoute);

            await _eventPublisher.PublishAsync(ApigatewayConfigChangeCommand.EventName,
                                               new ApigatewayConfigChangeCommand("AggregateRoute", "Create"));

            return(ObjectMapper.Map <AggregateReRoute, AggregateReRouteDto>(aggregateRoute));
        }