64 lines
2.1 KiB
C#
Raw Normal View History

2025-02-13 13:52:02 +02:00
using DevOpsProject.CommunicationControl.API.DTO.Hive.Request;
using DevOpsProject.CommunicationControl.API.DTO.Hive.Response;
using DevOpsProject.CommunicationControl.Logic.Services.Interfaces;
using DevOpsProject.Shared.Models;
using Microsoft.AspNetCore.Mvc;
namespace DevOpsProject.CommunicationControl.API.Controllers
{
[ApiController]
[Route("api/hive")]
public class HiveController : Controller
{
private readonly ICommunicationControlService _communicationControlService;
public HiveController(ICommunicationControlService communicationControlService)
{
_communicationControlService = communicationControlService;
}
[HttpPost("connect")]
public async Task<IActionResult> Connect(HiveConnectRequest request)
{
var hiveModel = new HiveModel
{
HiveID = request.HiveID,
HiveIP = request.HiveIP,
HivePort = request.HivePort,
};
var hiveOperationalArea = await _communicationControlService.ConnectHive(hiveModel);
var connectResponse = new HiveConnectResponse
{
ConnectResult = true,
OperationalArea = hiveOperationalArea,
};
return Ok(connectResponse);
}
[HttpPost("telemetry")]
public async Task<IActionResult> Telemetry(HiveTelemetryRequest request)
{
var hiveTelemetryModel = new HiveTelemetryModel
{
HiveID = request.HiveID,
Location = request.Location,
Speed = request.Speed,
Height = request.Height,
State = request.State,
Timestamp = DateTime.Now
};
var telemetryUpdateTimestamp = await _communicationControlService.AddTelemetry(hiveTelemetryModel);
var telemetryResponse = new HiveTelemetryResponse
{
Timestamp = telemetryUpdateTimestamp
};
return Ok(telemetryResponse);
}
}
}