Yes, you can easily search for events based on specific keywords within their descriptions. To do this, you'll use a LINQ queries that combines Any and Contains methods. This dynamic duo will help you pinpoint the events that match your keywords.
Service:
public async Task<List<LogStore>> GetEvents(string[] keywords, CancellationToken token)
{
try
{
var events = await _applicationDbContext.LogStore
.AsNoTracking()
.Where(x => keywords.Any(keyword => x.Description.Contains(keyword)))
.OrderByDescending(x => x.TimeStamp)
.ToListAsync(cancellationToken: token);
return events;
}
catch (OperationCanceledException)
{
return new List<LogStore>();
}
}
Controller:
[HttpGet("GetEvents")]
public async Task<ActionResult<List<LogStore>>> GetEvents([FromQuery] string[] keywords, CancellationToken token)
{
var events = await _eventsManagementService.GetEvents(keywords, token);
return Ok(new { data = events });
}