-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Meeting, decoupling domain API from underlying data sources…
… (#47) ### Summary & Motivation This change introduces decouples our commands and queries for meetings from the underlying implementation. Commands and queries now work with a Meeting(Dto) concept, which is a projection based on ManagedMeetings in our database and from CalendarEntries in connected calendars. ManagedMeetings can be connected to CalendarEntries. This is the case when a Meeting is created and the user already has connected their calendar. It can also be disconnected. This happens when no calendar is connected, but can in the future also apply to "undetermined" meetings, i.e. where no timeslot has been identified for the meeting yet. When accessing meetings, we read both from our ManagedMeetings table and from connected calendars. The results are combined, combining ManagedMeetings and CalendarEntries that are connected, and returning other ManagedMeetings and CalendarEntries directly. Other changes: - Set up for easy tests of commands and queries in calendar-assistant - Prepare for multiple calendar providers by introduction of ICalendarClient and a factory - Make clear separation between regular and infrastructure dependencies in our dependency configuration. The latter being all dependencies that call outside of the system, such as to Azure Open AI, Microsoft Graph, etc. - Add AccountManagementClient for encapsulating cross-service requests - Add AuthenticatedExecutionContext for a stronger DI-based guarantee that the user is authenticated ### Checklist - [x] I have added a Label to the pull-request - [x] I have added tests, and done manual regression tests - [x] I have updated the documentation, if necessary --------- Co-authored-by: Marco van Kimmenade <[email protected]>
- Loading branch information
1 parent
2d5ec11
commit d78e3fe
Showing
38 changed files
with
1,146 additions
and
465 deletions.
There are no files selected for viewing
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
40 changes: 40 additions & 0 deletions
40
application/calendar-assistant/Core/AccountManagementClient.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Net; | ||
using System.Net.Http.Json; | ||
using JetBrains.Annotations; | ||
using Moment42.CalendarAssistant.Application; | ||
using PlatformPlatform.SharedKernel.Domain; | ||
|
||
namespace Moment42.CalendarAssistant; | ||
|
||
public interface IAccountManagementClient | ||
{ | ||
Task<AccountManagementUserResponse> GetUser(UserId userId, CancellationToken cancellationToken); | ||
} | ||
|
||
public sealed class AccountManagementClient(IHttpClientFactory httpClientFactory) : IAccountManagementClient | ||
{ | ||
public async Task<AccountManagementUserResponse> GetUser(UserId userId, CancellationToken cancellationToken) | ||
{ | ||
var accountManagementHttpClient = httpClientFactory.CreateClient("AccountManagement"); | ||
var getUserResponse = await accountManagementHttpClient.SendAsync( | ||
new HttpRequestMessage(HttpMethod.Get, $"{AccountManagementEndpoints.UserEndpoint}/{userId}"), | ||
cancellationToken | ||
); | ||
|
||
if (getUserResponse.StatusCode != HttpStatusCode.OK) | ||
{ | ||
throw new AccountManagementClientException($"User with UserId {userId} not found. Status code {getUserResponse.StatusCode}."); | ||
} | ||
|
||
return await getUserResponse.Content.ReadFromJsonAsync<AccountManagementUserResponse>(cancellationToken) | ||
?? throw new AccountManagementClientException($"Failed to parse response from user endpoint. UserId {userId}."); | ||
} | ||
|
||
private sealed class AccountManagementClientException(string message) : Exception(message); | ||
} | ||
|
||
[PublicAPI] | ||
public sealed record AccountManagementUserResponse( | ||
string Id, | ||
string TenantId | ||
); |
3 changes: 3 additions & 0 deletions
3
application/calendar-assistant/Core/Application/Calendar/CalendarClientException.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Moment42.CalendarAssistant.Application.Calendar; | ||
|
||
public sealed class CalendarClientException(string message) : Exception(message); |
17 changes: 17 additions & 0 deletions
17
application/calendar-assistant/Core/Application/Calendar/CalendarClientFactory.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moment42.CalendarAssistant.Application.CalendarConnections.Domain; | ||
|
||
namespace Moment42.CalendarAssistant.Application.Calendar; | ||
|
||
public interface ICalendarClientFactory | ||
{ | ||
ICalendarClient GetCalendarClient(CalendarConnectionType calendarConnection); | ||
} | ||
|
||
public sealed class CalendarClientFactory(IServiceProvider serviceProvider) : ICalendarClientFactory | ||
{ | ||
public ICalendarClient GetCalendarClient(CalendarConnectionType calendarConnectionType) | ||
{ | ||
return serviceProvider.GetRequiredKeyedService<ICalendarClient>(calendarConnectionType.ToString()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
application/calendar-assistant/Core/Application/Calendar/CalendarEntry.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Moment42.CalendarAssistant.Application.Calendar; | ||
|
||
public abstract record CalendarEntryBase | ||
{ | ||
public string? Title { get; init; } | ||
|
||
public bool IsOnline { get; init; } | ||
|
||
public string[] Attendees { get; init; } = []; | ||
|
||
public DateTimeOffset StartTime { get; init; } | ||
|
||
public DateTimeOffset EndTime { get; init; } | ||
} | ||
|
||
public sealed record CalendarEntryDetails : CalendarEntryBase; | ||
|
||
public sealed record CalendarEntry : CalendarEntryBase | ||
{ | ||
public CalendarEntryId Id { get; init; } = null!; | ||
} |
9 changes: 9 additions & 0 deletions
9
application/calendar-assistant/Core/Application/Calendar/CalendarEntryId.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Moment42.CalendarAssistant.Application.Calendar; | ||
|
||
public sealed record CalendarEntryId(string Value) | ||
{ | ||
public static implicit operator string(CalendarEntryId calendarEntryId) | ||
{ | ||
return calendarEntryId.Value; | ||
} | ||
} |
58 changes: 0 additions & 58 deletions
58
application/calendar-assistant/Core/Application/Calendar/Commands/CancelEvent.cs
This file was deleted.
Oops, something went wrong.
113 changes: 0 additions & 113 deletions
113
application/calendar-assistant/Core/Application/Calendar/Commands/CreateEvent.cs
This file was deleted.
Oops, something went wrong.
75 changes: 0 additions & 75 deletions
75
application/calendar-assistant/Core/Application/Calendar/Commands/RescheduleEvent.cs
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
application/calendar-assistant/Core/Application/Calendar/ICalendarClient.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Moment42.CalendarAssistant.Application.CalendarConnections.Domain; | ||
using PlatformPlatform.SharedKernel.Domain; | ||
|
||
namespace Moment42.CalendarAssistant.Application.Calendar; | ||
|
||
public interface ICalendarClient | ||
{ | ||
Task<CalendarEntryId> CreateCalendarEntry(CalendarEntryDetails calendarEntry, CancellationToken cancellationToken); | ||
|
||
Task<IReadOnlyList<CalendarEntry>> GetCalendarEntries(TenantId tenantId, UserId userId, DateTimeOffset startTime, DateTimeOffset endTime, CancellationToken cancellationToken); | ||
|
||
Task CancelCalendarEntry(CalendarEntryId id, CancellationToken cancellationToken); | ||
|
||
Task RescheduleCalendarEntry(CalendarEntryId id, DateTimeOffset startTime, DateTimeOffset endTime, CancellationToken cancellationToken); | ||
|
||
Task<AuthenticationTokens> GetNewAuthenticationTokens(string refreshToken, CancellationToken cancellationToken); | ||
} |
Oops, something went wrong.