Skip to content

Commit

Permalink
adjust feature stack
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Nov 10, 2024
1 parent b8231f2 commit e9c4097
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
10 changes: 3 additions & 7 deletions rubberduckvba.Server/Api/Features/FeatureViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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; }
Expand Down
26 changes: 4 additions & 22 deletions rubberduckvba.Server/Api/Features/FeaturesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<RepositoryId>().Select(e => new RepositoryOptionViewModel { Id = e, Name = e.ToString() }).ToArray();
Expand Down Expand Up @@ -58,32 +59,13 @@ public async Task<ActionResult<FeatureViewModel>> 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);
}
Expand Down
1 change: 1 addition & 0 deletions rubberduckvba.Server/Data/FeaturesRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public FeaturesRepository(IOptions<ConnectionSettings> settings)
: base(settings) { }

protected override string TableName { get; } = "Features";
protected override string? ParentFKColumnName { get; } = "ParentId";

protected override string SelectSql { get; } = @"
SELECT
Expand Down
2 changes: 2 additions & 0 deletions rubberduckvba.Server/Services/rubberduckdb/FeatureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Inspection> inspections = [];
IEnumerable<QuickFix> quickfixes = [];
Expand All @@ -42,6 +43,7 @@ public FeatureGraph Get(string name)

return new FeatureGraph(feature)
{
Features = children,
Annotations = annotations,
QuickFixes = quickfixes,
Inspections = inspections,
Expand Down

0 comments on commit e9c4097

Please sign in to comment.