slik-dispenser/backend/Controllers/DispenserController.cs

27 lines
629 B
C#
Raw Normal View History

using Microsoft.AspNetCore.Mvc;
using MQTTnet;
using backend.Application;
2023-12-05 22:43:02 +00:00
using backend.Models;
namespace backend.Controllers;
[ApiController]
public class DispenserController : ControllerBase
{
[HttpPost("Dispense")]
public void Dispense()
{
Console.WriteLine("Dispensing..");
var message = new MqttApplicationMessageBuilder()
.WithTopic("dispense")
.WithPayload("dispense")
.Build();
2023-12-05 22:43:02 +00:00
ApplicationState.DbContext!.Add(new DispenserLog { Timestamp = DateTime.Now });
ApplicationState.DbContext!.SaveChanges();
ApplicationState.MqttClient!.PublishAsync(message, CancellationToken.None);
}
}