From e9c40979e8f0bf8adaa4f24633448a2c958236b5 Mon Sep 17 00:00:00 2001 From: Mathieu Guindon Date: Sun, 10 Nov 2024 01:57:17 -0500 Subject: [PATCH] adjust feature stack --- .../Api/Features/FeatureViewModel.cs | 10 +++---- .../Api/Features/FeaturesController.cs | 26 +++---------------- .../Data/FeaturesRepository.cs | 1 + .../Services/rubberduckdb/FeatureServices.cs | 2 ++ 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/rubberduckvba.Server/Api/Features/FeatureViewModel.cs b/rubberduckvba.Server/Api/Features/FeatureViewModel.cs index 6211158..12b9220 100644 --- a/rubberduckvba.Server/Api/Features/FeatureViewModel.cs +++ b/rubberduckvba.Server/Api/Features/FeatureViewModel.cs @@ -20,11 +20,7 @@ public FeatureViewModel(Feature model) if (model is FeatureGraph graph) { - FeatureId = graph.ParentId; - FeatureName = graph.ParentName; - FeatureTitle = graph.ParentTitle; - - Features = graph.Features.Select(e => new FeatureViewModel(e)).ToArray(); + Features = graph.Features.Select(e => new FeatureViewModel(e) { FeatureId = e.ParentId, FeatureName = graph.Name, FeatureTitle = graph.Title }).ToArray(); Inspections = graph.Inspections.ToArray(); } } @@ -34,8 +30,8 @@ public FeatureViewModel(Feature model) public DateTime? DateUpdated { get; init; } public int? FeatureId { get; init; } - public string FeatureName { get; init; } - public string FeatureTitle { get; init; } + public string? FeatureName { get; init; } + public string? FeatureTitle { get; init; } public string Name { get; init; } public string Title { get; init; } diff --git a/rubberduckvba.Server/Api/Features/FeaturesController.cs b/rubberduckvba.Server/Api/Features/FeaturesController.cs index 3832084..43f60c1 100644 --- a/rubberduckvba.Server/Api/Features/FeaturesController.cs +++ b/rubberduckvba.Server/Api/Features/FeaturesController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using rubberduckvba.Server.Model; using rubberduckvba.Server.Services; +using rubberduckvba.Server.Services.rubberduckdb; using System.ComponentModel; using System.Reflection; @@ -16,7 +17,7 @@ public record class MarkdownFormattingRequestViewModel [ApiController] [AllowAnonymous] -public class FeaturesController(IRubberduckDbService db, IMarkdownFormattingService md, ICacheService cache) : ControllerBase +public class FeaturesController(IRubberduckDbService db, FeatureServices features, IMarkdownFormattingService md, ICacheService cache) : ControllerBase { private static RepositoryOptionViewModel[] RepositoryOptions { get; } = Enum.GetValues().Select(e => new RepositoryOptionViewModel { Id = e, Name = e.ToString() }).ToArray(); @@ -58,32 +59,13 @@ public async Task> Info([FromRoute] string name) // return cached; //} - var feature = await db.ResolveFeature(RepositoryId.Rubberduck, name); + var feature = features.Get(name); if (feature is null) { return NotFound(); } - var model = new FeatureViewModel(feature with - { - Description = feature.Description, - ShortDescription = feature.ShortDescription, - - ParentId = feature.Id, - ParentName = feature.Name, - ParentTitle = feature.Title, - - Features = feature.Features.Select(subFeature => subFeature with - { - Description = subFeature.Description, - ShortDescription = subFeature.ShortDescription - }).ToArray(), - - Inspections = feature.Inspections, - QuickFixes = feature.QuickFixes, - Annotations = feature.Annotations, - }); - + var model = new FeatureViewModel(feature); //cache.Write(HttpContext.Request.Path, model); return Ok(model); } diff --git a/rubberduckvba.Server/Data/FeaturesRepository.cs b/rubberduckvba.Server/Data/FeaturesRepository.cs index be7dc6b..94cb0b8 100644 --- a/rubberduckvba.Server/Data/FeaturesRepository.cs +++ b/rubberduckvba.Server/Data/FeaturesRepository.cs @@ -9,6 +9,7 @@ public FeaturesRepository(IOptions settings) : base(settings) { } protected override string TableName { get; } = "Features"; + protected override string? ParentFKColumnName { get; } = "ParentId"; protected override string SelectSql { get; } = @" SELECT diff --git a/rubberduckvba.Server/Services/rubberduckdb/FeatureServices.cs b/rubberduckvba.Server/Services/rubberduckdb/FeatureServices.cs index ec5b1af..44402a4 100644 --- a/rubberduckvba.Server/Services/rubberduckdb/FeatureServices.cs +++ b/rubberduckvba.Server/Services/rubberduckdb/FeatureServices.cs @@ -22,6 +22,7 @@ public FeatureGraph Get(string name) { var id = featureRepository.GetId(name); var feature = featureRepository.GetById(id); + var children = featureRepository.GetAll(parentId: id).Select(e => new Feature(e)); IEnumerable inspections = []; IEnumerable quickfixes = []; @@ -42,6 +43,7 @@ public FeatureGraph Get(string name) return new FeatureGraph(feature) { + Features = children, Annotations = annotations, QuickFixes = quickfixes, Inspections = inspections,