Removed unnessesary usings and added a datetimerange for getting logs
This commit is contained in:
parent
f6e2c8f450
commit
9dc19efd83
@ -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;
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="deviceId">The deviceId that you want from the logs</param>
|
||||
/// <returns>returns the logs in a OkObjectResult and if there is some error it returns a ConflictObjectResult and a message that explain the reason</returns>
|
||||
public async Task<IActionResult> GetLogs(int deviceId)
|
||||
public async Task<IActionResult> 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<TemperatureLogs> rangedLogs = new List<TemperatureLogs>();
|
||||
foreach (var log in logs)
|
||||
{
|
||||
if (log.Date <= dateTimeRange.DateTimeStart && log.Date >= dateTimeRange.DateTimeEnd) { rangedLogs.Add(log); }
|
||||
}
|
||||
|
||||
return new OkObjectResult(rangedLogs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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;
|
||||
|
@ -45,9 +45,9 @@ namespace Api.Controllers
|
||||
// Sends the deviceId to deviceLogic
|
||||
[Authorize]
|
||||
[HttpGet("logs/{deviceId}")]
|
||||
public async Task<IActionResult> GetLogs(int deviceId)
|
||||
public async Task<IActionResult> GetLogs([FromBody] DateTimeRange dateTimeRange, int deviceId)
|
||||
{
|
||||
return await _deviceLogic.GetLogs(deviceId);
|
||||
return await _deviceLogic.GetLogs(dateTimeRange, deviceId);
|
||||
}
|
||||
|
||||
// Sends the deviceId to deviceLogic
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<Device> 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);
|
||||
|
9
backend/Api/Models/DateTimeRange.cs
Normal file
9
backend/Api/Models/DateTimeRange.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Api.Models
|
||||
{
|
||||
public class DateTimeRange
|
||||
{
|
||||
public DateTime DateTimeStart { get; set; }
|
||||
|
||||
public DateTime DateTimeEnd { get; set; }
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ using Api.DBAccess;
|
||||
using Api.MQTTReciever;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
class Program
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user