42 lines
1006 B
C#
42 lines
1006 B
C#
|
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;
|
|||
|
}
|
|||
|
|
|||
|
[HttpPost("farm/{farmId}/greenhouse/{greenhouseId}/watering")]
|
|||
|
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);
|
|||
|
|
|||
|
await _producerService.ProduceMessageAsync("InventoryUpdates", message);
|
|||
|
|
|||
|
return Ok($"Valve status is {request.Action}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|