diff options
| author | JP Dillingham <jp@dillingham.me> | 2024-10-06 16:56:27 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2024-10-06 16:56:27 -0500 |
| commit | 8d919e494ef53fbdf625540971414d26c06a96fb (patch) | |
| tree | 8806c87048477fc416c67a3065c3936ae305651d /src | |
| parent | c0e02f9806ed95dd43bbb7bff74d6abe5e66109c (diff) | |
| download | slskd-8d919e494ef53fbdf625540971414d26c06a96fb.tar.gz | |
add X-Total-Count to events GET
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Events/API/EventsController.cs | 5 | ||||
| -rw-r--r-- | src/slskd/Events/EventService.cs | 19 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/slskd/Events/API/EventsController.cs b/src/slskd/Events/API/EventsController.cs index 8f47fe91..e9780fad 100644 --- a/src/slskd/Events/API/EventsController.cs +++ b/src/slskd/Events/API/EventsController.cs @@ -19,6 +19,7 @@ namespace slskd.Events.API; using Asp.Versioning; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Serilog; @@ -56,6 +57,10 @@ public class EventsController : ControllerBase } var events = Events.Get(offset, limit); + var count = Events.Count(); + + Response.Headers.Append("X-Total-Count", count.ToString()); + return Ok(events); } }
\ No newline at end of file diff --git a/src/slskd/Events/EventService.cs b/src/slskd/Events/EventService.cs index 0406f83d..72a71d22 100644 --- a/src/slskd/Events/EventService.cs +++ b/src/slskd/Events/EventService.cs @@ -74,6 +74,25 @@ public class EventService } /// <summary> + /// Gets the total number of events. + /// </summary> + /// <returns>The total number of events.</returns> + public virtual int Count() + { + try + { + using var context = ContextFactory.CreateDbContext(); + var count = context.Events.Count(); + return count; + } + catch (Exception ex) + { + Log.Error(ex, "Failed to count event records: {Message}", ex.Message); + throw; + } + } + + /// <summary> /// Adds the specified event <paramref name="eventRecord"/>. /// </summary> /// <remarks> |
