2024-11-13 15:24:47 +04:00
|
|
|
|
using Cloud.Requests;
|
|
|
|
|
using Cloud.Services;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
//Контроллер вентиля
|
|
|
|
|
|
|
|
|
|
private readonly ProducerService _producerService;
|
|
|
|
|
|
|
|
|
|
public ValveController(ProducerService producerService)
|
|
|
|
|
{
|
|
|
|
|
_producerService = producerService;
|
|
|
|
|
}
|
|
|
|
|
|
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-11-19 19:36:05 +04:00
|
|
|
|
/*await _producerService.ProduceMessageAsync("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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|