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