コード例 #1
0
        public async Task <IEnumerable <LaunchpadModel> > getAllLaunchpads(string status, string location)
        {
            var dataObject = await _launchpadRepo.Get();

            if (!string.IsNullOrWhiteSpace(status))
            {
                dataObject = dataObject.Where(x => x.Status == status);
            }

            if (!string.IsNullOrWhiteSpace(location))
            {
                dataObject = dataObject.Where(x => x.Full_name.Contains(location));
            }
            var responseObject = new List <LaunchpadModel>();

            foreach (var modelToChange in dataObject)
            {
                var modelItem = new LaunchpadModel(modelToChange.Id, modelToChange.Full_name, modelToChange.Status);
                _logger.LogInformation("LaunchpadDAO getAllLaunchpads creating new LaunchpadModel with {Id} {Full_Name} {Status}", modelToChange.Id, modelToChange.Full_name, modelToChange.Status);
                responseObject.Add(modelItem);
            }


            return(responseObject);
        }
コード例 #2
0
        public async Task <LaunchpadModel> getLaunchPadById(string id)
        {
            var dataObject = await _launchpadRepo.GetById(id);

            _logger.LogInformation("LaunchpadDAO getLaunchPadById creating new LaunchpadModel with {Id} {Full_Name} {Status}", dataObject.Id, dataObject.Full_name, dataObject.Status);

            var response = new LaunchpadModel(dataObject.Id, dataObject.Full_name, dataObject.Status);

            return(response);
        }
コード例 #3
0
        public async Task <ActionResult <LaunchpadModel> > Get(string id)
        {
            // I went with Serilogs so that I can eventually configure it for cloud-based logging using CloudWatch or some other analog of it
            // but I implemented it with ILogger so that I could swap out the logger for another if needed and to make unit tests easier
            _logger.LogDebug("Launchpad Get called with Id: {Id}", id);

            // call a service with the given ID. This service will return a LaunchpadModel after checking either the api or a future database.
            try
            {
                LaunchpadModel response = await _launchpadService.getLaunchPadById(id);

                _logger.LogDebug("Launchpad Get returned from service with response of: {Response}", response);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError("Launchpad Get encountered an exception: {Ex}", ex);
                return(NotFound());
            }
        }
コード例 #4
0
        public async Task <object> GetById(string id)
        {
            string launchpadData         = null;
            HttpResponseMessage response = await client.GetAsync(_configuration["SiteConfig"] + "/" + id);

            if (response.IsSuccessStatusCode)
            {
                launchpadData = await response.Content.ReadAsStringAsync();

                JObject productJObject = JObject.Parse(launchpadData);

                LaunchpadModel launchpad = new LaunchpadModel
                {
                    FullName = productJObject["full_name"].ToString(),
                    Id       = productJObject["id"].ToString(),
                    Status   = productJObject["status"].ToString()
                };
                return(launchpad);
            }
            return(new List <LaunchpadModel>());
        }
コード例 #5
0
        public async Task <IActionResult> Get(string id)
        {
            try
            {
                var launchpad = await _launchPadService.GetById(id);

                if (launchpad == null)
                {
                    return(StatusCode(StatusCodes.Status404NotFound));
                }

                var launchpadModel = new LaunchpadModel(launchpad.Id, launchpad.Name, launchpad.Status);

                return(Ok(launchpadModel));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }