Skip to content

Commit e9c4097

Browse files
committed
adjust feature stack
1 parent b8231f2 commit e9c4097

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

rubberduckvba.Server/Api/Features/FeatureViewModel.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ public FeatureViewModel(Feature model)
2020

2121
if (model is FeatureGraph graph)
2222
{
23-
FeatureId = graph.ParentId;
24-
FeatureName = graph.ParentName;
25-
FeatureTitle = graph.ParentTitle;
26-
27-
Features = graph.Features.Select(e => new FeatureViewModel(e)).ToArray();
23+
Features = graph.Features.Select(e => new FeatureViewModel(e) { FeatureId = e.ParentId, FeatureName = graph.Name, FeatureTitle = graph.Title }).ToArray();
2824
Inspections = graph.Inspections.ToArray();
2925
}
3026
}
@@ -34,8 +30,8 @@ public FeatureViewModel(Feature model)
3430
public DateTime? DateUpdated { get; init; }
3531

3632
public int? FeatureId { get; init; }
37-
public string FeatureName { get; init; }
38-
public string FeatureTitle { get; init; }
33+
public string? FeatureName { get; init; }
34+
public string? FeatureTitle { get; init; }
3935

4036
public string Name { get; init; }
4137
public string Title { get; init; }

rubberduckvba.Server/Api/Features/FeaturesController.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Mvc;
33
using rubberduckvba.Server.Model;
44
using rubberduckvba.Server.Services;
5+
using rubberduckvba.Server.Services.rubberduckdb;
56
using System.ComponentModel;
67
using System.Reflection;
78

@@ -16,7 +17,7 @@ public record class MarkdownFormattingRequestViewModel
1617

1718
[ApiController]
1819
[AllowAnonymous]
19-
public class FeaturesController(IRubberduckDbService db, IMarkdownFormattingService md, ICacheService cache) : ControllerBase
20+
public class FeaturesController(IRubberduckDbService db, FeatureServices features, IMarkdownFormattingService md, ICacheService cache) : ControllerBase
2021
{
2122
private static RepositoryOptionViewModel[] RepositoryOptions { get; } =
2223
Enum.GetValues<RepositoryId>().Select(e => new RepositoryOptionViewModel { Id = e, Name = e.ToString() }).ToArray();
@@ -58,32 +59,13 @@ public async Task<ActionResult<FeatureViewModel>> Info([FromRoute] string name)
5859
// return cached;
5960
//}
6061

61-
var feature = await db.ResolveFeature(RepositoryId.Rubberduck, name);
62+
var feature = features.Get(name);
6263
if (feature is null)
6364
{
6465
return NotFound();
6566
}
6667

67-
var model = new FeatureViewModel(feature with
68-
{
69-
Description = feature.Description,
70-
ShortDescription = feature.ShortDescription,
71-
72-
ParentId = feature.Id,
73-
ParentName = feature.Name,
74-
ParentTitle = feature.Title,
75-
76-
Features = feature.Features.Select(subFeature => subFeature with
77-
{
78-
Description = subFeature.Description,
79-
ShortDescription = subFeature.ShortDescription
80-
}).ToArray(),
81-
82-
Inspections = feature.Inspections,
83-
QuickFixes = feature.QuickFixes,
84-
Annotations = feature.Annotations,
85-
});
86-
68+
var model = new FeatureViewModel(feature);
8769
//cache.Write(HttpContext.Request.Path, model);
8870
return Ok(model);
8971
}

rubberduckvba.Server/Data/FeaturesRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public FeaturesRepository(IOptions<ConnectionSettings> settings)
99
: base(settings) { }
1010

1111
protected override string TableName { get; } = "Features";
12+
protected override string? ParentFKColumnName { get; } = "ParentId";
1213

1314
protected override string SelectSql { get; } = @"
1415
SELECT

rubberduckvba.Server/Services/rubberduckdb/FeatureServices.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public FeatureGraph Get(string name)
2222
{
2323
var id = featureRepository.GetId(name);
2424
var feature = featureRepository.GetById(id);
25+
var children = featureRepository.GetAll(parentId: id).Select(e => new Feature(e));
2526

2627
IEnumerable<Inspection> inspections = [];
2728
IEnumerable<QuickFix> quickfixes = [];
@@ -42,6 +43,7 @@ public FeatureGraph Get(string name)
4243

4344
return new FeatureGraph(feature)
4445
{
46+
Features = children,
4547
Annotations = annotations,
4648
QuickFixes = quickfixes,
4749
Inspections = inspections,

0 commit comments

Comments
 (0)