コード例 #1
0
        public async Task <IActionResult> UpdateCapability(string id, [FromBody] CapabilityInput input)
        {
            var capabilityId = Guid.Empty;

            Guid.TryParse(id, out capabilityId);


            IActionResult actionResult;

            try
            {
                var capability =
                    await _capabilityApplicationService.UpdateCapability(capabilityId, input.Name, input.Description);

                var dto = Capability.Create(capability);

                actionResult = Ok(
                    value: dto
                    );
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }

            return(actionResult);
        }
コード例 #2
0
        public async Task <IActionResult> DeleteTopicByName(string name, [FromQuery(Name = "clusterId")] string clusterId)
        {
            IActionResult actionResult = Ok();

            try
            {
                await _topicDomainService.DeleteTopic(name, clusterId);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);

                ExceptionToStatusCode.CanConvert(exception, out actionResult);
            }

            return(actionResult);
        }
コード例 #3
0
        public async Task <IActionResult> AddContextToCapability(string id, [FromBody] ContextInput input)
        {
            var capabilityId = Guid.Empty;

            Guid.TryParse(id, out capabilityId);

            IActionResult actionResult;

            try
            {
                await _capabilityApplicationService.AddContext(capabilityId, input.Name);

                actionResult = Ok();
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }

            return(actionResult);
        }
コード例 #4
0
        public async Task <IActionResult> DeleteCapability(string id)
        {
            var capabilityId = Guid.Empty;

            Guid.TryParse(id, out capabilityId);

            IActionResult actionResult;

            try
            {
                await _capabilityApplicationService.DeleteCapability(capabilityId);

                actionResult = Ok();
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }

            return(actionResult);
        }
コード例 #5
0
        public async Task <IActionResult> RemoveMemberFromCapability([FromRoute] string id,
                                                                     [FromRoute] string memberEmail)
        {
            var capabilityId = Guid.Empty;

            Guid.TryParse(id, out capabilityId);

            IActionResult actionResult;

            try
            {
                await _capabilityApplicationService.LeaveCapability(capabilityId, memberEmail);

                actionResult = Ok();
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }

            return(actionResult);
        }
コード例 #6
0
        public async Task <IActionResult> CreateCapability(CapabilityInput input)
        {
            IActionResult actionResult;

            try
            {
                var capability = await _capabilityApplicationService.CreateCapability(input.Name, input.Description);

                var dto = Capability.Create(capability);

                actionResult = CreatedAtAction(
                    actionName: nameof(GetCapability),
                    routeValues: new { id = capability.Id },
                    value: dto
                    );
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }

            return(actionResult);
        }
コード例 #7
0
        public async Task <IActionResult> GetCapability(string id)
        {
            var capabilityId = Guid.Empty;

            Guid.TryParse(id, out capabilityId);

            IActionResult actionResult;

            try
            {
                var capability = await _capabilityApplicationService.GetCapability(capabilityId);

                var dto = CapabilityDetails.Create(capability);
                actionResult = Ok(dto);
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }


            return(actionResult);
        }
コード例 #8
0
        public async Task <IActionResult> AddTopicToCapability(string id, [FromBody] TopicInput input)
        {
            var capabilityId = Guid.Empty;

            Guid.TryParse(id, out capabilityId);

            if (capabilityId == Guid.Empty)
            {
                return(BadRequest(new { Message = $"the capability id: {id} is malformed" }));
            }

            var capability = await
                             _capabilityRepository.Get(capabilityId);

            IActionResult actionResult;

            try
            {
                var configurations = new Dictionary <string, object>();
                if (input.Configurations != null)
                {
                    foreach (var(key, value) in input.Configurations)
                    {
                        var jsonElement = (JsonElement)value;
                        configurations[key] = JsonObjectTools.GetValueFromJsonElement(jsonElement);
                    }
                }

                if (String.IsNullOrEmpty(input.KafkaClusterId))
                {
                    throw new ClusterNotSelectedException();
                }

                var topic = Topic.Create(
                    capabilityId,
                    Guid.Parse(input.KafkaClusterId),
                    capability.RootId,
                    input.Name,
                    input.Description,
                    input.Partitions,
                    input.Availability,
                    configurations
                    );

                await _topicDomainService.CreateTopic(
                    topic : topic,
                    dryRun : true
                    );

                var kafkaCluster = await _topicDomainService.GetClusterById(topic.KafkaClusterId);

                if (input.DryRun)
                {
                    return(Ok(DTOs.Topic.CreateFrom(topic)));
                }

                TaskFactoryExtensions.StartActionWithConsoleExceptions(async() =>
                {
                    await _kafkaJanitorRestClient.CreateTopic(topic, capability, kafkaCluster.ClusterId);

                    await _topicDomainService.CreateTopic(
                        topic: topic,
                        dryRun: input.DryRun
                        );
                });

                var topicDto = DTOs.Topic.CreateFrom(topic);
                actionResult = Ok(topicDto);
            }
            catch (Exception exception) when(ExceptionToStatusCode.CanConvert(exception, out actionResult))
            {
            }

            return(actionResult);
        }