Esempio n. 1
0
        public async Task <IActionResult> PostNewSample([FromBody] EnvSampleSubmission sample)
        {
            // Ensure model is correctly populated.
            if (!ModelState.IsValid ||
                sample.Environment == Guid.Empty)
            {
                return(BadRequest(ModelState));
            }

            // Submit to core:
            var userId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User);

            if (userId == Guid.Empty)
            {
                return(BadRequest("Who are you?"));
            }

            var request = new NewSampleRequest
            {
                Sample = sample,
                UserId = userId
            };
            var port = new BasicPresenter <BlankResponse>();

            var success = await _addSample.Handle(request, port);

            return((success) ? Ok() : BadRequest("Failed to post sample"));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetOwnedNodesForUser()
        {
            var request = new DataAccessRequest <IController>
            {
                UserId   = _claimsCompat.ExtractFirstIdClaim(HttpContext.User),
                Strategy = DataAccessRequest <IController> .AcquisitionStrategy.All
            };

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

            return((success) ? new OkObjectResult(port.Response.Result.Select(ControllerDto.From)) : BadRequest());
        }
Esempio n. 3
0
        public async Task <IActionResult> RegisterEnvToUser(Guid envGuid)
        {
            var request = new RegisterEnvironmentRequest
            {
                Owner      = _claimsCompat.ExtractFirstIdClaim(HttpContext.User),
                MfgId      = envGuid,
                CreateMode = RegisterEnvironmentRequest.Mode.Touch,
            };

            var port    = new BasicPresenter <NewEntityResponse <Guid> >();
            var success = await _registerEnvironment.Handle(request, port);

            return((success) ? new OkObjectResult(port.Response.Id) : BadRequest(ModelState));
        }
Esempio n. 4
0
        public async Task <IActionResult> AcquireTokenForDaemon()
        {
            BasicPresenter <LoginResponse> port    = new BasicPresenter <LoginResponse>();
            ProviderGrantRequest           request = new ProviderGrantRequest
            {
                OnBehalfOf = _claimCompat.ExtractFirstIdClaim(HttpContext.User)
            };

            var success = await _dataProviderGrant.Handle(request, port);

            return((success) ?  new OkObjectResult(port.Response) : BadRequest());
        }
Esempio n. 5
0
        public async Task <IActionResult> GetIdsForUsersPets()
        {
            var userId = _claimsCompat.ExtractFirstIdClaim(HttpContext.User);

            // fetch all pets for the given user.
            var request = new DataAccessRequest <IPet>
            {
                UserId   = userId,
                Strategy = DataAccessRequest <IPet> .AcquisitionStrategy.All
            };
            var port    = new BasicPresenter <GenericDataResponse <IPet> >();
            var success = await _getPetDataUseCase.Handle(request, port);

            if (!success)
            {
                return(BadRequest());
            }

            // Transform into just IDs
            var idList = port.Response.Result.Select(pet => pet.Id).ToImmutableList();

            return(new OkObjectResult(idList));
        }