Example #1
0
        public async Task <APIResponse> GetRecordById(string collectionName, string id)
        {
            _logger.LogInformation($"GetRecordById request recieved");

            var collection = await GetCollection(collectionName).ConfigureAwait(false);

            if (collection == null)
            {
                return(APIResponse.NotOk(Request.ToRequestString(), $"Cant find collection with name {collectionName}", HttpStatusCode.BadRequest));
            }

            var response = await _elasticBand.GetDocumentByID <object>(collection.Index, id).ConfigureAwait(false);

            if (response.Ok)
            {
                return new APIResponse
                       {
                           Request = Request.ToRequestString(),
                           Ok      = true,
                           Result  = "found",
                           Data    = response.Data
                       }
            }
            ;

            return(APIResponse.NotOk(Request.ToRequestString(), "Failed to return any data", HttpStatusCode.NotFound));
        }
Example #2
0
 /// <summary>
 /// Fetch an object (T) from Elasticsearch, fast lookup by id.
 /// </summary>
 /// <param name="id">A string containing the id of the document in Elasticsearch</param>
 /// <returns>An ElasticBandResponse, where Data is an object (T) containing the fetched object.</returns>
 public async Task <ElasticBandResponse <T> > GetById(string id)
 {
     return(await _elasticBand.GetDocumentByID <T>(IndexName, id));
 }