diff --git a/src/Controllers/AssetsController.cs b/src/Controllers/AssetsController.cs index 584e3ae..adb7031 100644 --- a/src/Controllers/AssetsController.cs +++ b/src/Controllers/AssetsController.cs @@ -20,18 +20,35 @@ public class AssetsController : Controller _logger = logger; } - [HttpGet("GetAll")] - public async Task GetAllAssetModelAsync() + [HttpGet("Get")] + public async Task GetAllAssetModelAsync(string Cn) { - AssetsIndexResponseModel result; + AssetsGetResponseModel result; try { - var assetList = await _ldap.ListDeviceAsync(); - result = new AssetsIndexResponseModel(successful: true, assetsModel: assetList); + var assetList = await _ldap.ListDeviceAsync(Cn); + result = new AssetsGetResponseModel(successful: true, assetModel: assetList); } catch (Exception e) { - result = new AssetsIndexResponseModel(successful: false, exception: e.Message); + result = new AssetsGetResponseModel(successful: false, exception: e.Message); + } + + return result; + } + + [HttpGet("GetAll")] + public async Task GetAllAssetModelAsync() + { + AssetsGetAllResponseModel result; + try + { + var assetList = await _ldap.ListDeviceAsync(); + result = new AssetsGetAllResponseModel(successful: true, assetsModel: assetList); + } + catch (Exception e) + { + result = new AssetsGetAllResponseModel(successful: false, exception: e.Message); } return result; @@ -121,7 +138,7 @@ public class AssetsController : Controller } [HttpPatch("Update")] - public async Task Update(AssetsModifyRequestModel requestModel) + public async Task Update([FromBody]AssetsModifyRequestModel requestModel) { AssetsUpdateResponseModel result; if (requestModel is null) @@ -161,6 +178,10 @@ public class AssetsController : Controller { AssetModel? asset = null; asset = await _ldap.GetAssetByCnAsync(cn); + if (asset.Description is null) + { + asset.Description = new(); + } AttributesHelper.UpdateNonNullProperties(requestModel.Description, asset.Description); await _ldap.UpdateAsset(cn, "description", JsonSerializer.Serialize(requestModel.Description)); } diff --git a/src/Models/AssetsModel.cs b/src/Models/AssetsModel.cs index 632776f..80bf3cd 100644 --- a/src/Models/AssetsModel.cs +++ b/src/Models/AssetsModel.cs @@ -1,15 +1,22 @@ namespace Berufsschule_HAM.Models; using System.Text.Json; +using System.Text.Json.Serialization; using Berufsschule_HAM.Exceptions; public class AssetModel { + [JsonPropertyName("Cn")] public required string Cn { get; set; } + [JsonPropertyName("SerialNumber")] public string? SerialNumber { get; set; } + [JsonPropertyName("Description")] public AssetDescription? Description { get; set; } + [JsonPropertyName("Location")] public string? Location { get; set; } + [JsonPropertyName("Owner")] public string? Owner { get; set; } + [JsonPropertyName("Name")] public string? Name { get; set; } public AssetModel(Dictionary ldapData) @@ -33,18 +40,27 @@ public class AssetModel public class AssetDescription { + [JsonPropertyName("Type")] public string? Type { get; set; } + [JsonPropertyName("Make")] public string? Make { get; set; } + [JsonPropertyName("Model")] public string? Model { get; set; } + [JsonPropertyName("Attributes")] public Dictionary? Attributes { get; set; } + [JsonPropertyName("Purchase")] public AssetPurchase? Purchase { get; set; } } public class AssetPurchase { + [JsonPropertyName("PurchaseDate")] public string? PurchaseDate { get; set; } + [JsonPropertyName("PurchaseValue")] public string? PurchaseValue { get; set; } + [JsonPropertyName("PurchaseAt")] public string? PurchasedAt { get; set; } + [JsonPropertyName("PurchaseBy")] public string? PurchasedBy { get; set; } } diff --git a/src/Models/AssetsResponseModel.cs b/src/Models/AssetsResponseModel.cs index e9a899e..d2577f2 100644 --- a/src/Models/AssetsResponseModel.cs +++ b/src/Models/AssetsResponseModel.cs @@ -21,7 +21,7 @@ public class AssetsDeleteResponseModel(bool successful, string exception = "None public string? Exception { get; set; } = exception; } -public class AssetsIndexResponseModel(bool successful, IEnumerable? assetsModel = null, string exception = "None") +public class AssetsGetAllResponseModel(bool successful, IEnumerable? assetsModel = null, string exception = "None") { public bool Success { get; set; } = successful; @@ -30,3 +30,12 @@ public class AssetsIndexResponseModel(bool successful, IEnumerable? public string? Exception { get; set; } = exception; } +public class AssetsGetResponseModel(bool successful, AssetModel? assetModel = null, string exception = "None") +{ + public bool Success { get; set; } = successful; + + public AssetModel? AssetsModel { get; set; } = assetModel; + + public string? Exception { get; set; } = exception; +} + diff --git a/src/Program.cs b/src/Program.cs index 7d76ef1..0dad9d7 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -45,6 +45,22 @@ builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationSc options.AccessDeniedPath = "/Home/AccessDenied"; }); +builder.Services.AddResponseCompression(options => +{ + options.EnableForHttps = true; + options.MimeTypes = new[] + { + "text/plain", + "text/css", + "application/javascript", + "text/html", + "application/xml", + "text/xml", + "application/json", + "image/svg+xml" + }; +}); + var app = builder.Build(); if (!app.Environment.IsDevelopment()) @@ -76,6 +92,7 @@ if (app.Environment.IsDevelopment()) app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); +app.UseResponseCompression(); string[] supportedCultures = ["de", "en"]; var localizationOptions = new RequestLocalizationOptions() diff --git a/src/Services/LdapService.cs b/src/Services/LdapService.cs index 76416e6..65e37e3 100644 --- a/src/Services/LdapService.cs +++ b/src/Services/LdapService.cs @@ -186,9 +186,18 @@ public partial class LdapService : IDisposable { IEnumerable> devices = await ListObjectBy(AssetsBaseDn, "(objectClass=device)", AssetsAttributes); List models = []; - devices.ToList().ForEach(x => models.Add(new AssetModel(x) {Cn = x["cn"]})); + devices.ToList().ForEach(x => models.Add(new AssetModel(x) { Cn = x["cn"] })); return models; } + + public async Task ListDeviceAsync(string Cn) + { + IEnumerable> devices = await ListObjectBy(AssetsBaseDn, $"(objectClass=device)", AssetsAttributes); + Dictionary entry = devices.ToList().First(x => x.GetValueOrDefault("cn") != null && x["cn"] == Cn); + AssetModel model = new(entry) { Cn = entry["cn"] }; + + return model; + } public async Task CreateUser(string uid, LdapAttributeSet attributeSet) { diff --git a/src/Views/Home/Assets.cshtml b/src/Views/Home/Assets.cshtml index 9f59067..354d0cd 100644 --- a/src/Views/Home/Assets.cshtml +++ b/src/Views/Home/Assets.cshtml @@ -40,12 +40,17 @@ @assetsTableViewModel.LocationName
- +
@@ -343,4 +348,245 @@ }); }); }); + + + + + + \ No newline at end of file diff --git a/src/Views/Shared/_Layout.cshtml b/src/Views/Shared/_Layout.cshtml index 3d07f61..2c00a9d 100644 --- a/src/Views/Shared/_Layout.cshtml +++ b/src/Views/Shared/_Layout.cshtml @@ -7,8 +7,12 @@ @ViewData["Title"] - Berufsschule_HAM - + @* *@ + + @@ -67,8 +71,12 @@ © 2025 - Berufsschule_HAM - - + @* *@ + + @* *@ + @await RenderSectionAsync("Scripts", required: false)