From bbc96ae3e6093f710c10036d535d8bf0b69831d7 Mon Sep 17 00:00:00 2001 From: sadq Date: Tue, 27 Aug 2024 10:34:40 +0330 Subject: [PATCH 1/5] add new class and controller --- .../Controllers/NodeController.cs | 9 +++- .../Dto/Graph/ExpansionDto.cs | 15 ++++++ .../Abstraction/IExpansionGraphReceiver.cs | 9 ++++ .../GraphServices/ExpansionGraphReceiver.cs | 46 +++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 RelationshipAnalysis/Dto/Graph/ExpansionDto.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs diff --git a/RelationshipAnalysis/Controllers/NodeController.cs b/RelationshipAnalysis/Controllers/NodeController.cs index b70c9bc..2bab426 100644 --- a/RelationshipAnalysis/Controllers/NodeController.cs +++ b/RelationshipAnalysis/Controllers/NodeController.cs @@ -14,9 +14,16 @@ namespace RelationshipAnalysis.Controllers; public class NodeController( ICreateNodeCategoryService createNodeCategoryService, INodeCategoryReceiver nodeCategoryReceiver, - INodesAdditionService nodesAdditionService) + INodesAdditionService nodesAdditionService, + IExpansionGraphReceiver expansionGraphReceiver) : ControllerBase { + [HttpGet] + public async Task GetExpansionGraph(ExpansionDto expansionDto) + { + var result = await expansionGraphReceiver.GetExpansionGraph(expansionDto); + return StatusCode((int)result.StatusCode, result.Data); + } [HttpGet("categories")] public async Task GetAllNodeCategories() { diff --git a/RelationshipAnalysis/Dto/Graph/ExpansionDto.cs b/RelationshipAnalysis/Dto/Graph/ExpansionDto.cs new file mode 100644 index 0000000..61ef24d --- /dev/null +++ b/RelationshipAnalysis/Dto/Graph/ExpansionDto.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace RelationshipAnalysis.Dto.Graph; + +public class ExpansionDto +{ + [Required] + public int NodeId { get; set; } + [Required] + public int SourceCategoryId { get; set; } + [Required] + public int TargetCategoryId { get; set; } + [Required] + public int EdgeCategoryId { get; set; } +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs new file mode 100644 index 0000000..41d72a7 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs @@ -0,0 +1,9 @@ +using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto.Graph; + +namespace RelationshipAnalysis.Services.GraphServices.Abstraction; + +public interface IExpansionGraphReceiver +{ + Task> GetExpansionGraph(ExpansionDto expansionDto); +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs new file mode 100644 index 0000000..c026e2a --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs @@ -0,0 +1,46 @@ +using Microsoft.EntityFrameworkCore; +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Dto.Graph; +using RelationshipAnalysis.Models.Graph; +using RelationshipAnalysis.Services.GraphServices.Abstraction; + +namespace RelationshipAnalysis.Services.GraphServices; + +public class ExpansionGraphReceiver(IServiceProvider serviceProvider) : IExpansionGraphReceiver +{ + public async Task> GetExpansionGraph(ExpansionDto expansionDto) + { + using var scope = serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + var inputNodes = await GetInputNodes(expansionDto, context); + var outputNodes = await GetOutputNodes(expansionDto, context); + var validEdges = await GetValidEdges(expansionDto, context, inputNodes, outputNodes); + + + } + + private async Task> GetValidEdges(ExpansionDto expansionDto, ApplicationDbContext context, List inputNodes, + List outputNodes) + { + var validEdges = await context.Edges.Where(e => + e.EdgeCategoryId == expansionDto.EdgeCategoryId && + inputNodes.Contains(e.NodeSource) && + outputNodes.Contains(e.NodeDestination)).ToListAsync(); + return validEdges; + } + + private async Task> GetOutputNodes(ExpansionDto expansionDto, ApplicationDbContext context) + { + var outputNodes = + await context.Nodes.Where(n => n.NodeCategoryId == expansionDto.TargetCategoryId).ToListAsync(); + return outputNodes; + } + + private async Task> GetInputNodes(ExpansionDto expansionDto, ApplicationDbContext context) + { + var inputNodes = + await context.Nodes.Where(n => n.NodeCategoryId == expansionDto.SourceCategoryId).ToListAsync(); + return inputNodes; + } +} \ No newline at end of file From 0bd49372705877cefd128d59af306ede5bdfd6d5 Mon Sep 17 00:00:00 2001 From: sadq Date: Tue, 27 Aug 2024 10:45:26 +0330 Subject: [PATCH 2/5] update --- RelationshipAnalysis/Dto/Graph/GraphDto.cs | 4 +-- .../Abstraction/IGraphDtoCreator.cs | 10 +++++++ .../GraphServices/ExpansionGraphReceiver.cs | 7 +++-- .../Services/GraphServices/GraphDtoCreator.cs | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 RelationshipAnalysis/Services/GraphServices/Abstraction/IGraphDtoCreator.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs diff --git a/RelationshipAnalysis/Dto/Graph/GraphDto.cs b/RelationshipAnalysis/Dto/Graph/GraphDto.cs index c4f8a85..e3fe18e 100644 --- a/RelationshipAnalysis/Dto/Graph/GraphDto.cs +++ b/RelationshipAnalysis/Dto/Graph/GraphDto.cs @@ -2,6 +2,6 @@ namespace RelationshipAnalysis.Dto.Graph; public class GraphDto { - public List nodes { get; set; } = new List(); - public List edges { get; set; } = new List(); + public List Nodes { get; set; } = new List(); + public List Edges { get; set; } = new List(); } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/IGraphDtoCreator.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/IGraphDtoCreator.cs new file mode 100644 index 0000000..afc0867 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/IGraphDtoCreator.cs @@ -0,0 +1,10 @@ +using RelationshipAnalysis.Dto.Graph; +using RelationshipAnalysis.Models.Graph; +using Node = AngleSharp.Dom.Node; + +namespace RelationshipAnalysis.Services.GraphServices.Abstraction; + +public interface IGraphDtoCreator +{ + GraphDto CreateResultGraphDto(List contextNodes, List contextEdges); +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs index c026e2a..6cf74c9 100644 --- a/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs @@ -1,3 +1,4 @@ +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; using RelationshipAnalysis.Dto; @@ -7,17 +8,19 @@ namespace RelationshipAnalysis.Services.GraphServices; -public class ExpansionGraphReceiver(IServiceProvider serviceProvider) : IExpansionGraphReceiver +public class ExpansionGraphReceiver(IServiceProvider serviceProvider, IGraphDtoCreator graphDtoCreator, IResponseMessageCreator responseCreator) : IExpansionGraphReceiver { public async Task> GetExpansionGraph(ExpansionDto expansionDto) { using var scope = serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); + var inputNodes = await GetInputNodes(expansionDto, context); var outputNodes = await GetOutputNodes(expansionDto, context); var validEdges = await GetValidEdges(expansionDto, context, inputNodes, outputNodes); - + var resultData = graphDtoCreator.CreateResultGraphDto(inputNodes.Union(outputNodes).ToList(), validEdges); + return responseCreator.Create() } private async Task> GetValidEdges(ExpansionDto expansionDto, ApplicationDbContext context, List inputNodes, diff --git a/RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs b/RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs new file mode 100644 index 0000000..a780761 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs @@ -0,0 +1,28 @@ +using RelationshipAnalysis.Dto.Graph; +using RelationshipAnalysis.Models.Graph; +using RelationshipAnalysis.Services.GraphServices.Abstraction; +using Node = AngleSharp.Dom.Node; + +namespace RelationshipAnalysis.Services.GraphServices; + +public class GraphDtoCreator : IGraphDtoCreator +{ + + public GraphDto CreateResultGraphDto(List contextNodes, List contextEdges) + { + if (contextEdges == null || contextNodes == null) throw new ArgumentNullException(); + var resultGraphDto = new GraphDto(); + contextNodes.ForEach(n => resultGraphDto.Nodes.Add(new NodeDto + { + id = n.NodeId.ToString(), + label = $"{n.NodeCategory.NodeCategoryName}/{n.NodeUniqueString}" + })); + contextEdges.ForEach(e => resultGraphDto.Edges.Add(new EdgeDto + { + id = e.EdgeId.ToString(), + source = e.EdgeSourceNodeId.ToString(), + target = e.EdgeDestinationNodeId.ToString() + })); + return resultGraphDto; + } +} \ No newline at end of file From 1a8424791bf1289e256c288f46ebfdc08f0b4605 Mon Sep 17 00:00:00 2001 From: sadq Date: Tue, 27 Aug 2024 11:40:26 +0330 Subject: [PATCH 3/5] complete expansion graph --- .../Controllers/GraphController.cs | 9 +++++- .../Controllers/NodeController.cs | 9 +----- RelationshipAnalysis/Dto/Graph/GraphDto.cs | 4 +-- RelationshipAnalysis/Program.cs | 4 ++- .../Abstraction/IExpansionGraphReceiver.cs | 3 +- .../GraphServices/ExpansionGraphReceiver.cs | 29 +++++++++---------- .../Services/GraphServices/GraphDtoCreator.cs | 4 +-- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/RelationshipAnalysis/Controllers/GraphController.cs b/RelationshipAnalysis/Controllers/GraphController.cs index b5cf057..ad26917 100644 --- a/RelationshipAnalysis/Controllers/GraphController.cs +++ b/RelationshipAnalysis/Controllers/GraphController.cs @@ -8,11 +8,18 @@ namespace RelationshipAnalysis.Controllers; [ApiController] [Authorize] [Route("api/[controller]")] -public class GraphController(IGraphReceiver graphReceiver) : ControllerBase +public class GraphController(IGraphReceiver graphReceiver, + IExpansionGraphReceiver expansionGraphReceiver) : ControllerBase { [HttpGet] public async Task GetGraph() { return Ok(await graphReceiver.GetGraph()); } + [HttpGet("expansion")] + public async Task GetExpansionGraph(int nodeId, string sourceCategoryName, string targetCategoryName, string edgeCategoryName) + { + var result = await expansionGraphReceiver.GetExpansionGraph(nodeId, sourceCategoryName, targetCategoryName, edgeCategoryName); + return Ok(result); + } } \ No newline at end of file diff --git a/RelationshipAnalysis/Controllers/NodeController.cs b/RelationshipAnalysis/Controllers/NodeController.cs index 2bab426..b70c9bc 100644 --- a/RelationshipAnalysis/Controllers/NodeController.cs +++ b/RelationshipAnalysis/Controllers/NodeController.cs @@ -14,16 +14,9 @@ namespace RelationshipAnalysis.Controllers; public class NodeController( ICreateNodeCategoryService createNodeCategoryService, INodeCategoryReceiver nodeCategoryReceiver, - INodesAdditionService nodesAdditionService, - IExpansionGraphReceiver expansionGraphReceiver) + INodesAdditionService nodesAdditionService) : ControllerBase { - [HttpGet] - public async Task GetExpansionGraph(ExpansionDto expansionDto) - { - var result = await expansionGraphReceiver.GetExpansionGraph(expansionDto); - return StatusCode((int)result.StatusCode, result.Data); - } [HttpGet("categories")] public async Task GetAllNodeCategories() { diff --git a/RelationshipAnalysis/Dto/Graph/GraphDto.cs b/RelationshipAnalysis/Dto/Graph/GraphDto.cs index e3fe18e..c4f8a85 100644 --- a/RelationshipAnalysis/Dto/Graph/GraphDto.cs +++ b/RelationshipAnalysis/Dto/Graph/GraphDto.cs @@ -2,6 +2,6 @@ namespace RelationshipAnalysis.Dto.Graph; public class GraphDto { - public List Nodes { get; set; } = new List(); - public List Edges { get; set; } = new List(); + public List nodes { get; set; } = new List(); + public List edges { get; set; } = new List(); } \ No newline at end of file diff --git a/RelationshipAnalysis/Program.cs b/RelationshipAnalysis/Program.cs index 69a0c6c..c9f9749 100644 --- a/RelationshipAnalysis/Program.cs +++ b/RelationshipAnalysis/Program.cs @@ -56,7 +56,9 @@ .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddSingleton() + .AddSingleton(); diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs index 41d72a7..255cfaf 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/IExpansionGraphReceiver.cs @@ -5,5 +5,6 @@ namespace RelationshipAnalysis.Services.GraphServices.Abstraction; public interface IExpansionGraphReceiver { - Task> GetExpansionGraph(ExpansionDto expansionDto); + Task GetExpansionGraph(int nodeId, string sourceCategoryName, string targetCategoryName, + string edgeCategoryName); } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs b/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs index 6cf74c9..f9d0015 100644 --- a/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/ExpansionGraphReceiver.cs @@ -1,49 +1,46 @@ -using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.EntityFrameworkCore; using RelationshipAnalysis.Context; -using RelationshipAnalysis.Dto; using RelationshipAnalysis.Dto.Graph; using RelationshipAnalysis.Models.Graph; using RelationshipAnalysis.Services.GraphServices.Abstraction; namespace RelationshipAnalysis.Services.GraphServices; -public class ExpansionGraphReceiver(IServiceProvider serviceProvider, IGraphDtoCreator graphDtoCreator, IResponseMessageCreator responseCreator) : IExpansionGraphReceiver +public class ExpansionGraphReceiver(IServiceProvider serviceProvider, IGraphDtoCreator graphDtoCreator) : IExpansionGraphReceiver { - public async Task> GetExpansionGraph(ExpansionDto expansionDto) + public async Task GetExpansionGraph(int nodeId, string sourceCategoryName, string targetCategoryName, string edgeCategoryName) { using var scope = serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - var inputNodes = await GetInputNodes(expansionDto, context); - var outputNodes = await GetOutputNodes(expansionDto, context); - var validEdges = await GetValidEdges(expansionDto, context, inputNodes, outputNodes); - - var resultData = graphDtoCreator.CreateResultGraphDto(inputNodes.Union(outputNodes).ToList(), validEdges); - return responseCreator.Create() + var inputNodes = await GetInputNodes(sourceCategoryName, context); + var outputNodes = await GetOutputNodes(targetCategoryName, context); + var validEdges = await GetValidEdges(edgeCategoryName, context, inputNodes, outputNodes); + + return graphDtoCreator.CreateResultGraphDto(inputNodes.Union(outputNodes).ToList(), validEdges); } - private async Task> GetValidEdges(ExpansionDto expansionDto, ApplicationDbContext context, List inputNodes, + private async Task> GetValidEdges(string edgeCategoryName, ApplicationDbContext context, List inputNodes, List outputNodes) { var validEdges = await context.Edges.Where(e => - e.EdgeCategoryId == expansionDto.EdgeCategoryId && + e.EdgeCategory.EdgeCategoryName == edgeCategoryName && inputNodes.Contains(e.NodeSource) && outputNodes.Contains(e.NodeDestination)).ToListAsync(); return validEdges; } - private async Task> GetOutputNodes(ExpansionDto expansionDto, ApplicationDbContext context) + private async Task> GetOutputNodes(string targetCategoryName, ApplicationDbContext context) { var outputNodes = - await context.Nodes.Where(n => n.NodeCategoryId == expansionDto.TargetCategoryId).ToListAsync(); + await context.Nodes.Where(n => n.NodeCategory.NodeCategoryName == targetCategoryName).ToListAsync(); return outputNodes; } - private async Task> GetInputNodes(ExpansionDto expansionDto, ApplicationDbContext context) + private async Task> GetInputNodes(string sourceCategoryName, ApplicationDbContext context) { var inputNodes = - await context.Nodes.Where(n => n.NodeCategoryId == expansionDto.SourceCategoryId).ToListAsync(); + await context.Nodes.Where(n => n.NodeCategory.NodeCategoryName == sourceCategoryName).ToListAsync(); return inputNodes; } } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs b/RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs index a780761..02a8db2 100644 --- a/RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs +++ b/RelationshipAnalysis/Services/GraphServices/GraphDtoCreator.cs @@ -12,12 +12,12 @@ public GraphDto CreateResultGraphDto(List contextNodes, List< { if (contextEdges == null || contextNodes == null) throw new ArgumentNullException(); var resultGraphDto = new GraphDto(); - contextNodes.ForEach(n => resultGraphDto.Nodes.Add(new NodeDto + contextNodes.ForEach(n => resultGraphDto.nodes.Add(new NodeDto { id = n.NodeId.ToString(), label = $"{n.NodeCategory.NodeCategoryName}/{n.NodeUniqueString}" })); - contextEdges.ForEach(e => resultGraphDto.Edges.Add(new EdgeDto + contextEdges.ForEach(e => resultGraphDto.edges.Add(new EdgeDto { id = e.EdgeId.ToString(), source = e.EdgeSourceNodeId.ToString(), From 640e1addad396d61b7a27c83fda4aad2f32a19d5 Mon Sep 17 00:00:00 2001 From: sadq Date: Tue, 27 Aug 2024 12:48:32 +0330 Subject: [PATCH 4/5] add inforeceiver class --- .../Services/GraphServices/Abstraction/IInfoReceiver.cs | 8 ++++++++ .../Services/GraphServices/InfoReceiver.cs | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs new file mode 100644 index 0000000..ea766e3 --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs @@ -0,0 +1,8 @@ +using RelationshipAnalysis.Dto; + +namespace RelationshipAnalysis.Services.GraphServices.Abstraction; + +public interface IInfoReceiver +{ + Task +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs new file mode 100644 index 0000000..48aed5f --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs @@ -0,0 +1,8 @@ +using RelationshipAnalysis.Services.GraphServices.Abstraction; + +namespace RelationshipAnalysis.Services.GraphServices; + +public class InfoReceiver : IInfoReceiver +{ + +} \ No newline at end of file From 6fb018973e79303d05ff1a6ba390fa8b5051b703 Mon Sep 17 00:00:00 2001 From: sadq Date: Tue, 27 Aug 2024 14:44:59 +0330 Subject: [PATCH 5/5] add get info for nodes and edges --- .../Controllers/EdgeController.cs | 11 ++++- .../Controllers/NodeController.cs | 9 +++- RelationshipAnalysis/Program.cs | 4 +- .../Abstraction/IInfoReceiver.cs | 2 +- .../GraphServices/EdgeInfoReceiver.cs | 41 ++++++++++++++++++ .../Services/GraphServices/InfoReceiver.cs | 8 ---- .../GraphServices/NodeInfoReceiver.cs | 42 +++++++++++++++++++ 7 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 RelationshipAnalysis/Services/GraphServices/EdgeInfoReceiver.cs delete mode 100644 RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs create mode 100644 RelationshipAnalysis/Services/GraphServices/NodeInfoReceiver.cs diff --git a/RelationshipAnalysis/Controllers/EdgeController.cs b/RelationshipAnalysis/Controllers/EdgeController.cs index 5734321..5a5d8d5 100644 --- a/RelationshipAnalysis/Controllers/EdgeController.cs +++ b/RelationshipAnalysis/Controllers/EdgeController.cs @@ -14,7 +14,8 @@ namespace RelationshipAnalysis.Controllers; public class EdgeController( ICreateEdgeCategoryService createEdgeCategoryService, IEdgeCategoryReceiver edgeCategoryReceiver, - IEdgesAdditionService edgesAdditionService) + IEdgesAdditionService edgesAdditionService, + [FromKeyedServices("edge")] IInfoReceiver infoReceiver) : ControllerBase { @@ -25,6 +26,14 @@ public async Task GetAllEdgeCategories() return Ok(result); } + + [HttpGet] + public async Task GetInfo(int edgeId) + { + var result = await infoReceiver.GetInfo(edgeId); + return StatusCode((int)result.StatusCode, result.Data); + } + [HttpPost("categories")] public async Task CreateEdgeCategory([FromBody] CreateEdgeCategoryDto createEdgeCategoryDto) { diff --git a/RelationshipAnalysis/Controllers/NodeController.cs b/RelationshipAnalysis/Controllers/NodeController.cs index b70c9bc..0611480 100644 --- a/RelationshipAnalysis/Controllers/NodeController.cs +++ b/RelationshipAnalysis/Controllers/NodeController.cs @@ -14,7 +14,8 @@ namespace RelationshipAnalysis.Controllers; public class NodeController( ICreateNodeCategoryService createNodeCategoryService, INodeCategoryReceiver nodeCategoryReceiver, - INodesAdditionService nodesAdditionService) + INodesAdditionService nodesAdditionService, + [FromKeyedServices("node")] IInfoReceiver infoReceiver) : ControllerBase { [HttpGet("categories")] @@ -24,6 +25,12 @@ public async Task GetAllNodeCategories() return Ok(result); } + [HttpGet] + public async Task GetInfo(int nodeId) + { + var result = await infoReceiver.GetInfo(nodeId); + return StatusCode((int)result.StatusCode, result.Data); + } [HttpPost("categories")] public async Task CreateNodeCategory([FromBody] CreateNodeCategoryDto createNodeCategoryDto) diff --git a/RelationshipAnalysis/Program.cs b/RelationshipAnalysis/Program.cs index c9f9749..38b0d15 100644 --- a/RelationshipAnalysis/Program.cs +++ b/RelationshipAnalysis/Program.cs @@ -58,7 +58,9 @@ .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(); + .AddSingleton() + .AddKeyedSingleton("node") + .AddKeyedSingleton("edge"); diff --git a/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs index ea766e3..03b62b9 100644 --- a/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs +++ b/RelationshipAnalysis/Services/GraphServices/Abstraction/IInfoReceiver.cs @@ -4,5 +4,5 @@ namespace RelationshipAnalysis.Services.GraphServices.Abstraction; public interface IInfoReceiver { - Task + Task>> GetInfo(int id); } \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/EdgeInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/EdgeInfoReceiver.cs new file mode 100644 index 0000000..8061e7c --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/EdgeInfoReceiver.cs @@ -0,0 +1,41 @@ +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Enums; +using RelationshipAnalysis.Services.GraphServices.Abstraction; + +namespace RelationshipAnalysis.Services.GraphServices; + +public class EdgeInfoReceiver(IServiceProvider serviceProvider) : IInfoReceiver +{ + public Task>> GetInfo(int edgeId) + { + using var scope = serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + + var result = new Dictionary(); + var selectedEdge = context.Edges.SingleOrDefault(e => e.EdgeId == edgeId); + if (selectedEdge == null) + { + return NotFoundResult(); + } + selectedEdge.EdgeValues.ToList().ForEach(v => result.Add(v.EdgeAttribute.EdgeAttributeName, v.ValueData)); + return SuccessResult(result); + } + + private async Task>> NotFoundResult() + { + return new ActionResponse>() + { + StatusCode = StatusCodeType.NotFound + }; + } + + private async Task>> SuccessResult(Dictionary result) + { + return new ActionResponse>() + { + StatusCode = StatusCodeType.Success, + Data = result + }; + } +} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs deleted file mode 100644 index 48aed5f..0000000 --- a/RelationshipAnalysis/Services/GraphServices/InfoReceiver.cs +++ /dev/null @@ -1,8 +0,0 @@ -using RelationshipAnalysis.Services.GraphServices.Abstraction; - -namespace RelationshipAnalysis.Services.GraphServices; - -public class InfoReceiver : IInfoReceiver -{ - -} \ No newline at end of file diff --git a/RelationshipAnalysis/Services/GraphServices/NodeInfoReceiver.cs b/RelationshipAnalysis/Services/GraphServices/NodeInfoReceiver.cs new file mode 100644 index 0000000..0d8fa2e --- /dev/null +++ b/RelationshipAnalysis/Services/GraphServices/NodeInfoReceiver.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Mvc; +using RelationshipAnalysis.Context; +using RelationshipAnalysis.Dto; +using RelationshipAnalysis.Enums; +using RelationshipAnalysis.Services.GraphServices.Abstraction; + +namespace RelationshipAnalysis.Services.GraphServices; + +public class NodeInfoReceiver(IServiceProvider serviceProvider) : IInfoReceiver +{ + public Task>> GetInfo(int nodeId) + { + using var scope = serviceProvider.CreateScope(); + var context = scope.ServiceProvider.GetRequiredService(); + + var result = new Dictionary(); + var selectedNode = context.Nodes.SingleOrDefault(n => n.NodeId == nodeId); + if (selectedNode == null) + { + return NotFoundResult(); + } + selectedNode.Values.ToList().ForEach(v => result.Add(v.NodeAttribute.NodeAttributeName, v.ValueData)); + return SuccessResult(result); + } + + private async Task>> NotFoundResult() + { + return new ActionResponse>() + { + StatusCode = StatusCodeType.NotFound + }; + } + + private async Task>> SuccessResult(Dictionary result) + { + return new ActionResponse>() + { + StatusCode = StatusCodeType.Success, + Data = result + }; + } +} \ No newline at end of file