first commit
This commit is contained in:
41
src/GreenHome.Api/Controllers/DeviceSettingsController.cs
Normal file
41
src/GreenHome.Api/Controllers/DeviceSettingsController.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using GreenHome.Application;
|
||||
|
||||
namespace GreenHome.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DeviceSettingsController : ControllerBase
|
||||
{
|
||||
private readonly IDeviceSettingsService deviceSettingsService;
|
||||
|
||||
public DeviceSettingsController(IDeviceSettingsService deviceSettingsService)
|
||||
{
|
||||
this.deviceSettingsService = deviceSettingsService;
|
||||
}
|
||||
|
||||
[HttpGet("{deviceId}")]
|
||||
public async Task<ActionResult<DeviceSettingsDto>> GetByDeviceId(int deviceId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await deviceSettingsService.GetByDeviceIdAsync(deviceId, cancellationToken);
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<int>> Create(DeviceSettingsDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
var id = await deviceSettingsService.CreateAsync(dto, cancellationToken);
|
||||
return Ok(id);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
public async Task<ActionResult> Update(DeviceSettingsDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
await deviceSettingsService.UpdateAsync(dto, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
38
src/GreenHome.Api/Controllers/DevicesController.cs
Normal file
38
src/GreenHome.Api/Controllers/DevicesController.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using GreenHome.Application;
|
||||
|
||||
namespace GreenHome.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DevicesController : ControllerBase
|
||||
{
|
||||
private readonly IDeviceService deviceService;
|
||||
|
||||
public DevicesController(IDeviceService deviceService)
|
||||
{
|
||||
this.deviceService = deviceService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IReadOnlyList<DeviceDto>>> GetAll(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await deviceService.ListAsync(cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("CheckDevice")]
|
||||
public async Task<ActionResult<IReadOnlyList<DeviceDto>>> CheckDevice(string deviceName,CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await deviceService.GetDeviceId(deviceName,cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<int>> Create(DeviceDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
var id = await deviceService.AddDeviceAsync(dto, cancellationToken);
|
||||
return Ok(id);
|
||||
}
|
||||
}
|
||||
63
src/GreenHome.Api/Controllers/TelemetryController.cs
Normal file
63
src/GreenHome.Api/Controllers/TelemetryController.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using GreenHome.Application;
|
||||
|
||||
namespace GreenHome.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TelemetryController : ControllerBase
|
||||
{
|
||||
private readonly ITelemetryService telemetryService;
|
||||
|
||||
public TelemetryController(ITelemetryService telemetryService)
|
||||
{
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<PagedResult<TelemetryDto>>> List([FromQuery] int? deviceId, [FromQuery] DateTime? startUtc, [FromQuery] DateTime? endUtc, [FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var filter = new TelemetryFilter { DeviceId = deviceId, StartDateUtc = startUtc, EndDateUtc = endUtc, Page = page, PageSize = pageSize };
|
||||
var result = await telemetryService.ListAsync(filter, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("AddData")]
|
||||
public async Task<ActionResult<int>> Create(string deviceName, decimal temperatureC, decimal humidityPercent,
|
||||
decimal soilPercent, int gasPPM, decimal lux, CancellationToken cancellationToken)
|
||||
{
|
||||
TelemetryDto dto = new TelemetryDto
|
||||
{
|
||||
DeviceName = deviceName,
|
||||
TemperatureC = temperatureC,
|
||||
HumidityPercent = humidityPercent,
|
||||
SoilPercent = soilPercent,
|
||||
GasPPM = gasPPM,
|
||||
Lux = lux,
|
||||
TimestampUtc = DateTime.UtcNow
|
||||
};
|
||||
var id = await telemetryService.AddAsync(dto, cancellationToken);
|
||||
return Ok(id);
|
||||
}
|
||||
|
||||
[HttpGet("minmax")]
|
||||
public async Task<ActionResult<TelemetryMinMax>> MinMax([FromQuery] int deviceId, [FromQuery] DateTime? startUtc, [FromQuery] DateTime? endUtc, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await telemetryService.GetMinMaxAsync(deviceId, startUtc, endUtc, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("days")]
|
||||
public async Task<ActionResult<IReadOnlyList<DayCount>>> Days([FromQuery] int deviceId, [FromQuery] int year, [FromQuery] int month, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await telemetryService.GetMonthDaysAsync(deviceId, year, month, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("months")]
|
||||
public async Task<ActionResult<IReadOnlyList<int>>> Months([FromQuery] int deviceId, [FromQuery] int year, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await telemetryService.GetActiveMonthsAsync(deviceId, year, cancellationToken);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user