public async Task <SearchMerchantsResponse> Search(SearchMerchantsRequest request) { return(await GrpcCallerService.CallService(_urls.GrpcMerchants, async channel => { var client = new Merchants.MerchantsClient(channel); _logger.LogDebug("grpc client created, request = {@request}", request); var response = await client.SearchMerchantsAsync(request); _logger.LogDebug("grpc response {@response}", response); return response; })); }
public async Task <SearchMerchantsResponse> Search(SearchMerchantsRequest request, string token = null) { _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); try { var requestUri = _urls.Merchants + UrlsConfig.MerchantOperations.SearchMerchants(); var content = new StringContent(JsonSerializer.Serialize(request), Encoding.UTF8, "application/json"); var response = await _client.PostAsync(requestUri, content); return(response.IsSuccessStatusCode ? JsonSerializer.Deserialize <SearchMerchantsResponse>(response.Content.ReadAsStringAsync().Result) : default);
public async Task <ActionResult <SearchMerchantsResponse> > SearchMerchants(SearchMerchantsRequest request = null) { return(await _mediator.Send(new SearchMerchantsQuery(request))); }
public async Task <ActionResult <SearchMerchantsResponse> > SearchMerchants(SearchMerchantsRequest request = null) { return(await _merchantService.Search(request)); }
public override async Task <SearchMerchantsResponse> SearchMerchants(SearchMerchantsRequest request, ServerCallContext context) { context.Status = new Status(StatusCode.OK, $"OK"); var rows = await _merchantQueries.SearchMerchants(request.Lat, request.Lng, request.Miles, request.Location, request.Location); var response = new SearchMerchantsResponse { DisplayLocation = request.Location }; if (rows != null) { try { var dict_merchants = new Dictionary <int, SearchMerchantModel>(); foreach (var row in rows) { var m = (Merchant)row.m; var mi = (MerchantImage)row.mi; if (!dict_merchants.ContainsKey(m.ID)) { var merchant = new SearchMerchantModel { ID = m.ID, Name = m.Name ?? string.Empty, Description = m.Description ?? string.Empty, CallToAction = m.CallToAction ?? string.Empty, ShortDescription = m.ShortDescription ?? string.Empty, WebsiteUrl = m.WebsiteUrl ?? string.Empty, Street1 = m.Street1 ?? string.Empty, Street2 = m.Street2 ?? string.Empty, StateAbbreviation = m.StateAbbreviation ?? string.Empty, City = m.City ?? string.Empty, Zip = m.Zip ?? string.Empty, Latitude = m.Latitude, Longitude = m.Longitude, MerchantTypeID = m.MerchantTypeID, MerchantTypeName = m.MerchantType?.Name ?? string.Empty, MilesAway = 0, DefaultImageUrl = string.Empty, Location = string.Empty, DistanceAway = string.Empty }; merchant.MilesAway = request.Lat != 0 && request.Lng != 0 ? m.HaversineDistance(request.Lat, request.Lng) : 0.0; dict_merchants.Add(m.ID, merchant); } if (mi != null && !string.IsNullOrEmpty(mi.ImageUrl) && string.IsNullOrEmpty(dict_merchants[m.ID].DefaultImageUrl)) { dict_merchants[m.ID].DefaultImageUrl = mi.ImageUrl; } } if (string.IsNullOrWhiteSpace(request.Keyword)) { response.Merchants.AddRange(dict_merchants.Values); } else { //TODO: improve search response.Merchants.AddRange(dict_merchants.Values .Where(m => m.Name.ToLower().Contains(request.Keyword.ToLower()))); } } catch (System.Exception e) { throw e; } } return(response); }