Compare commits

..

No commits in common. "b0117e514879999947ed943ae2e6d6e01c44c443" and "8d04d89eabc776819b85d0b0958d7bae6f59fe59" have entirely different histories.

8 changed files with 4 additions and 149 deletions

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backend", "Backend.csproj", "{161624D7-33B9-48B8-BA05-303DCFAEB03E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{161624D7-33B9-48B8-BA05-303DCFAEB03E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{161624D7-33B9-48B8-BA05-303DCFAEB03E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{161624D7-33B9-48B8-BA05-303DCFAEB03E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{161624D7-33B9-48B8-BA05-303DCFAEB03E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A377D3C5-E56D-4A16-AC4B-F3B0BB4CFCCE}
EndGlobalSection
EndGlobal

View File

@ -100,24 +100,6 @@ public class Controller : ControllerBase
.ToList();
}
[HttpGet(nameof(GetHistoryForInstallation))]
public ActionResult<IEnumerable<UserAction>> GetHistoryForInstallation(Int64 id, Token authToken)
{
var user = Db.GetSession(authToken)?.User;
if (user == null)
return Unauthorized();
var installation = Db.GetInstallationById(id);
if (installation is null || !user.HasAccessTo(installation))
return Unauthorized();
return Db.UserActions
.Where(action =>action.InstallationId == id)
.OrderByDescending(action => action.Timestamp)
.ToList();
}
[HttpGet(nameof(GetAllWarningsForInstallation))]
public ActionResult<IEnumerable<Warning>> GetAllWarningsForInstallation(Int64 id, Token authToken)
{
@ -570,19 +552,12 @@ public class Controller : ControllerBase
{
var session = Db.GetSession(authToken);
//Console.WriteLine(config.GridSetPoint);
// Send configuration changes
var success = await session.SendInstallationConfig(installationId, config);
// Record configuration change
if (success)
{
var actionSuccess = await session.RecordUserAction(installationId, config);
return actionSuccess?Ok():Unauthorized();
}
return Unauthorized();
//var installationToUpdate = Db.GetInstallationById(installationId);
return await session.SendInstallationConfig(installationId, config)
? Ok()
: Unauthorized();
}
[HttpPut(nameof(MoveFolder))]

View File

@ -6,10 +6,6 @@ public class Configuration
public Double GridSetPoint { get; set; }
public CalibrationChargeType CalibrationChargeState { get; set; }
public DateTime CalibrationChargeDate { get; set; }
public String GetConfigurationString()
{
return $"MinimumSoC: {MinimumSoC}, GridSetPoint: {GridSetPoint}, CalibrationChargeState: {CalibrationChargeState}, CalibrationChargeDate: {CalibrationChargeDate}";
}
}
public enum CalibrationChargeType

View File

@ -101,28 +101,6 @@ public static class SessionMethods
&& user.HasAccessTo(installation)
&& await installation.SendConfig(configuration);
}
public static async Task<Boolean> RecordUserAction(this Session? session, Int64 installationId, Configuration newConfiguration)
{
var user = session?.User;
var timestamp = DateTime.Now;
if (user is null || user.UserType == 0)
return false;
// Create a new UserAction object
var action = new UserAction
{
UserName = user.Name,
InstallationId = installationId,
Timestamp = timestamp,
Description = newConfiguration.GetConfigurationString()
};
// Save the configuration change to the database
Db.HandleAction(action);
return true;
}
public static Boolean Delete(this Session? session, Folder? folder)
{

View File

@ -1,18 +0,0 @@
using SQLite;
namespace InnovEnergy.App.Backend.DataTypes;
public class UserAction
{
[PrimaryKey, AutoIncrement]
public Int64 Id { get; set; } // Primary key for the table, auto-incremented
[Indexed]
public String UserName { get; set; } = null!;// User Name who made the configuration change
public Int64 InstallationId { get; set; } // Installation ID where the configuration change is made
public DateTime Timestamp { get; set; } // Timestamp of the configuration change
public String Description { get; set; } = null!;// Serialized string representing the new configuration
}

View File

@ -62,37 +62,6 @@ public static partial class Db
return Insert(o2i);
}
public static Boolean Create(UserAction action)
{
return Insert(action);
}
public static void HandleAction(UserAction newAction)
{
//Find the total number of actions for this installation
var totalActions = UserActions.Count(action => action.InstallationId == newAction.InstallationId);
//If there are 100 actions, remove the one with the oldest timestamp
if (totalActions == 100)
{
var oldestAction =
UserActions.Where(action => action.InstallationId == newAction.InstallationId)
.OrderBy(action => action.Timestamp)
.FirstOrDefault();
//Remove the old action
Delete(oldestAction);
//Add the new action
Create(newAction);
}
else
{
Console.WriteLine("---------------Added the new Error to the database-----------------");
Create(newAction);
}
}
public static void HandleError(Error newError,int installationId)
{
//Find the total number of errors for this installation

View File

@ -36,7 +36,6 @@ public static partial class Db
fileConnection.CreateTable<OrderNumber2Installation>();
fileConnection.CreateTable<Error>();
fileConnection.CreateTable<Warning>();
fileConnection.CreateTable<UserAction>();
return fileConnection;
//return CopyDbToMemory(fileConnection);
@ -56,7 +55,6 @@ public static partial class Db
memoryConnection.CreateTable<OrderNumber2Installation>();
memoryConnection.CreateTable<Error>();
memoryConnection.CreateTable<Warning>();
fileConnection.CreateTable<UserAction>();
//Copy all the existing tables from the disk to main memory
fileConnection.Table<Session>().ForEach(memoryConnection.Insert);
@ -68,7 +66,6 @@ public static partial class Db
fileConnection.Table<OrderNumber2Installation>().ForEach(memoryConnection.Insert);
fileConnection.Table<Error>().ForEach(memoryConnection.Insert);
fileConnection.Table<Warning>().ForEach(memoryConnection.Insert);
fileConnection.Table<UserAction>().ForEach(memoryConnection.Insert);
return memoryConnection;
}
@ -88,7 +85,6 @@ public static partial class Db
public static TableQuery<OrderNumber2Installation> OrderNumber2Installation => Connection.Table<OrderNumber2Installation>();
public static TableQuery<Error> Errors => Connection.Table<Error>();
public static TableQuery<Warning> Warnings => Connection.Table<Warning>();
public static TableQuery<UserAction> UserActions => Connection.Table<UserAction>();
public static void Init()
{
@ -110,7 +106,6 @@ public static partial class Db
Connection.CreateTable<OrderNumber2Installation>();
Connection.CreateTable<Error>();
Connection.CreateTable<Warning>();
Connection.CreateTable<UserAction>();
});
//UpdateKeys();

View File

@ -1,7 +1,6 @@
using InnovEnergy.App.Backend.DataTypes;
using InnovEnergy.App.Backend.DataTypes.Methods;
using InnovEnergy.App.Backend.Relations;
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
namespace InnovEnergy.App.Backend.Database;
@ -50,20 +49,6 @@ public static partial class Db
}
}
public static Boolean Delete(UserAction actionToDelete)
{
var deleteSuccess = RunTransaction(DeleteAction);
if (deleteSuccess)
BackupDatabase();
return deleteSuccess;
Boolean DeleteAction()
{
return UserActions.Delete(action => action.Id == actionToDelete.Id) >0;
}
}
public static Boolean Delete(Warning warningToDelete)
{
var deleteSuccess = RunTransaction(DeleteWarning);