-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathAdminEventService.cs
111 lines (92 loc) · 3.52 KB
/
AdminEventService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using AzureOpenAIProxy.ApiApp.Models;
using AzureOpenAIProxy.ApiApp.Repositories;
namespace AzureOpenAIProxy.ApiApp.Services;
/// <summary>
/// This provides interfaces to <see cref="AdminEventService"/> class.
/// </summary>
public interface IAdminEventService
{
/// <summary>
/// Creates a new event.
/// </summary>
/// <param name="eventDetails">Event payload.</param>
/// <returns>Returns the event payload created.</returns>
Task<AdminEventDetails> CreateEvent(AdminEventDetails eventDetails);
/// <summary>
/// Gets the list of events.
/// </summary>
/// <returns>Returns the list of events.</returns>
Task<List<AdminEventDetails>> GetEvents();
/// <summary>
/// Gets the event details.
/// </summary>
/// <param name="eventId">Event ID.</param>
/// <returns>Returns the event details.</returns>
Task<AdminEventDetails> GetEvent(Guid eventId);
/// <summary>
/// Updates the event details.
/// </summary>
/// <param name="eventId">Event ID.</param>
/// <param name="eventDetails">Event details to update.</param>
/// <returns>Returns the updated event details.</returns>
Task<AdminEventDetails> UpdateEvent(Guid eventId, AdminEventDetails eventDetails);
/// <summary>
/// Deletes the event details.
/// </summary>
/// <param name="eventDetails">Event details to update.</param>
/// <returns>Removed EventID of event details instance.</returns>
Task<Guid> DeleteEvent(AdminEventDetails eventDetails);
}
/// <summary>
/// This represents the service entity for admin event.
/// </summary>
public class AdminEventService(IAdminEventRepository repository) : IAdminEventService
{
private readonly IAdminEventRepository _repository = repository ?? throw new ArgumentNullException(nameof(repository));
/// <inheritdoc />
public async Task<AdminEventDetails> CreateEvent(AdminEventDetails eventDetails)
{
var result = await this._repository.CreateEvent(eventDetails).ConfigureAwait(false);
return result;
}
/// <inheritdoc />
public async Task<List<AdminEventDetails>> GetEvents()
{
var result = await this._repository.GetEvents().ConfigureAwait(false);
return result;
}
/// <inheritdoc />
public async Task<AdminEventDetails> GetEvent(Guid eventId)
{
var result = await this._repository.GetEvent(eventId).ConfigureAwait(false);
return result;
}
/// <inheritdoc />
public async Task<AdminEventDetails> UpdateEvent(Guid eventId, AdminEventDetails eventDetails)
{
var result = await this._repository.UpdateEvent(eventId, eventDetails).ConfigureAwait(false);
return result;
}
/// <inheritdoc />
public async Task<Guid> DeleteEvent(AdminEventDetails eventDetails)
{
var result = await this._repository.DeleteEvent(eventDetails).ConfigureAwait(false);
return result;
}
}
/// <summary>
/// This represents the extension class for <see cref="IServiceCollection"/>
/// </summary>
public static class AdminEventServiceExtensions
{
/// <summary>
/// Adds the <see cref="AdminEventService"/> instance to the service collection.
/// </summary>
/// <param name="services"><see cref="IServiceCollection"/> instance.</param>
/// <returns>Returns <see cref="IServiceCollection"/> instance.</returns>
public static IServiceCollection AddAdminEventService(this IServiceCollection services)
{
services.AddScoped<IAdminEventService, AdminEventService>();
return services;
}
}