-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGetApplicationByClientIdUseCase.cs
More file actions
57 lines (52 loc) · 2.21 KB
/
Copy pathGetApplicationByClientIdUseCase.cs
File metadata and controls
57 lines (52 loc) · 2.21 KB
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
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Applications;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;
namespace Dfe.SignIn.Core.UseCases.Applications;
/// <summary>
/// Use case responsible for obtaining information about an application.
/// </summary>
public sealed class GetApplicationByClientIdUseCase(DbOrganisationsContext uowOrganisations) : Interactor<GetApplicationByClientIdRequest, GetApplicationByClientIdResponse>
{
/// <inheritdoc/>
public override async Task<GetApplicationByClientIdResponse> InvokeAsync(
InteractionContext<GetApplicationByClientIdRequest> context,
CancellationToken cancellationToken = default)
{
context.ThrowIfHasValidationErrors();
var serviceEntity = await uowOrganisations.Services
.Select(x => new {
x.Id,
x.ClientId,
x.Description,
x.Name,
x.ServiceHome,
x.IsExternalService,
x.IsHiddenService,
x.IsIdOnlyService,
x.ParentId,
ParentClientId = x.Parent != null ? x.Parent.ClientId : null,
})
.SingleOrDefaultAsync(
x => x.ClientId == context.Request.ClientId,
cancellationToken
) ?? throw new ApplicationNotFoundException(null, context.Request.ClientId);
Uri? serviceHomeUrl = !string.IsNullOrWhiteSpace(serviceEntity.ServiceHome)
? new Uri(serviceEntity.ServiceHome)
: null;
return new GetApplicationByClientIdResponse {
Application = new() {
Id = serviceEntity.Id,
ClientId = serviceEntity.ClientId,
Description = serviceEntity.Description,
Name = serviceEntity.Name,
ServiceHomeUrl = serviceHomeUrl,
IsExternalService = serviceEntity.IsExternalService,
IsHiddenService = serviceEntity.IsHiddenService,
IsIdOnlyService = serviceEntity.IsIdOnlyService,
ParentId = serviceEntity.ParentId,
ParentClientId = serviceEntity.ParentClientId,
}
};
}
}