-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…rom-booking Feature/vih 4200 create conference from booking
- Loading branch information
Showing
48 changed files
with
1,147 additions
and
32 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
BookingQueueSubscriber/BookingQueueSubscriber.Common/ApiHelper/ApiRequestHelper.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,38 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace BookingQueueSubscriber.Common.ApiHelper | ||
{ | ||
public static class ApiRequestHelper | ||
{ | ||
public static string SerialiseRequestToSnakeCaseJson(object request) | ||
{ | ||
DefaultContractResolver contractResolver = new DefaultContractResolver | ||
{ | ||
NamingStrategy = new SnakeCaseNamingStrategy() | ||
}; | ||
|
||
return JsonConvert.SerializeObject(request, new JsonSerializerSettings | ||
{ | ||
ContractResolver = contractResolver, | ||
Formatting = Formatting.Indented | ||
}); | ||
} | ||
|
||
public static T DeserialiseSnakeCaseJsonToResponse<T>(string response) | ||
{ | ||
var contractResolver = new DefaultContractResolver | ||
{ | ||
NamingStrategy = new SnakeCaseNamingStrategy() | ||
}; | ||
|
||
return JsonConvert.DeserializeObject<T>(response, new JsonSerializerSettings | ||
{ | ||
ContractResolver = contractResolver, | ||
Formatting = Formatting.Indented, | ||
TypeNameHandling = TypeNameHandling.Objects | ||
}); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
BookingQueueSubscriber/BookingQueueSubscriber.Common/ApiHelper/ApiUriFactory.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,32 @@ | ||
using System; | ||
|
||
namespace BookingQueueSubscriber.Common.ApiHelper | ||
{ | ||
public class ApiUriFactory | ||
{ | ||
public ParticipantsEndpoints ParticipantsEndpoints { get; } | ||
public ConferenceEndpoints ConferenceEndpoints { get; } | ||
|
||
public ApiUriFactory() | ||
{ | ||
ParticipantsEndpoints = new ParticipantsEndpoints(); | ||
ConferenceEndpoints = new ConferenceEndpoints(); | ||
} | ||
} | ||
|
||
public class ParticipantsEndpoints | ||
{ | ||
private string ApiRoot => "conferences"; | ||
|
||
public string AddParticipantsToConference(Guid conferenceId) => $"{ApiRoot}/{conferenceId}/participants"; | ||
|
||
public string RemoveParticipantFromConference(Guid conferenceId, Guid participantId) => | ||
$"{ApiRoot}/{conferenceId}/participants/{participantId}"; | ||
} | ||
|
||
public class ConferenceEndpoints | ||
{ | ||
private string ApiRoot => "conferences"; | ||
public string BookNewConference => $"{ApiRoot}"; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
BookingQueueSubscriber/BookingQueueSubscriber.Common/BookingQueueSubscriber.Common.csproj
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.4" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.19.8" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> | ||
<PackageReference Include="SonarAnalyzer.CSharp" Version="7.13.0.8313" /> | ||
</ItemGroup> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
BookingQueueSubscriber/BookingQueueSubscriber.Common/Configuration/AzureAdConfiguration.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,10 @@ | ||
namespace BookingQueueSubscriber.Common.Configuration | ||
{ | ||
public class AzureAdConfiguration | ||
{ | ||
public string ClientId { get; set; } | ||
public string ClientSecret { get; set; } | ||
public string Authority { get; set; } | ||
public string TenantId { get; set; } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
BookingQueueSubscriber/BookingQueueSubscriber.Common/Configuration/ConfigLoader.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,28 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace BookingQueueSubscriber.Common.Configuration | ||
{ | ||
public class ConfigLoader | ||
{ | ||
public readonly IConfigurationRoot ConfigRoot; | ||
|
||
public ConfigLoader() | ||
{ | ||
var configRootBuilder = new ConfigurationBuilder() | ||
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) | ||
.AddEnvironmentVariables(); | ||
ConfigRoot = configRootBuilder.Build(); | ||
} | ||
|
||
public IOptions<AzureAdConfiguration> ReadAzureAdSettings() | ||
{ | ||
return Options.Create(ConfigRoot.GetSection("AzureAd").Get<AzureAdConfiguration>()); | ||
} | ||
|
||
public IOptions<HearingServicesConfiguration> ReadHearingServiceSettings() | ||
{ | ||
return Options.Create(ConfigRoot.GetSection("VhServices").Get<HearingServicesConfiguration>()); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...eueSubscriber/BookingQueueSubscriber.Common/Configuration/HearingServicesConfiguration.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,8 @@ | ||
namespace BookingQueueSubscriber.Common.Configuration | ||
{ | ||
public class HearingServicesConfiguration | ||
{ | ||
public string VideoApiUrl { get; set; } | ||
public string VideoApiResourceId { get; set; } | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
BookingQueueSubscriber/BookingQueueSubscriber.Common/Security/AzureTokenProvider.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,48 @@ | ||
using System; | ||
using BookingQueueSubscriber.Common.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.IdentityModel.Clients.ActiveDirectory; | ||
|
||
namespace BookingQueueSubscriber.Common.Security | ||
{ | ||
public interface IAzureTokenProvider | ||
{ | ||
string GetClientAccessToken(string clientId, string clientSecret, string clientResource); | ||
AuthenticationResult GetAuthorisationResult(string clientId, string clientSecret, string clientResource); | ||
} | ||
|
||
public class AzureAzureTokenProvider : IAzureTokenProvider | ||
{ | ||
private readonly AzureAdConfiguration _azureAdConfiguration; | ||
|
||
public AzureAzureTokenProvider(IOptions<AzureAdConfiguration> azureAdConfiguration) | ||
{ | ||
_azureAdConfiguration = azureAdConfiguration.Value; | ||
} | ||
|
||
public string GetClientAccessToken(string clientId, string clientSecret, string clientResource) | ||
{ | ||
var result = GetAuthorisationResult(clientId, clientSecret, clientResource); | ||
return result.AccessToken; | ||
} | ||
|
||
public AuthenticationResult GetAuthorisationResult(string clientId, string clientSecret, string clientResource) | ||
{ | ||
AuthenticationResult result; | ||
var credential = new ClientCredential(clientId, clientSecret); | ||
var authContext = | ||
new AuthenticationContext($"{_azureAdConfiguration.Authority}{_azureAdConfiguration.TenantId}"); | ||
|
||
try | ||
{ | ||
result = authContext.AcquireTokenAsync(clientResource, credential).Result; | ||
} | ||
catch (AdalException) | ||
{ | ||
throw new UnauthorizedAccessException(); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ingQueueSubscriber/BookingQueueSubscriber.Services/BookingQueueSubscriber.Services.csproj
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BookingQueueSubscriber.Common\BookingQueueSubscriber.Common.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
11 changes: 11 additions & 0 deletions
11
...ber/BookingQueueSubscriber.Services/IntegrationEvents/HearingCancelledIntegrationEvent.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,11 @@ | ||
using System; | ||
using BookingQueueSubscriber.Services.MessageHandlers; | ||
|
||
namespace BookingQueueSubscriber.Services.IntegrationEvents | ||
{ | ||
public class HearingCancelledIntegrationEvent : IntegrationEvent | ||
{ | ||
public Guid HearingId { get; set; } | ||
public override IntegrationEventType EventType => IntegrationEventType.HearingCancelled; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ookingQueueSubscriber.Services/IntegrationEvents/HearingDetailsUpdatedIntegrationEvent.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,11 @@ | ||
using BookingQueueSubscriber.Services.MessageHandlers; | ||
using BookingQueueSubscriber.Services.MessageHandlers.Dtos; | ||
|
||
namespace BookingQueueSubscriber.Services.IntegrationEvents | ||
{ | ||
public class HearingDetailsUpdatedIntegrationEvent : IntegrationEvent | ||
{ | ||
public HearingDto Hearing { get; set; } | ||
public override IntegrationEventType EventType => IntegrationEventType.HearingDetailsUpdated; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...okingQueueSubscriber.Services/IntegrationEvents/HearingIsReadyForVideoIntegrationEvent.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,13 @@ | ||
using System.Collections.Generic; | ||
using BookingQueueSubscriber.Services.MessageHandlers; | ||
using BookingQueueSubscriber.Services.MessageHandlers.Dtos; | ||
|
||
namespace BookingQueueSubscriber.Services.IntegrationEvents | ||
{ | ||
public class HearingIsReadyForVideoIntegrationEvent : IntegrationEvent | ||
{ | ||
public HearingDto Hearing { get; set; } | ||
public IList<ParticipantDto> Participants { get; set; } | ||
public override IntegrationEventType EventType => IntegrationEventType.HearingIsReadyForVideo; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
BookingQueueSubscriber/BookingQueueSubscriber.Services/IntegrationEvents/IntegrationEvent.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 @@ | ||
using BookingQueueSubscriber.Services.MessageHandlers; | ||
|
||
namespace BookingQueueSubscriber.Services.IntegrationEvents | ||
{ | ||
public class IntegrationEvent | ||
{ | ||
public virtual IntegrationEventType EventType { get; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ber/BookingQueueSubscriber.Services/IntegrationEvents/ParticipantAddedIntegrationEvent.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,14 @@ | ||
using System; | ||
using BookingQueueSubscriber.Services.MessageHandlers; | ||
using BookingQueueSubscriber.Services.MessageHandlers.Dtos; | ||
|
||
namespace BookingQueueSubscriber.Services.IntegrationEvents | ||
{ | ||
public class ParticipantAddedIntegrationEvent: IntegrationEvent | ||
{ | ||
|
||
public Guid HearingId { get; } | ||
public ParticipantDto Participant { get; } | ||
public override IntegrationEventType EventType => IntegrationEventType.ParticipantAdded; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...r/BookingQueueSubscriber.Services/IntegrationEvents/ParticipantRemovedIntegrationEvent.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,19 @@ | ||
using System; | ||
using BookingQueueSubscriber.Services.MessageHandlers; | ||
|
||
namespace BookingQueueSubscriber.Services.IntegrationEvents | ||
{ | ||
public class ParticipantRemovedIntegrationEvent : IntegrationEvent | ||
{ | ||
public ParticipantRemovedIntegrationEvent(Guid hearingId, Guid participantId) | ||
{ | ||
HearingId = hearingId; | ||
ParticipantId = participantId; | ||
} | ||
|
||
public Guid HearingId { get; } | ||
public Guid ParticipantId { get; } | ||
|
||
public override IntegrationEventType EventType => IntegrationEventType.ParticipantRemoved; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...gQueueSubscriber/BookingQueueSubscriber.Services/Mappers/HearingToBookConferenceMapper.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,28 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using BookingQueueSubscriber.Services.MessageHandlers.Dtos; | ||
using BookingQueueSubscriber.Services.VideoApi.Contracts; | ||
|
||
namespace BookingQueueSubscriber.Services.Mappers | ||
{ | ||
public class HearingToBookConferenceMapper | ||
{ | ||
public BookNewConferenceRequest MapToBookNewConferenceRequest(HearingDto hearingDto, IEnumerable<ParticipantDto> participantDtos) | ||
{ | ||
var participantMapper = new ParticipantToParticipantRequestMapper(); | ||
var participants = participantDtos.Select(participantMapper.MapToParticipantRequest).ToList(); | ||
|
||
var request = new BookNewConferenceRequest | ||
{ | ||
CaseNumber = hearingDto.CaseNumber, | ||
CaseName = hearingDto.CaseName, | ||
CaseType = hearingDto.CaseType, | ||
ScheduledDuration = hearingDto.ScheduledDuration, | ||
ScheduledDateTime = hearingDto.ScheduledDateTime, | ||
HearingRefId = hearingDto.HearingId, | ||
Participants = participants | ||
}; | ||
return request; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...bscriber/BookingQueueSubscriber.Services/Mappers/ParticipantToParticipantRequestMapper.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,24 @@ | ||
using System; | ||
using BookingQueueSubscriber.Services.MessageHandlers.Dtos; | ||
using BookingQueueSubscriber.Services.VideoApi.Contracts; | ||
|
||
namespace BookingQueueSubscriber.Services.Mappers | ||
{ | ||
public class ParticipantToParticipantRequestMapper | ||
{ | ||
public ParticipantRequest MapToParticipantRequest(ParticipantDto participantDto) | ||
{ | ||
var request = new ParticipantRequest | ||
{ | ||
Name = participantDto.Fullname, | ||
Username = participantDto.Username, | ||
DisplayName = participantDto.DisplayName, | ||
UserRole = Enum.Parse<UserRole>(participantDto.UserRole), | ||
CaseTypeGroup = participantDto.CaseGroupType.ToString(), | ||
ParticipantRefId = participantDto.ParticipantId | ||
}; | ||
|
||
return request; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
BookingQueueSubscriber/BookingQueueSubscriber.Services/MessageHandlers/BookingsMessage.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,12 @@ | ||
using System; | ||
using BookingQueueSubscriber.Services.IntegrationEvents; | ||
|
||
namespace BookingQueueSubscriber.Services.MessageHandlers | ||
{ | ||
public class BookingsMessage | ||
{ | ||
public Guid Id { get; set; } | ||
public DateTime Timestamp { get; set; } | ||
public IntegrationEvent IntegrationEvent { get; set; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ueueSubscriber/BookingQueueSubscriber.Services/MessageHandlers/Core/MessageHandlerBase.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,27 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using BookingQueueSubscriber.Services.IntegrationEvents; | ||
|
||
namespace BookingQueueSubscriber.Services.MessageHandlers.Core | ||
{ | ||
public interface IMessageHandler | ||
{ | ||
IntegrationEventType IntegrationEventType { get; } | ||
Type BodyType { get; } | ||
Task HandleAsync(IntegrationEvent integrationEvent); | ||
} | ||
|
||
public abstract class MessageHandlerBase : IMessageHandler | ||
{ | ||
protected IVideoApiService VideoApiService { get; } | ||
public abstract IntegrationEventType IntegrationEventType { get; } | ||
public abstract Type BodyType { get; } | ||
|
||
public abstract Task HandleAsync(IntegrationEvent integrationEvent); | ||
|
||
protected MessageHandlerBase(IVideoApiService videoApiService) | ||
{ | ||
VideoApiService = videoApiService; | ||
} | ||
} | ||
} |
Oops, something went wrong.