Exemplo n.º 1
0
        public IActionResult UpdateNode([FromBody] NodeUpdateRequest nodeRequest)
        {
            var node = _nodeService.GetNode(nodeRequest.Id);

            node.Name      = nodeRequest.Name;
            node.Points    = nodeRequest.Points;
            node.Longitude = nodeRequest.Longitude;
            node.Latitude  = nodeRequest.Latitude;
            _nodeService.UpdateNode(node);
            return(Ok());
        }
Exemplo n.º 2
0
        public void UpdateNode()
        {
            // Arrange
            var nodeRequest = new NodeUpdateRequest()
            {
                Id = 1, Name = "toto"
            };

            // Act
            _target.UpdateNode(nodeRequest);
            // Assert
            A.CallTo(() => _nodeService.GetNode(nodeRequest.Id)).MustHaveHappened();
            A.CallTo(() => _nodeService.UpdateNode(A <Node> ._)).MustHaveHappened();
        }
Exemplo n.º 3
0
        public async Task <IActionResult> RegisterController(Guid controllerId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var request = new NodeUpdateRequest
            {
                UserId       = _claimsCompat.ExtractFirstIdClaim(HttpContext.User),
                ControllerId = controllerId,
                Operation    = NodeUpdateRequest.Mode.Create
            };

            var port   = new BasicPresenter <GenericDataResponse <IController> >();
            var result = await _updateNodeUseCase.Handle(request, port);

            return((result) ? new OkObjectResult(ControllerDto.From(port.Response.Result.First())) : BadRequest());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> SetPeers([FromBody] PeerUpdateForm form)
        {
            if (!ModelState.IsValid ||
                form.ControllerId == Guid.Empty)
            {
                return(BadRequest(ModelState));
            }

            var request = new NodeUpdateRequest
            {
                UserId       = _claimsCompat.ExtractFirstIdClaim(HttpContext.User),
                ControllerId = form.ControllerId,
                PeerIds      = form.PeerIds,
                Operation    = NodeUpdateRequest.Mode.PeerUpdate
            };

            var port   = new BasicPresenter <GenericDataResponse <IController> >();
            var result = await _updateNodeUseCase.Handle(request, port);

            return((result) ? new OkObjectResult(ControllerDto.From(port.Response.Result.First())) : BadRequest());
        }
Exemplo n.º 5
0
        public async Task <bool> Handle(NodeUpdateRequest message, IOutboundPort <GenericDataResponse <IController> > outputPort)
        {
            var user = await _userStore.GetUserById(message.UserId);

            if (user == null)
            {
                return(false);              // specified user doesn't exist, do nothing on their behalf.
            }
            var controller = await _controllerStore.GetById(message.ControllerId);

            if (message.Operation == NodeUpdateRequest.Mode.Create)
            {
                // if the controller exists - then it was owned by another user
                // if they haven't relinquished it then we don't want to re-author its owner.
                if (controller?.Owner != null)
                {
                    if (controller.Owner != user)
                    {
                        return(false);
                    }
                }


                // add controller (or a new instance) to the user:
                controller ??= _entityFactory.GetControllerBuilder()
                .SetId(message.ControllerId)
                .Build();

                await _userStore.AddAssociationToController(user, controller);
            }
            else if (message.Operation == NodeUpdateRequest.Mode.PeerUpdate)
            {
                if (controller == null)
                {
                    return(false);
                }

                // call through to RegisterEnvironmentUseCase?
                foreach (Guid envId in message.PeerIds)
                {
                    // try loading the environment, update its association
                    var env = await _environmentStore.GetById(envId);

                    // Behavior here is TBD. Should environment devices just be 'whoever has posession it'
                    // if so, should existing data associated to that environment be dumped?
                    // if not, hos should we permit giving them out? etc.
                    // Point is, I have some system-level planning to do here, but I need *something*
                    // here for the time being:
                    if (env == null)
                    {
                        continue;
                    }
                    if (env.Controller != controller)
                    {
                        await _controllerStore.ReParentEnvironment(controller, env);
                    }

                    // for now: not creating new Env entities in this use case. Expect it to be
                    // handled separately
                }
            }

            var response = new GenericDataResponse <IController>
            {
                Result = new[] { controller }
            };

            outputPort.Handle(response);
            return(true);
        }