using Confluent.Kafka.Admin; using Microsoft.AspNetCore.Mvc; using TelpoKafkaConsole.Service; using TelpoKafkaConsole.WebApi.Controllers.Api; using TelpoKafkaConsole.WebApi.Model.Request; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace TelpoKafkaConsole.WebApi.Controllers { [Route("api/[controller]")] [ApiController] public class TopicController : ControllerBase { private readonly KafkaAdminService _servicekafkaAdmin; public TopicController(KafkaAdminService kafkaAdminService) { _servicekafkaAdmin = kafkaAdminService; } [HttpGet("{topic}")] public async Task>> Get(string topic) { var topicInfo = await _servicekafkaAdmin.DescribeTopicsAsync(new List() { topic }); return ApiResponse>.Success(topicInfo); } [HttpPost] public async Task> Post([FromBody] TopicReq topic) { await _servicekafkaAdmin.CreateTopic(topic.TopicName,TimeSpan.FromDays(3), topic.NumPartitions); return ApiResponse.Success($"创建 Topic {topic} 成功"); } [HttpDelete("{topic}")] public async Task> Delete(string topic) { await _servicekafkaAdmin.DeleteTopics(new List() {topic}); return ApiResponse.Success($"删除 Topic {topic} 成功"); } } }