39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
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);
|
|
}
|
|
}
|