Cucumber/Cloud/Controllers/ValveController.cs

44 lines
1.0 KiB
C#
Raw Normal View History

2024-11-13 15:24:47 +04:00
using Cloud.Requests;
using Cloud.Services;
2024-12-04 01:57:10 +04:00
using Cloud.Services.Broker;
2024-11-13 15:24:47 +04:00
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
namespace Cloud.Controllers
{
[Authorize]
[ApiController]
[Route("api")]
public class ValveController : ControllerBase
{
//Контроллер вентиля
2024-12-04 01:57:10 +04:00
private readonly IBrokerService _kafkaService;
2024-11-13 15:24:47 +04:00
2024-12-04 01:57:10 +04:00
public ValveController(IBrokerService kafkaService)
2024-11-13 15:24:47 +04:00
{
2024-12-04 01:57:10 +04:00
_kafkaService = kafkaService;
2024-11-13 15:24:47 +04:00
}
2024-11-19 19:36:05 +04:00
[HttpPost("farm/{farmId}/greenhouse/{ghId}/watering")]
2024-11-13 15:24:47 +04:00
public async Task<IActionResult> interactValve([FromBody] ValveRequest request, int farmId, int ghId)
{
var kafkaRequest = new
{
FarmId = farmId,
GreenHouseId = ghId,
SomeAction = request.Action,
};
var message = JsonSerializer.Serialize(kafkaRequest);
2024-11-19 19:36:05 +04:00
return Ok(kafkaRequest);
2024-11-13 15:24:47 +04:00
2024-12-04 01:57:10 +04:00
/*await _kafkaService.ProduceAsync("ValvesHeatersRequest", message);
2024-11-13 15:24:47 +04:00
2024-11-19 19:36:05 +04:00
return Ok($"Valve status is {request.Action}");*/
2024-11-13 15:24:47 +04:00
}
}
}