diff --git a/backend/Api/AMQP/AMQPPublisher.cs b/backend/Api/AMQP/AMQPPublisher.cs
index 60bb0a4..be883f1 100644
--- a/backend/Api/AMQP/AMQPPublisher.cs
+++ b/backend/Api/AMQP/AMQPPublisher.cs
@@ -1,9 +1,7 @@
using Api.DBAccess;
using Api.Models;
-using Microsoft.IdentityModel.Tokens;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
-using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
diff --git a/backend/Api/AMQP/AMQPReciever.cs b/backend/Api/AMQP/AMQPReciever.cs
index 0280791..215f956 100644
--- a/backend/Api/AMQP/AMQPReciever.cs
+++ b/backend/Api/AMQP/AMQPReciever.cs
@@ -4,7 +4,6 @@ using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;
using System.Text.Json;
-using System.Threading.Channels;
namespace Api.AMQPReciever
{
diff --git a/backend/Api/BusinessLogic/DeviceLogic.cs b/backend/Api/BusinessLogic/DeviceLogic.cs
index 27ab67a..ae4be2c 100644
--- a/backend/Api/BusinessLogic/DeviceLogic.cs
+++ b/backend/Api/BusinessLogic/DeviceLogic.cs
@@ -1,7 +1,6 @@
using Api.DBAccess;
using Api.Models;
using Microsoft.AspNetCore.Mvc;
-using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Api.BusinessLogic
{
@@ -54,10 +53,12 @@ namespace Api.BusinessLogic
///
/// Checks if the device exist that is trying to be read from
/// Gets the logs and checks if there are any in the list
+ /// Checks if the datetimeRange have 2 values that are the same bc that means they want all logs
+ /// Then it makes a new list with all data that are in the range of the 2 datetimes
///
/// The deviceId that you want from the logs
/// returns the logs in a OkObjectResult and if there is some error it returns a ConflictObjectResult and a message that explain the reason
- public async Task GetLogs(int deviceId)
+ public async Task GetLogs(DateTimeRange dateTimeRange, int deviceId)
{
var device = await _dbAccess.ReadDevice(deviceId);
@@ -67,7 +68,15 @@ namespace Api.BusinessLogic
if (logs.Count == 0) { return new ConflictObjectResult(new { message = "Could not find any logs connected to the device" }); }
- return new OkObjectResult(logs);
+ if (dateTimeRange.DateTimeStart == dateTimeRange.DateTimeEnd) { return new OkObjectResult(logs); }
+
+ List rangedLogs = new List();
+ foreach (var log in logs)
+ {
+ if (log.Date <= dateTimeRange.DateTimeStart && log.Date >= dateTimeRange.DateTimeEnd) { rangedLogs.Add(log); }
+ }
+
+ return new OkObjectResult(rangedLogs);
}
///
diff --git a/backend/Api/BusinessLogic/UserLogic.cs b/backend/Api/BusinessLogic/UserLogic.cs
index d8dcf13..a39a83c 100644
--- a/backend/Api/BusinessLogic/UserLogic.cs
+++ b/backend/Api/BusinessLogic/UserLogic.cs
@@ -1,6 +1,5 @@
using Api.DBAccess;
using Api.Models;
-using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
diff --git a/backend/Api/Controllers/DeviceController.cs b/backend/Api/Controllers/DeviceController.cs
index b8442ff..7cee3ad 100644
--- a/backend/Api/Controllers/DeviceController.cs
+++ b/backend/Api/Controllers/DeviceController.cs
@@ -45,9 +45,9 @@ namespace Api.Controllers
// Sends the deviceId to deviceLogic
[Authorize]
[HttpGet("logs/{deviceId}")]
- public async Task GetLogs(int deviceId)
+ public async Task GetLogs([FromBody] DateTimeRange dateTimeRange, int deviceId)
{
- return await _deviceLogic.GetLogs(deviceId);
+ return await _deviceLogic.GetLogs(dateTimeRange, deviceId);
}
// Sends the deviceId to deviceLogic
diff --git a/backend/Api/Controllers/UserController.cs b/backend/Api/Controllers/UserController.cs
index ec462dc..510cd79 100644
--- a/backend/Api/Controllers/UserController.cs
+++ b/backend/Api/Controllers/UserController.cs
@@ -1,10 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Api.Models;
-using Api.DBAccess;
-using Microsoft.IdentityModel.Tokens;
-using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
-using System.Text;
using Microsoft.AspNetCore.Authorization;
using Api.BusinessLogic;
diff --git a/backend/Api/DBAccess/DBAccess.cs b/backend/Api/DBAccess/DBAccess.cs
index 012f86d..a3882ae 100644
--- a/backend/Api/DBAccess/DBAccess.cs
+++ b/backend/Api/DBAccess/DBAccess.cs
@@ -1,10 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Api.Models;
-using System.Text;
-using System.Runtime.Intrinsics.Arm;
-using System.Security.Cryptography;
using Microsoft.AspNetCore.Mvc;
-using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Api.DBAccess
@@ -81,6 +77,7 @@ namespace Api.DBAccess
return await _context.Users.FirstOrDefaultAsync(u => u.RefreshToken == refreshToken);
}
+ // Updates the refreshtoken saved in DB
public async void UpdatesRefreshToken(string refreshToken, int userId)
{
var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);
@@ -190,14 +187,14 @@ namespace Api.DBAccess
return new ConflictObjectResult(new { message = "Could not save to database" });
}
-
- // Returns a device according to userID
+
+ // Returns a device according to deviceId
public async Task ReadDevice(int deviceId)
{
return await _context.Devices.FirstOrDefaultAsync(d => d.Id == deviceId);
}
- // Returns a device according to userID
+ // Returns a device according to refenreId
public Device ReadDevice(string refenreId)
{
return _context.Devices.FirstOrDefault(d => d.ReferenceId == refenreId);
diff --git a/backend/Api/Models/DateTimeRange.cs b/backend/Api/Models/DateTimeRange.cs
new file mode 100644
index 0000000..018df76
--- /dev/null
+++ b/backend/Api/Models/DateTimeRange.cs
@@ -0,0 +1,9 @@
+namespace Api.Models
+{
+ public class DateTimeRange
+ {
+ public DateTime DateTimeStart { get; set; }
+
+ public DateTime DateTimeEnd { get; set; }
+ }
+}
diff --git a/backend/Api/Program.cs b/backend/Api/Program.cs
index e2bce37..fc7a5e3 100644
--- a/backend/Api/Program.cs
+++ b/backend/Api/Program.cs
@@ -5,7 +5,6 @@ using Api.DBAccess;
using Api.MQTTReciever;
using Microsoft.AspNetCore;
using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.Configuration;
class Program
{