From 9e536bd6d756a9cfb5fe3d845245c5f0106125bc Mon Sep 17 00:00:00 2001 From: Jesper Ladegaard Date: Mon, 11 Dec 2023 21:26:08 +0100 Subject: [PATCH] moveRackEquipment and arrangeRackEquipment mutations added --- .../Mutations/NodeContainerMutations.cs | 76 +++++++++++++++++++ .../RackEquipmentArrangeMethodEnumType.cs | 14 ++++ .../OpenFTTH.APIGateway.csproj | 4 +- 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Types/RackEquipmentArrangeMethodEnumType.cs diff --git a/OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Mutations/NodeContainerMutations.cs b/OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Mutations/NodeContainerMutations.cs index 3e4b505..5bf7c55 100644 --- a/OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Mutations/NodeContainerMutations.cs +++ b/OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Mutations/NodeContainerMutations.cs @@ -396,6 +396,82 @@ public NodeContainerMutations(ICommandDispatcher commandDispatcher, IQueryDispat return new CommandResult(updateResult); } ); + + FieldAsync( + "moveRackEquipment", + description: "Mutation that moves a terminal equipment within or between racks", + arguments: new QueryArguments( + new QueryArgument> { Name = "nodeContainerId" }, + new QueryArgument> { Name = "terminalEquipmentId" }, + new QueryArgument> { Name = "moveToRackId" }, + new QueryArgument { Name = "moveToRackPosition" } + ), + resolve: async context => + { + var nodeContainerId = context.GetArgument("nodeContainerId"); + var terminalEquipmentId = context.GetArgument("terminalEquipmentId"); + var moveToRackId = context.GetArgument("moveToRackId"); + int moveToRackPosition = context.GetArgument("moveToRackPosition"); + + var correlationId = Guid.NewGuid(); + + var userContext = context.UserContext as GraphQLUserContext; + var userName = userContext.Username; + + // Get the users current work task (will fail, if user has not selected a work task) + var currentWorkTaskIdResult = WorkQueryHelper.GetUserCurrentWorkId(userName, queryDispatcher); + + if (currentWorkTaskIdResult.IsFailed) + return new CommandResult(currentWorkTaskIdResult); + + var commandUserContext = new UserContext(userName, currentWorkTaskIdResult.Value); + + var cmd = new MoveRackEquipmentInNodeContainer(correlationId, commandUserContext, nodeContainerId, terminalEquipmentId, moveToRackId, moveToRackPosition); + + var cmdResult = await commandDispatcher.HandleAsync(cmd); + + return new CommandResult(cmdResult); + } + ); + + FieldAsync( + "arrangeRackEquipment", + description: "Mutation that can move terminal equipments up/down in a rack", + arguments: new QueryArguments( + new QueryArgument> { Name = "nodeContainerId" }, + new QueryArgument> { Name = "terminalEquipmentId" }, + new QueryArgument> { Name = "arrangeMethod" }, + new QueryArgument { Name = "numberOfRackPositions" } + ), + resolve: async context => + { + var nodeContainerId = context.GetArgument("nodeContainerId"); + var terminalEquipmentId = context.GetArgument("terminalEquipmentId"); + var arrangeMethod = context.GetArgument("moveToRackId"); + int numberOfRackPositions = context.GetArgument("numberOfRackPositions"); + + var correlationId = Guid.NewGuid(); + + var userContext = context.UserContext as GraphQLUserContext; + var userName = userContext.Username; + + // Get the users current work task (will fail, if user has not selected a work task) + var currentWorkTaskIdResult = WorkQueryHelper.GetUserCurrentWorkId(userName, queryDispatcher); + + if (currentWorkTaskIdResult.IsFailed) + return new CommandResult(currentWorkTaskIdResult); + + var commandUserContext = new UserContext(userName, currentWorkTaskIdResult.Value); + + var cmd = new ArrangeRackEquipmentInNodeContainer(correlationId, commandUserContext, nodeContainerId, terminalEquipmentId, arrangeMethod, numberOfRackPositions); + + var cmdResult = await commandDispatcher.HandleAsync(cmd); + + return new CommandResult(cmdResult); + } + ); + + } } } diff --git a/OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Types/RackEquipmentArrangeMethodEnumType.cs b/OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Types/RackEquipmentArrangeMethodEnumType.cs new file mode 100644 index 0000000..e61dac1 --- /dev/null +++ b/OpenFTTH.APIGateway/GraphQL/UtilityNetwork/Types/RackEquipmentArrangeMethodEnumType.cs @@ -0,0 +1,14 @@ +using GraphQL.Types; +using OpenFTTH.UtilityGraphService.API.Model.UtilityNetwork; + +namespace OpenFTTH.APIGateway.GraphQL.UtilityNetwork.Types +{ + public class RackEquipmentArrangeMethodEnumType : EnumerationGraphType + { + public RackEquipmentArrangeMethodEnumType() + { + Name = "RackEquipmentArrangeMethodEnum"; + Description = @"How rack terminal equipments should arranged - up/down"; + } + } +} diff --git a/OpenFTTH.APIGateway/OpenFTTH.APIGateway.csproj b/OpenFTTH.APIGateway/OpenFTTH.APIGateway.csproj index 0459b6a..b46435d 100644 --- a/OpenFTTH.APIGateway/OpenFTTH.APIGateway.csproj +++ b/OpenFTTH.APIGateway/OpenFTTH.APIGateway.csproj @@ -22,8 +22,8 @@ - - + +