public async Task <IEnumerable <FlightModel> > GetOffers(GetOffersRequest request)
        {
            var authToken = await GetAuthToken();

            using (var http = GetHttpClient())
            {
                http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);

                var x        = request.Stringify();
                var response = await http.PostAsync("booking/availability", request.AsJson());

                var stringResponse = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"Unable to get flights! Error: {stringResponse}");
                }

                var parsed    = JsonConvert.DeserializeObject <GetOffersResponse>(stringResponse);
                var allOffers = parsed.FlightsGroupedByPrice.SelectMany(a => a);

                var grouped = allOffers.GroupBy(a => a.Outbound.Segments.Last().ArrivalAirport);

                var res = new List <FlightModel>();

                return(res);
            };
        }
예제 #2
0
        public async Task <IActionResult> GetOffers([FromQuery] GetOffersRequest request)
        {
            var response = await mediator.Send(request);

            Log.Information($"User #{HttpContext.GetCurrentUserId()} fetched offers");

            return(this.CreateResponse(response));
        }
예제 #3
0
        /// <summary>
        /// Get Offers from the service API.
        /// </summary>
        /// <param name="request">The main request class that holds the needed parameters to make the call.</param>
        /// <returns>
        /// An instance of the <see cref="T:expedia.CodingExercise.DataType.Responses.HotelsOffering.GetOffersResponse"/> class.
        /// </returns>
        public GetOffersResponse GetOffers(GetOffersRequest request)
        {
            string jsonOffers = GetJsonOffers(request);

            if (!string.IsNullOrWhiteSpace(jsonOffers))
            {
                return(JsonConvert.DeserializeObject <GetOffersResponse>(jsonOffers));
            }

            return(null);
        }
        /// <summary>
        /// Get Offers from the service API, and do the needed filtering and sorting.
        /// </summary>
        /// <param name="filter">The filter of offers.</param>
        /// <param name="sorting">The sorting order.</param>
        /// <returns>
        /// An instance of the <see cref="T:Expedia.CodingExercise.DataType.ActivityResult"/> class.
        /// </returns>
        public ActivityResult GetOffers(HotelsOffersFilter filter, HotelsOffersSorting sorting)
        {
            /// <summary>
            /// Returned calss
            /// </summary>
            ActivityResult activityResult = new ActivityResult();

            /// <summary>
            /// The needed parameters to make the API request
            /// </summary>
            GetOffersRequest request = new GetOffersRequest(filter);

            try
            {
                using (HotelsOfferingDataSource dataSource = new HotelsOfferingDataSource())
                {
                    var offers = dataSource.GetOffers(request);

                    if (offers != null)
                    {
                        HotelOfferModel hotelOffersModel = new HotelOfferModel();
                        hotelOffersModel.Offers  = offers.GetHotelsOffersDetailsModel();
                        hotelOffersModel.Filter  = filter ?? new HotelsOffersFilter();
                        hotelOffersModel.Sorting = sorting ?? new HotelsOffersSorting();
                        if (sorting != null)
                        {
                            hotelOffersModel.Offers = hotelOffersModel.Offers.ApplyOrder(sorting.OrderBy);
                        }

                        activityResult.IsPassed       = true;
                        activityResult.ReturnedObject = hotelOffersModel;
                    }
                    else
                    {
                        activityResult.IsPassed = false;
                        activityResult.Code     = eResponseCode.General_Error;
                    }
                }
            }
            catch (Exception ex)
            {
                activityResult.IsPassed = false;
                activityResult.Code     = eResponseCode.General_Error;
            }

            return(activityResult);
        }
        public async Task <IEnumerable <FlightModel> > GetOffers(GetOffersRequest request)
        {
            var data = await GetMockData <IEnumerable <FlightModel> >("flights");

            var from = request.GetOffersRequestParam.Origin.FirstOrDefault();
            var to   = request.GetOffersRequestParam.Destination.FirstOrDefault();

            if (!string.IsNullOrEmpty(from))
            {
                data = data.Where(a => a.OriginCode == from);
            }

            if (!string.IsNullOrEmpty(to))
            {
                data = data.Where(a => a.DestinationCode == to);
            }


            return(data);
        }
예제 #6
0
        /// <summary>
        /// Get Offers from the service API.
        /// </summary>
        /// <param name="request">The main request class that holds the needed parameters to make the call.</param>
        /// <returns>
        /// Json object of the offers response.
        /// </returns>
        public string GetJsonOffers(GetOffersRequest request)
        {
            HttpRequestMessage httpRequest;
            /// <summary>
            /// Create common httpclient needed to fetch the response form the API, ite avalaible in the base class
            /// </summary>
            HttpClient client = CreateHttpClient(request, out httpRequest);

            /// <summary>
            /// Create common httpclient executer, ite avalaible in the base class
            /// </summary>
            HttpResponseMessage httpResponse = ExecuteHttpClient(client, httpRequest);

            if (httpResponse.IsSuccessStatusCode)
            {
                return(httpResponse.Content.ReadAsStringAsync().Result);
            }

            return(null);
        }