Created
September 10, 2022 11:37
-
-
Save Rajdeep-Das/b57f7053a1a1d6e4372f5e3146c9c074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Http; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.VisualBasic; | |
using Redis.OM; | |
using Redis.OM.Searching; | |
using System; | |
using WatchLogger.Helpers; | |
using WatchLogger.Models; | |
namespace WatchLogger.Controllers | |
{ | |
[Route("watchlogger")] | |
[ApiController] | |
public class WatchLoggerController : ControllerBase | |
{ | |
private readonly RedisStackHelper _redisStackHelper; | |
public WatchLoggerController(RedisStackHelper redisStackHelper) | |
{ | |
_redisStackHelper = redisStackHelper; | |
} | |
[HttpGet] | |
public IActionResult GetAll() | |
{ | |
var allLogs = _redisStackHelper.GETAllWatchLog(); | |
return Ok(allLogs); | |
} | |
[HttpGet("filter")] | |
public IActionResult GetAllWithFilters(string searchString = "", string verbString = "", string statusCode = "") | |
{ | |
var logs = _redisStackHelper.GETAllWatchLog(); | |
if (logs != null) | |
{ | |
if (!string.IsNullOrEmpty(searchString)) | |
{ | |
searchString = searchString.ToLower(); | |
logs = logs.Where(l => l.Path.ToLower().Contains(searchString) || l.Method.ToLower().Contains(searchString) || l.ResponseStatus.ToString().Contains(searchString) || (!String.IsNullOrEmpty(l.QueryString) && l.QueryString.ToLower().Contains(searchString))); | |
} | |
if (!string.IsNullOrEmpty(verbString)) | |
{ | |
logs = logs.Where(l => l.Method.ToLower() == verbString.ToLower()); | |
} | |
if (!string.IsNullOrEmpty(statusCode)) | |
{ | |
logs = logs.Where(l => l.ResponseStatus.ToString() == statusCode); | |
} | |
} | |
logs = logs.OrderByDescending(x => x.StartTime); | |
return Ok(logs); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment