Mqttreciever
This commit is contained in:
parent
1d3f929986
commit
2d7e80b3a1
@ -28,21 +28,21 @@ namespace Api.Controllers
|
|||||||
return await _deviceLogic.GetDevices(userId);
|
return await _deviceLogic.GetDevices(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
[HttpPost("adddevice/{userId}")]
|
[HttpPost("adddevice/{userId}")]
|
||||||
public async Task<IActionResult> AddDevice([FromBody] Device device, int userId)
|
public async Task<IActionResult> AddDevice([FromBody] Device device, int userId)
|
||||||
{
|
{
|
||||||
return await _deviceLogic.AddDevice(device, userId);
|
return await _deviceLogic.AddDevice(device, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
[HttpGet("logs/{deviceId}")]
|
[HttpGet("logs/{deviceId}")]
|
||||||
public async Task<IActionResult> GetLogs(int deviceId)
|
public async Task<IActionResult> GetLogs(int deviceId)
|
||||||
{
|
{
|
||||||
return await _deviceLogic.GetLogs(deviceId);
|
return await _deviceLogic.GetLogs(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
[HttpPut("Edit/{deviceId}")]
|
[HttpPut("Edit/{deviceId}")]
|
||||||
public async Task<IActionResult> EditDevice([FromBody] Device device, int deviceId)
|
public async Task<IActionResult> EditDevice([FromBody] Device device, int deviceId)
|
||||||
{
|
{
|
||||||
|
@ -33,14 +33,14 @@ namespace Api.Controllers
|
|||||||
return await _userLogic.RegisterUser(user);
|
return await _userLogic.RegisterUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
[HttpPut("Edit/{userId}")]
|
[HttpPut("Edit/{userId}")]
|
||||||
public async Task<IActionResult> EditUser([FromBody] User user, int userId)
|
public async Task<IActionResult> EditUser([FromBody] User user, int userId)
|
||||||
{
|
{
|
||||||
return await _userLogic.EditProfile(user, userId);
|
return await _userLogic.EditProfile(user, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
//[Authorize]
|
||||||
[HttpDelete("Delete/{userId}")]
|
[HttpDelete("Delete/{userId}")]
|
||||||
public async Task<IActionResult> DeleteUser(int userId)
|
public async Task<IActionResult> DeleteUser(int userId)
|
||||||
{
|
{
|
||||||
|
@ -150,6 +150,10 @@ namespace Api.DBAccess
|
|||||||
return await _context.Devices.FirstOrDefaultAsync(d => d.Id == deviceId);
|
return await _context.Devices.FirstOrDefaultAsync(d => d.Id == deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Device ReadDevice(string refenreId)
|
||||||
|
{
|
||||||
|
return _context.Devices.FirstOrDefault(d => d.ReferenceId == refenreId);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> UpdateDevice(Device device, int deviceId)
|
public async Task<IActionResult> UpdateDevice(Device device, int deviceId)
|
||||||
{
|
{
|
||||||
@ -183,6 +187,18 @@ namespace Api.DBAccess
|
|||||||
return logs;
|
return logs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async void CreateLog(TemperatureLogs temperatureLogs, string referenceId)
|
||||||
|
{
|
||||||
|
var device = await _context.Devices.Include(d => d.Logs).FirstOrDefaultAsync(d => d.ReferenceId == referenceId);
|
||||||
|
|
||||||
|
if (device == null) { return; }
|
||||||
|
|
||||||
|
if (device.Logs == null) { device.Logs = new List<TemperatureLogs>(); }
|
||||||
|
|
||||||
|
device.Logs.Add(temperatureLogs);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> Test()
|
public async Task<bool> Test()
|
||||||
{
|
{
|
||||||
return _context.Database.CanConnect();
|
return _context.Database.CanConnect();
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using Api;
|
using Api;
|
||||||
|
using Api.DBAccess;
|
||||||
|
using Api.MQTTReciever;
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@ -8,6 +10,17 @@ class Program
|
|||||||
{
|
{
|
||||||
var app = CreateWebHostBuilder(args).Build();
|
var app = CreateWebHostBuilder(args).Build();
|
||||||
|
|
||||||
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var services = scope.ServiceProvider;
|
||||||
|
var configuration = services.GetRequiredService<IConfiguration>();
|
||||||
|
var dbAccess = services.GetRequiredService<DbAccess>();
|
||||||
|
|
||||||
|
MQTTReciever mqtt = new MQTTReciever(configuration, dbAccess);
|
||||||
|
mqtt.Handle_Received_Application_Message();
|
||||||
|
}
|
||||||
|
|
||||||
RunMigrations(app);
|
RunMigrations(app);
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
Loading…
Reference in New Issue
Block a user