Compare commits

..

No commits in common. "7a3d5b4f71953d1f03b2b080e3c721e5fe810a73" and "6fe0841cbc2aecd03dd040eff529a7c1bd206eeb" have entirely different histories.

9 changed files with 21 additions and 27 deletions

View File

@ -1,7 +1,9 @@
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;

View File

@ -4,6 +4,7 @@ using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System.Text;
using System.Text.Json;
using System.Threading.Channels;
namespace Api.AMQPReciever
{

View File

@ -1,6 +1,7 @@
using Api.DBAccess;
using Api.Models;
using Microsoft.AspNetCore.Mvc;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Api.BusinessLogic
{
@ -53,12 +54,10 @@ 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(DateTimeRange dateTimeRange, int deviceId)
public async Task<IActionResult> GetLogs(int deviceId)
{
var device = await _dbAccess.ReadDevice(deviceId);
@ -68,15 +67,7 @@ namespace Api.BusinessLogic
if (logs.Count == 0) { return new ConflictObjectResult(new { message = "Could not find any logs connected to the device" }); }
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);
return new OkObjectResult(logs);
}
/// <summary>

View File

@ -1,5 +1,6 @@
using Api.DBAccess;
using Api.Models;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;

View File

@ -45,9 +45,9 @@ namespace Api.Controllers
// Sends the deviceId to deviceLogic
[Authorize]
[HttpGet("logs/{deviceId}")]
public async Task<IActionResult> GetLogs([FromBody] DateTimeRange dateTimeRange, int deviceId)
public async Task<IActionResult> GetLogs(int deviceId)
{
return await _deviceLogic.GetLogs(dateTimeRange, deviceId);
return await _deviceLogic.GetLogs(deviceId);
}
// Sends the deviceId to deviceLogic

View File

@ -1,6 +1,10 @@
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;

View File

@ -1,6 +1,10 @@
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
@ -77,7 +81,6 @@ 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);
@ -187,14 +190,14 @@ namespace Api.DBAccess
return new ConflictObjectResult(new { message = "Could not save to database" });
}
// Returns a device according to deviceId
// Returns a device according to userID
public async Task<Device> ReadDevice(int deviceId)
{
return await _context.Devices.FirstOrDefaultAsync(d => d.Id == deviceId);
}
// Returns a device according to refenreId
// Returns a device according to userID
public Device ReadDevice(string refenreId)
{
return _context.Devices.FirstOrDefault(d => d.ReferenceId == refenreId);

View File

@ -1,9 +0,0 @@
namespace Api.Models
{
public class DateTimeRange
{
public DateTime DateTimeStart { get; set; }
public DateTime DateTimeEnd { get; set; }
}
}

View File

@ -5,6 +5,7 @@ using Api.DBAccess;
using Api.MQTTReciever;
using Microsoft.AspNetCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
class Program
{