2024-12-22 19:46:36 +04:00
|
|
|
|
using Cloud.Models;
|
|
|
|
|
using Cloud.Requests;
|
2024-11-13 15:24:47 +04:00
|
|
|
|
using Cloud.Services;
|
2024-12-04 01:57:10 +04:00
|
|
|
|
using Cloud.Services.Broker;
|
2024-12-22 19:46:36 +04:00
|
|
|
|
using Cloud.Services.Broker.Implement.Kafka;
|
|
|
|
|
using Cloud.Services.Broker.Support;
|
2024-11-13 15:24:47 +04:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-12-22 19:46:36 +04:00
|
|
|
|
using System;
|
2024-11-13 15:24:47 +04:00
|
|
|
|
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-22 19:46:36 +04:00
|
|
|
|
public ValveController(KafkaService 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)
|
|
|
|
|
{
|
2024-12-22 19:46:36 +04:00
|
|
|
|
var command = new Command
|
2024-11-13 15:24:47 +04:00
|
|
|
|
{
|
2024-12-22 19:46:36 +04:00
|
|
|
|
request_id = Guid.NewGuid(),
|
|
|
|
|
greenhouse_id = ghId,
|
|
|
|
|
farm_id = farmId,
|
|
|
|
|
command = "valve",
|
|
|
|
|
target_moisture = request.Moisture
|
2024-11-13 15:24:47 +04:00
|
|
|
|
};
|
|
|
|
|
|
2024-12-22 19:46:36 +04:00
|
|
|
|
await _kafkaService.ProduceAsync("commands", command);
|
2024-11-13 15:24:47 +04:00
|
|
|
|
|
2024-12-22 19:46:36 +04:00
|
|
|
|
return Ok($"Valve target moisture is set as {request.Moisture}%");
|
2024-11-13 15:24:47 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|