diff --git a/src/AzureOpenAIProxy.ApiApp/Program.cs b/src/AzureOpenAIProxy.ApiApp/Program.cs
index 1ef3a28c..4c5a0e55 100644
--- a/src/AzureOpenAIProxy.ApiApp/Program.cs
+++ b/src/AzureOpenAIProxy.ApiApp/Program.cs
@@ -1,5 +1,6 @@
using AzureOpenAIProxy.ApiApp.Endpoints;
using AzureOpenAIProxy.ApiApp.Extensions;
+using AzureOpenAIProxy.ApiApp.Repositories;
using AzureOpenAIProxy.ApiApp.Services;
var builder = WebApplication.CreateBuilder(args);
@@ -18,6 +19,9 @@
// Add admin services
builder.Services.AddAdminEventService();
+// Add admin repositories
+builder.Services.AddAdminEventRepository();
+
var app = builder.Build();
app.MapDefaultEndpoints();
diff --git a/src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs b/src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs
new file mode 100644
index 00000000..552b6416
--- /dev/null
+++ b/src/AzureOpenAIProxy.ApiApp/Repositories/AdminEventRepository.cs
@@ -0,0 +1,85 @@
+using AzureOpenAIProxy.ApiApp.Models;
+
+namespace AzureOpenAIProxy.ApiApp.Repositories;
+
+///
+/// This provides interfaces to the class.
+///
+public interface IAdminEventRepository
+{
+ ///
+ /// Creates a new record of event details.
+ ///
+ /// Event details instance.
+ /// Returns the event details instance created.
+ Task CreateEvent(AdminEventDetails eventDetails);
+
+ ///
+ /// Gets the list of events.
+ ///
+ /// Returns the list of events.
+ Task> GetEvents();
+
+ ///
+ /// Gets the event details.
+ ///
+ /// Event ID.
+ /// Returns the event details record.
+ Task GetEvent(Guid eventId);
+
+ ///
+ /// Updates the event details.
+ ///
+ /// Event ID.
+ /// Event details instance.
+ /// Returns the updated record of the event details.
+ Task UpdateEvent(Guid eventId, AdminEventDetails eventDetails);
+}
+
+///
+/// This represents the repository entity for the admin event.
+///
+public class AdminEventRepository : IAdminEventRepository
+{
+ ///
+ public async Task CreateEvent(AdminEventDetails eventDetails)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ public async Task> GetEvents()
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ public async Task GetEvent(Guid eventId)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ public async Task UpdateEvent(Guid eventId, AdminEventDetails eventDetails)
+ {
+ throw new NotImplementedException();
+ }
+}
+
+///
+/// This represents the extension class for
+///
+public static class AdminEventRepositoryExtensions
+{
+ ///
+ /// Adds the instance to the service collection.
+ ///
+ /// instance.
+ /// Returns instance.
+ public static IServiceCollection AddAdminEventRepository(this IServiceCollection services)
+ {
+ services.AddScoped();
+
+ return services;
+ }
+}
diff --git a/src/AzureOpenAIProxy.ApiApp/Services/AdminEventService.cs b/src/AzureOpenAIProxy.ApiApp/Services/AdminEventService.cs
index d3e0533f..09f21797 100644
--- a/src/AzureOpenAIProxy.ApiApp/Services/AdminEventService.cs
+++ b/src/AzureOpenAIProxy.ApiApp/Services/AdminEventService.cs
@@ -1,4 +1,5 @@
using AzureOpenAIProxy.ApiApp.Models;
+using AzureOpenAIProxy.ApiApp.Repositories;
namespace AzureOpenAIProxy.ApiApp.Services;
@@ -39,30 +40,40 @@ public interface IAdminEventService
///
/// This represents the service entity for admin event.
///
-public class AdminEventService : IAdminEventService
+public class AdminEventService(IAdminEventRepository repository) : IAdminEventService
{
+ private readonly IAdminEventRepository _repository = repository ?? throw new ArgumentNullException(nameof(repository));
+
///
public async Task CreateEvent(AdminEventDetails eventDetails)
{
- throw new NotImplementedException();
+ var result = await this._repository.CreateEvent(eventDetails).ConfigureAwait(false);
+
+ return result;
}
///
public async Task> GetEvents()
{
- throw new NotImplementedException();
+ var result = await this._repository.GetEvents().ConfigureAwait(false);
+
+ return result;
}
///
public async Task GetEvent(Guid eventId)
{
- throw new NotImplementedException();
+ var result = await this._repository.GetEvent(eventId).ConfigureAwait(false);
+
+ return result;
}
///
public async Task UpdateEvent(Guid eventId, AdminEventDetails eventDetails)
{
- throw new NotImplementedException();
+ var result = await this._repository.UpdateEvent(eventId, eventDetails).ConfigureAwait(false);
+
+ return result;
}
}
diff --git a/test/AzureOpenAIProxy.ApiApp.Tests/Repositories/AdminEventRepositoryTests.cs b/test/AzureOpenAIProxy.ApiApp.Tests/Repositories/AdminEventRepositoryTests.cs
new file mode 100644
index 00000000..0e00c5d4
--- /dev/null
+++ b/test/AzureOpenAIProxy.ApiApp.Tests/Repositories/AdminEventRepositoryTests.cs
@@ -0,0 +1,80 @@
+using AzureOpenAIProxy.ApiApp.Models;
+using AzureOpenAIProxy.ApiApp.Repositories;
+
+using FluentAssertions;
+
+using Microsoft.Extensions.DependencyInjection;
+
+namespace AzureOpenAIProxy.ApiApp.Tests.Repositories;
+
+public class AdminEventRepositoryTests
+{
+ [Fact]
+ public void Given_ServiceCollection_When_AddAdminEventRepository_Invoked_Then_It_Should_Contain_AdminEventRepository()
+ {
+ // Arrange
+ var services = new ServiceCollection();
+
+ // Act
+ services.AddAdminEventRepository();
+
+ // Assert
+ services.SingleOrDefault(p => p.ServiceType == typeof(IAdminEventRepository)).Should().NotBeNull();
+ }
+
+ [Fact]
+ public void Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Throw_Exception()
+ {
+ // Arrange
+ var eventDetails = new AdminEventDetails();
+ var repository = new AdminEventRepository();
+
+ // Act
+ Func func = async () => await repository.CreateEvent(eventDetails);
+
+ // Assert
+ func.Should().ThrowAsync();
+ }
+
+ [Fact]
+ public void Given_Instance_When_GetEvents_Invoked_Then_It_Should_Throw_Exception()
+ {
+ // Arrange
+ var repository = new AdminEventRepository();
+
+ // Act
+ Func func = async () => await repository.GetEvents();
+
+ // Assert
+ func.Should().ThrowAsync();
+ }
+
+ [Fact]
+ public void Given_Instance_When_GetEvent_Invoked_Then_It_Should_Throw_Exception()
+ {
+ // Arrange
+ var eventId = Guid.NewGuid();
+ var repository = new AdminEventRepository();
+
+ // Act
+ Func func = async () => await repository.GetEvent(eventId);
+
+ // Assert
+ func.Should().ThrowAsync();
+ }
+
+ [Fact]
+ public void Given_Instance_When_UpdateEvent_Invoked_Then_It_Should_Throw_Exception()
+ {
+ // Arrange
+ var eventId = Guid.NewGuid();
+ var eventDetails = new AdminEventDetails();
+ var repository = new AdminEventRepository();
+
+ // Act
+ Func func = async () => await repository.UpdateEvent(eventId, eventDetails);
+
+ // Assert
+ func.Should().ThrowAsync();
+ }
+}
diff --git a/test/AzureOpenAIProxy.ApiApp.Tests/Services/AdminEventServiceTests.cs b/test/AzureOpenAIProxy.ApiApp.Tests/Services/AdminEventServiceTests.cs
index e459e4d0..cf56f8e2 100644
--- a/test/AzureOpenAIProxy.ApiApp.Tests/Services/AdminEventServiceTests.cs
+++ b/test/AzureOpenAIProxy.ApiApp.Tests/Services/AdminEventServiceTests.cs
@@ -1,10 +1,13 @@
using AzureOpenAIProxy.ApiApp.Models;
+using AzureOpenAIProxy.ApiApp.Repositories;
using AzureOpenAIProxy.ApiApp.Services;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
+using NSubstitute;
+
namespace AzureOpenAIProxy.ApiApp.Tests.Services;
public class AdminEventServiceTests
@@ -27,7 +30,8 @@ public void Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Throw_Excepti
{
// Arrange
var eventDetails = new AdminEventDetails();
- var service = new AdminEventService();
+ var repository = Substitute.For();
+ var service = new AdminEventService(repository);
// Act
Func func = async () => await service.CreateEvent(eventDetails);
@@ -40,7 +44,8 @@ public void Given_Instance_When_CreateEvent_Invoked_Then_It_Should_Throw_Excepti
public void Given_Instance_When_GetEvents_Invoked_Then_It_Should_Throw_Exception()
{
// Arrange
- var service = new AdminEventService();
+ var repository = Substitute.For();
+ var service = new AdminEventService(repository);
// Act
Func func = async () => await service.GetEvents();
@@ -54,7 +59,8 @@ public void Given_Instance_When_GetEvent_Invoked_Then_It_Should_Throw_Exception(
{
// Arrange
var eventId = Guid.NewGuid();
- var service = new AdminEventService();
+ var repository = Substitute.For();
+ var service = new AdminEventService(repository);
// Act
Func func = async () => await service.GetEvent(eventId);
@@ -69,7 +75,8 @@ public void Given_Instance_When_UpdateEvent_Invoked_Then_It_Should_Throw_Excepti
// Arrange
var eventId = Guid.NewGuid();
var eventDetails = new AdminEventDetails();
- var service = new AdminEventService();
+ var repository = Substitute.For();
+ var service = new AdminEventService(repository);
// Act
Func func = async () => await service.UpdateEvent(eventId, eventDetails);