diff --git a/csharp/App/Backend/Controllers/Controller.cs b/csharp/App/Backend/Controllers/Controller.cs index 1aac55752..9136ac151 100644 --- a/csharp/App/Backend/Controllers/Controller.cs +++ b/csharp/App/Backend/Controllers/Controller.cs @@ -1,14 +1,14 @@ using System.Net; using System.Text; -using Innovenergy.Backend.Database; -using Innovenergy.Backend.Model; -using Innovenergy.Backend.Model.Relations; -using Innovenergy.Backend.Utils; +using InnovEnergy.App.Backend.Database; +using InnovEnergy.App.Backend.Model; +using InnovEnergy.App.Backend.Model.Relations; +using InnovEnergy.App.Backend.Utils; using InnovEnergy.Lib.Utils; using Microsoft.AspNetCore.Mvc; using HttpContextAccessor = Microsoft.AspNetCore.Http.HttpContextAccessor; -namespace Innovenergy.Backend.Controllers; +namespace InnovEnergy.App.Backend.Controllers; [ApiController] [Route("api/")] @@ -174,8 +174,7 @@ public class Controller using var db = Db.Connect(); var folders = db - .GetDirectlyAccessibleFolders(caller) - .Do(f => f.ParentId = 0) // ReSharper disable once AccessToDisposedClosure + .GetDirectlyAccessibleFolders(caller) // ReSharper disable once AccessToDisposedClosure .Select(f => PopulateChildren(db, f)); var installations = db.GetDirectlyAccessibleInstallations(caller); @@ -185,6 +184,25 @@ public class Controller .ToList(); // important! } + [Returns] // assuming swagger knows about arrays but not lists (JSON) + [Returns(HttpStatusCode.Unauthorized)] + [HttpGet($"{nameof(GetAllFoldersAndInstallations)}/")] + public Object GetAllFoldersAndInstallations() + { + var caller = GetCaller(); + if (caller == null) + return new HttpResponseMessage(HttpStatusCode.Unauthorized); + + using var db = Db.Connect(); + + var folders = db.GetAllAccessibleFolders(caller) as IEnumerable; + var installations = db.GetAllAccessibleInstallations(caller); + + return folders + .Concat(installations) + .ToList(); // important! + } + private static Folder PopulateChildren(Db db, Folder folder, HashSet? hs = null) { // TODO: remove cycle detector diff --git a/csharp/App/Backend/Controllers/Credentials.cs b/csharp/App/Backend/Controllers/Credentials.cs index 2c5c72b45..f3149f7e8 100644 --- a/csharp/App/Backend/Controllers/Credentials.cs +++ b/csharp/App/Backend/Controllers/Credentials.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; -namespace Innovenergy.Backend.Controllers; +namespace InnovEnergy.App.Backend.Controllers; [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] public record Credentials(String Username, String Password); \ No newline at end of file diff --git a/csharp/App/Backend/Controllers/ReturnsAttribute.cs b/csharp/App/Backend/Controllers/ReturnsAttribute.cs index 6d94088f5..2ef924055 100644 --- a/csharp/App/Backend/Controllers/ReturnsAttribute.cs +++ b/csharp/App/Backend/Controllers/ReturnsAttribute.cs @@ -1,7 +1,7 @@ using System.Net; using Microsoft.AspNetCore.Mvc; -namespace Innovenergy.Backend.Controllers; +namespace InnovEnergy.App.Backend.Controllers; public class ReturnsAttribute : ProducesResponseTypeAttribute { diff --git a/csharp/App/Backend/Database/Db.cs b/csharp/App/Backend/Database/Db.cs index aaabfbfd9..1625c128f 100644 --- a/csharp/App/Backend/Database/Db.cs +++ b/csharp/App/Backend/Database/Db.cs @@ -1,11 +1,11 @@ using System.Diagnostics.CodeAnalysis; -using Innovenergy.Backend.Model; -using Innovenergy.Backend.Model.Relations; -using Innovenergy.Backend.Utils; +using InnovEnergy.App.Backend.Model; +using InnovEnergy.App.Backend.Model.Relations; +using InnovEnergy.App.Backend.Utils; using InnovEnergy.Lib.Utils; using SQLite; -namespace Innovenergy.Backend.Database; +namespace InnovEnergy.App.Backend.Database; public partial class Db : IDisposable { @@ -97,8 +97,6 @@ public partial class Db : IDisposable return direct.Concat(fromFolders); } - - public IEnumerable GetAllAccessibleFolders(User user) { @@ -113,7 +111,8 @@ public partial class Db : IDisposable .Where(r => r.UserId == user.Id) .Select(r => r.InstallationId) .Select(GetInstallationById) - .NotNull(); + .NotNull() + .Do(i => i.ParentId = 0); // hide inaccessible parents from calling user } public IEnumerable GetDirectlyAccessibleFolders(User user) @@ -122,7 +121,8 @@ public partial class Db : IDisposable .Where(r => r.UserId == user.Id) .Select(r => r.FolderId) .Select(GetFolderById) - .NotNull(); + .NotNull() + .Do(i => i.ParentId = 0); // hide inaccessible parents from calling user; } public Result AddToAccessibleInstallations(Int64 userId, Int64 updatedInstallationId) diff --git a/csharp/App/Backend/Database/Fake.cs b/csharp/App/Backend/Database/Fake.cs index 427c78434..63fff39ee 100644 --- a/csharp/App/Backend/Database/Fake.cs +++ b/csharp/App/Backend/Database/Fake.cs @@ -1,6 +1,6 @@ -using Innovenergy.Backend.Model.Relations; +using InnovEnergy.App.Backend.Model.Relations; -namespace Innovenergy.Backend.Database; +namespace InnovEnergy.App.Backend.Database; public partial class Db { diff --git a/csharp/App/Backend/Database/Folder.cs b/csharp/App/Backend/Database/Folder.cs index 34e20f529..8a4785639 100644 --- a/csharp/App/Backend/Database/Folder.cs +++ b/csharp/App/Backend/Database/Folder.cs @@ -1,9 +1,9 @@ -using Innovenergy.Backend.Model; -using Innovenergy.Backend.Utils; +using InnovEnergy.App.Backend.Model; +using InnovEnergy.App.Backend.Utils; using InnovEnergy.Lib.Utils; using SQLite; -namespace Innovenergy.Backend.Database; +namespace InnovEnergy.App.Backend.Database; public partial class Db { diff --git a/csharp/App/Backend/Database/Installation.cs b/csharp/App/Backend/Database/Installation.cs index a362a39df..6e554f483 100644 --- a/csharp/App/Backend/Database/Installation.cs +++ b/csharp/App/Backend/Database/Installation.cs @@ -1,8 +1,8 @@ -using Innovenergy.Backend.Model; -using Innovenergy.Backend.Utils; +using InnovEnergy.App.Backend.Model; +using InnovEnergy.App.Backend.Utils; using SQLite; -namespace Innovenergy.Backend.Database; +namespace InnovEnergy.App.Backend.Database; public partial class Db { diff --git a/csharp/App/Backend/Database/User.cs b/csharp/App/Backend/Database/User.cs index ea2344aaf..0719ab9fe 100644 --- a/csharp/App/Backend/Database/User.cs +++ b/csharp/App/Backend/Database/User.cs @@ -2,18 +2,17 @@ using System.Diagnostics.CodeAnalysis; using System.Net.Mail; using System.Security.Cryptography; using System.Text; -using System.Text.Json; using System.Text.Json.Nodes; using Flurl.Http; -using Innovenergy.Backend.Model; -using Innovenergy.Backend.Utils; +using InnovEnergy.App.Backend.Model; +using InnovEnergy.App.Backend.Utils; using InnovEnergy.Lib.Utils; using SQLite; #pragma warning disable CS0472 #pragma warning disable CS8602 -namespace Innovenergy.Backend.Database; +namespace InnovEnergy.App.Backend.Database; public partial class Db { diff --git a/csharp/App/Backend/Database/User2Folder.cs b/csharp/App/Backend/Database/User2Folder.cs index 465eea722..29351f1dd 100644 --- a/csharp/App/Backend/Database/User2Folder.cs +++ b/csharp/App/Backend/Database/User2Folder.cs @@ -1,7 +1,7 @@ -using Innovenergy.Backend.Model.Relations; +using InnovEnergy.App.Backend.Model.Relations; using SQLite; -namespace Innovenergy.Backend.Database; +namespace InnovEnergy.App.Backend.Database; public partial class Db { diff --git a/csharp/App/Backend/Database/User2Installation.cs b/csharp/App/Backend/Database/User2Installation.cs index ca329deee..069588d7c 100644 --- a/csharp/App/Backend/Database/User2Installation.cs +++ b/csharp/App/Backend/Database/User2Installation.cs @@ -1,7 +1,7 @@ -using Innovenergy.Backend.Model.Relations; +using InnovEnergy.App.Backend.Model.Relations; using SQLite; -namespace Innovenergy.Backend.Database; +namespace InnovEnergy.App.Backend.Database; public partial class Db { diff --git a/csharp/App/Backend/HeaderFilter.cs b/csharp/App/Backend/HeaderFilter.cs index 8ca9cdff8..f3520b75e 100644 --- a/csharp/App/Backend/HeaderFilter.cs +++ b/csharp/App/Backend/HeaderFilter.cs @@ -1,7 +1,7 @@ using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; -namespace Innovenergy.Backend; +namespace InnovEnergy.App.Backend; /// /// This is for convenient testing! Todo throw me out? diff --git a/csharp/App/Backend/Model/Folder.cs b/csharp/App/Backend/Model/Folder.cs index c9c39c594..041c0f479 100644 --- a/csharp/App/Backend/Model/Folder.cs +++ b/csharp/App/Backend/Model/Folder.cs @@ -1,4 +1,4 @@ -namespace Innovenergy.Backend.Model; +namespace InnovEnergy.App.Backend.Model; public class Folder : TreeNode { diff --git a/csharp/App/Backend/Model/Installation.cs b/csharp/App/Backend/Model/Installation.cs index 4cca94295..b9858e9c8 100644 --- a/csharp/App/Backend/Model/Installation.cs +++ b/csharp/App/Backend/Model/Installation.cs @@ -1,4 +1,4 @@ -namespace Innovenergy.Backend.Model; +namespace InnovEnergy.App.Backend.Model; public class Installation : TreeNode diff --git a/csharp/App/Backend/Model/Relations/Relation.cs b/csharp/App/Backend/Model/Relations/Relation.cs index 31250df14..a791a4609 100644 --- a/csharp/App/Backend/Model/Relations/Relation.cs +++ b/csharp/App/Backend/Model/Relations/Relation.cs @@ -1,7 +1,7 @@ using System.Diagnostics.CodeAnalysis; using SQLite; -namespace Innovenergy.Backend.Model.Relations; +namespace InnovEnergy.App.Backend.Model.Relations; public abstract class Relation { diff --git a/csharp/App/Backend/Model/Relations/Session.cs b/csharp/App/Backend/Model/Relations/Session.cs index ff64b6644..829cc9a60 100644 --- a/csharp/App/Backend/Model/Relations/Session.cs +++ b/csharp/App/Backend/Model/Relations/Session.cs @@ -1,6 +1,6 @@ using SQLite; -namespace Innovenergy.Backend.Model.Relations; +namespace InnovEnergy.App.Backend.Model.Relations; public class Session : Relation { diff --git a/csharp/App/Backend/Model/Relations/User2Folder.cs b/csharp/App/Backend/Model/Relations/User2Folder.cs index 6e9f56433..f93cab568 100644 --- a/csharp/App/Backend/Model/Relations/User2Folder.cs +++ b/csharp/App/Backend/Model/Relations/User2Folder.cs @@ -1,6 +1,6 @@ using SQLite; -namespace Innovenergy.Backend.Model.Relations; +namespace InnovEnergy.App.Backend.Model.Relations; internal class User2Folder : Relation { diff --git a/csharp/App/Backend/Model/Relations/User2Installation.cs b/csharp/App/Backend/Model/Relations/User2Installation.cs index 43fa45d0e..fcd2760dd 100644 --- a/csharp/App/Backend/Model/Relations/User2Installation.cs +++ b/csharp/App/Backend/Model/Relations/User2Installation.cs @@ -1,6 +1,6 @@ using SQLite; -namespace Innovenergy.Backend.Model.Relations; +namespace InnovEnergy.App.Backend.Model.Relations; internal class User2Installation : Relation { diff --git a/csharp/App/Backend/Model/TreeNode.Equality.cs b/csharp/App/Backend/Model/TreeNode.Equality.cs index b044a020f..f37cd51d7 100644 --- a/csharp/App/Backend/Model/TreeNode.Equality.cs +++ b/csharp/App/Backend/Model/TreeNode.Equality.cs @@ -1,12 +1,13 @@ using System.Diagnostics.CodeAnalysis; -namespace Innovenergy.Backend.Model; +namespace InnovEnergy.App.Backend.Model; public abstract partial class TreeNode { + // Note: Only consider Id, but not ParentId for TreeNode equality checks protected Boolean Equals(TreeNode other) { - return Id == other.Id && ParentId == other.ParentId; + return Id == other.Id; } public override Boolean Equals(Object? obj) @@ -17,8 +18,5 @@ public abstract partial class TreeNode } [SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] - public override Int32 GetHashCode() - { - return HashCode.Combine(Id, ParentId); - } + public override Int32 GetHashCode() => Id.GetHashCode(); } \ No newline at end of file diff --git a/csharp/App/Backend/Model/TreeNode.cs b/csharp/App/Backend/Model/TreeNode.cs index b3cf22170..d02890a62 100644 --- a/csharp/App/Backend/Model/TreeNode.cs +++ b/csharp/App/Backend/Model/TreeNode.cs @@ -1,6 +1,6 @@ using SQLite; -namespace Innovenergy.Backend.Model; +namespace InnovEnergy.App.Backend.Model; public abstract partial class TreeNode { diff --git a/csharp/App/Backend/Model/User.cs b/csharp/App/Backend/Model/User.cs index a1a0be392..762c819a4 100644 --- a/csharp/App/Backend/Model/User.cs +++ b/csharp/App/Backend/Model/User.cs @@ -1,6 +1,6 @@ using SQLite; -namespace Innovenergy.Backend.Model; +namespace InnovEnergy.App.Backend.Model; public class User : TreeNode { diff --git a/csharp/App/Backend/Program.cs b/csharp/App/Backend/Program.cs index fd0206737..ae662b779 100644 --- a/csharp/App/Backend/Program.cs +++ b/csharp/App/Backend/Program.cs @@ -1,7 +1,7 @@ -using Innovenergy.Backend.Database; +using InnovEnergy.App.Backend.Database; using Microsoft.OpenApi.Models; -namespace Innovenergy.Backend; +namespace InnovEnergy.App.Backend; public static class Program { diff --git a/csharp/App/Backend/Utils/Crypto.cs b/csharp/App/Backend/Utils/Crypto.cs index 199b17fb9..c176fd284 100644 --- a/csharp/App/Backend/Utils/Crypto.cs +++ b/csharp/App/Backend/Utils/Crypto.cs @@ -1,6 +1,6 @@ using System.Security.Cryptography; -namespace Innovenergy.Backend.Utils; +namespace InnovEnergy.App.Backend.Utils; public static class Crypto { diff --git a/csharp/App/Backend/Utils/Result.cs b/csharp/App/Backend/Utils/Result.cs index 21e85876c..979e9184e 100644 --- a/csharp/App/Backend/Utils/Result.cs +++ b/csharp/App/Backend/Utils/Result.cs @@ -1,4 +1,4 @@ -namespace Innovenergy.Backend.Utils; +namespace InnovEnergy.App.Backend.Utils; public class Result {