Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bad1/assignment2
1 result
Show changes
Commits on Source (2)
......@@ -18,9 +18,9 @@ namespace assignment2.Controllers
//[Authorize(Roles = "Admin")]
[HttpGet]
public async Task<IActionResult> GetAsync(string? user, string? operation, DateTime? startDate, DateTime? endTime)
public async Task<IActionResult> GetAsync(string? user, string? operation, DateTime? startDate, DateTime? endTime, string? level)
{
var logs = await _logsService.GetAsync(user, operation, startDate, endTime);
var logs = await _logsService.GetAsync(user, operation, startDate, endTime, level);
return Ok(logs);
}
......
......@@ -8,6 +8,6 @@ namespace assignment2.Interfaces
{
public interface ILogService
{
Task<IEnumerable<LogEntry>> GetAsync(string? user, string? operation, DateTime? startDate, DateTime? endTime);
Task<IEnumerable<LogEntry>> GetAsync(string? user, string? operation, DateTime? startDate, DateTime? endTime, string? level);
}
}
\ No newline at end of file
......@@ -18,5 +18,5 @@ namespace assignment2.Models
[BsonElement("Timestamp")]
[BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
}
}
\ No newline at end of file
......@@ -37,7 +37,7 @@ namespace assignment2.Services
}
public async Task<IEnumerable<LogEntry>> GetAsync(string? user, string? operation, DateTime? startDate, DateTime? endTime)
public async Task<IEnumerable<LogEntry>> GetAsync(string? user, string? operation, DateTime? startDate, DateTime? endTime, string? level)
{
var builder = Builders<LogEntry>.Filter;
......@@ -60,6 +60,11 @@ namespace assignment2.Services
filters.Add(builder.And(builder.Gte(u => u.Properties.LogInfo.Timestamp, startDate), builder.Lte(u => u.Properties.LogInfo.Timestamp, endTime)));
Console.WriteLine($"Filtering by date range: {startDate} to {endTime}");
}
if (!string.IsNullOrEmpty(level))
{
filters.Add(builder.Eq(u => u.Level, level));
Console.WriteLine($"Filtering by level: {level}");
}
var filter = filters.Count > 0 ? builder.And(filters) : builder.Empty;
......