Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 0 additions & 87 deletions src/Dfe.SignIn.Core.Interfaces/DataAccess/IUnitOfWork.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<ProjectReference Include="..\Dfe.SignIn.Core.Contracts\Dfe.SignIn.Core.Contracts.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="DataAccess\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Applications;
using Dfe.SignIn.Core.Contracts.PublicApi;
using Dfe.SignIn.Core.Entities.Organisations;
using Dfe.SignIn.Core.Interfaces.DataAccess;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;

namespace Dfe.SignIn.Core.UseCases.Applications;
Expand All @@ -11,8 +10,8 @@ namespace Dfe.SignIn.Core.UseCases.Applications;
/// Use case responsible for obtaining the Public API configuration of an application.
/// </summary>
public sealed class GetApplicationApiConfigurationUseCase(
IInteractionDispatcher interaction,
IUnitOfWorkOrganisations uowOrganisations
DbOrganisationsContext uowOrganisations,
IInteractionDispatcher interaction
) : Interactor<GetApplicationApiConfigurationRequest, GetApplicationApiConfigurationResponse>
{
/// <inheritdoc/>
Expand All @@ -22,7 +21,7 @@ public override async Task<GetApplicationApiConfigurationResponse> InvokeAsync(
{
context.ThrowIfHasValidationErrors();

var serviceEntity = await uowOrganisations.Repository<ServiceEntity>()
var serviceEntity = await uowOrganisations.Services
.Select(x => new {
x.ClientId,
x.ApiSecret,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Applications;
using Dfe.SignIn.Core.Entities.Organisations;
using Dfe.SignIn.Core.Interfaces.DataAccess;
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(
IUnitOfWorkOrganisations uowOrganisations
) : Interactor<GetApplicationByClientIdRequest, GetApplicationByClientIdResponse>
public sealed class GetApplicationByClientIdUseCase(DbOrganisationsContext uowOrganisations) : Interactor<GetApplicationByClientIdRequest, GetApplicationByClientIdResponse>
{
/// <inheritdoc/>
public override async Task<GetApplicationByClientIdResponse> InvokeAsync(
Expand All @@ -20,7 +17,7 @@ public override async Task<GetApplicationByClientIdResponse> InvokeAsync(
{
context.ThrowIfHasValidationErrors();

var serviceEntity = await uowOrganisations.Repository<ServiceEntity>()
var serviceEntity = await uowOrganisations.Services
.Select(x => new {
x.Id,
x.ClientId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System.Data;
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Applications;
using Dfe.SignIn.Core.Entities.Organisations;
using Dfe.SignIn.Core.Interfaces.DataAccess;
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 GetApplicationRolesUseCase(
IUnitOfWorkOrganisations uowOrganisations
) : Interactor<GetApplicationRolesRequest, GetApplicationRolesResponse>
public sealed class GetApplicationRolesUseCase(DbOrganisationsContext uowOrganisations) : Interactor<GetApplicationRolesRequest, GetApplicationRolesResponse>
{
/// <inheritdoc/>
public override async Task<GetApplicationRolesResponse> InvokeAsync(
Expand All @@ -21,7 +18,7 @@ public override async Task<GetApplicationRolesResponse> InvokeAsync(
{
context.ThrowIfHasValidationErrors();

var roles = await uowOrganisations.Repository<RoleEntity>()
var roles = await uowOrganisations.Roles
.Include(r => r.Parent)
.Where(r => r.ApplicationId == context.Request.ApplicationId)
.OrderBy(r => r.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ProjectReference Include="..\Dfe.SignIn.Core.Entities\Dfe.SignIn.Core.Entities.csproj" />
<ProjectReference Include="..\Dfe.SignIn.Core.Interfaces\Dfe.SignIn.Core.Interfaces.csproj" />
<ProjectReference Include="..\Dfe.SignIn.Core.Public\Dfe.SignIn.Core.Public.csproj" />
<ProjectReference Include="..\Dfe.SignIn.Gateways.EntityFramework\Dfe.SignIn.Gateways.EntityFramework.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Organisations;
using Dfe.SignIn.Core.Entities.Organisations;
using Dfe.SignIn.Core.Interfaces.DataAccess;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;

namespace Dfe.SignIn.Core.UseCases.Organisations;

/// <summary>
/// Use case for getting information about an organisation.
/// </summary>
public sealed class GetOrganisationByIdUseCase(
IUnitOfWorkOrganisations uowOrganisations
) : Interactor<GetOrganisationByIdRequest, GetOrganisationByIdResponse>
public sealed class GetOrganisationByIdUseCase(DbOrganisationsContext uowOrganisations) : Interactor<GetOrganisationByIdRequest, GetOrganisationByIdResponse>
{
/// <inheritdoc/>
public override async Task<GetOrganisationByIdResponse> InvokeAsync(
Expand All @@ -20,7 +17,7 @@ public override async Task<GetOrganisationByIdResponse> InvokeAsync(
{
context.ThrowIfHasValidationErrors();

var organisationEntity = await uowOrganisations.Repository<OrganisationEntity>()
var organisationEntity = await uowOrganisations.Organisations
.Where(x => x.Id == context.Request.OrganisationId)
.FirstOrDefaultAsync(cancellationToken)
?? throw OrganisationNotFoundException.FromOrganisationId(context.Request.OrganisationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Linq.Expressions;
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Organisations;
using Dfe.SignIn.Core.Entities.Directories;

using Dfe.SignIn.Core.Entities.Organisations;
using Dfe.SignIn.Core.Interfaces.DataAccess;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;

namespace Dfe.SignIn.Core.UseCases.Organisations;
Expand All @@ -13,9 +13,7 @@ namespace Dfe.SignIn.Core.UseCases.Organisations;
/// Query returns users and their roles for a service and organisation.
/// </summary>
/// <param name="uowOrganisations"></param>
public sealed class GetUsersAtOrganisationUseCase(
IUnitOfWorkOrganisations uowOrganisations
) : Interactor<GetUsersAtOrganisationRequestRaw, GetUsersAtOrganisationResponseRaw>
public sealed class GetUsersAtOrganisationUseCase(DbOrganisationsContext uowOrganisations) : Interactor<GetUsersAtOrganisationRequestRaw, GetUsersAtOrganisationResponseRaw>
{
/// <inheritdoc/>
public override async Task<GetUsersAtOrganisationResponseRaw> InvokeAsync(
Expand Down Expand Up @@ -53,18 +51,18 @@ private IQueryable<UserAtOrganisationRaw> BuildQuery(
Expression<Func<OrganisationEntity, bool>> organisationFilter)
{
var organisations = uowOrganisations
.Repository<OrganisationEntity>()
.Organisations
.Where(organisationFilter);

return
from us in uowOrganisations.Repository<UserServiceEntity>()
from us in uowOrganisations.UserServices
join o in organisations
on us.OrganisationId equals o.Id
join u in uowOrganisations.Repository<UserEntity>()
join u in uowOrganisations.Users
on us.UserId equals u.Sub
join s in uowOrganisations.Repository<ServiceEntity>()
join s in uowOrganisations.Services
on us.ServiceId equals s.Id
join usr in uowOrganisations.Repository<UserServiceRoleEntity>()
join usr in uowOrganisations.UserServiceRoles
on new {
oid = us.OrganisationId,
sid = us.ServiceId,
Expand All @@ -77,7 +75,7 @@ join usr in uowOrganisations.Repository<UserServiceRoleEntity>()
}
into usrGroup
from usr in usrGroup.DefaultIfEmpty()
join r in uowOrganisations.Repository<RoleEntity>()
join r in uowOrganisations.Roles
on usr.RoleId equals r.Id
into roleGroup
from r in roleGroup.DefaultIfEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.SupportTickets;
using Dfe.SignIn.Core.Entities.Organisations;
using Dfe.SignIn.Core.Interfaces.DataAccess;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;

namespace Dfe.SignIn.Core.UseCases.SupportTickets;
Expand All @@ -10,9 +9,7 @@ namespace Dfe.SignIn.Core.UseCases.SupportTickets;
/// Use case for getting a list of application names that can be chosen from
/// when raising a support ticket.
/// </summary>
public sealed class GetApplicationNamesForSupportTicketUseCase(
IUnitOfWorkOrganisations unitOfWork
) : Interactor<GetApplicationNamesForSupportTicketRequest, GetApplicationNamesForSupportTicketResponse>
public sealed class GetApplicationNamesForSupportTicketUseCase(DbOrganisationsContext unitOfWork) : Interactor<GetApplicationNamesForSupportTicketRequest, GetApplicationNamesForSupportTicketResponse>
{
/// <inheritdoc/>
public override async Task<GetApplicationNamesForSupportTicketResponse> InvokeAsync(
Expand All @@ -21,7 +18,7 @@ public override async Task<GetApplicationNamesForSupportTicketResponse> InvokeAs
{
context.ThrowIfHasValidationErrors();

var applications = await unitOfWork.Repository<ServiceEntity>()
var applications = await unitOfWork.Services
.Where(x => !x.IsChildService && !x.ServiceParams.Any(sp =>
sp.ParamName == "helpHidden" &&
sp.ParamValue == "true"))
Expand Down
7 changes: 3 additions & 4 deletions src/Dfe.SignIn.Core.UseCases/Users/ChangeJobTitleUseCase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Audit;
using Dfe.SignIn.Core.Contracts.Users;
using Dfe.SignIn.Core.Entities.Directories;
using Dfe.SignIn.Core.Interfaces.DataAccess;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;

namespace Dfe.SignIn.Core.UseCases.Users;
Expand All @@ -11,7 +10,7 @@ namespace Dfe.SignIn.Core.UseCases.Users;
/// An interactor to change the job title of a user.
/// </summary>
public sealed class ChangeJobTitleUseCase(
IUnitOfWorkDirectories unitOfWork,
DbDirectoriesContext unitOfWork,
IInteractionDispatcher interaction
) : Interactor<ChangeJobTitleRequest, ChangeJobTitleResponse>
{
Expand All @@ -22,7 +21,7 @@ public override async Task<ChangeJobTitleResponse> InvokeAsync(
{
context.ThrowIfHasValidationErrors();

var user = await unitOfWork.Repository<UserEntity>()
var user = await unitOfWork.Users
.Where(x => x.Sub == context.Request.UserId)
.FirstOrDefaultAsync(cancellationToken) ?? throw UserNotFoundException.FromUserId(context.Request.UserId);

Expand Down
7 changes: 3 additions & 4 deletions src/Dfe.SignIn.Core.UseCases/Users/ChangeNameUseCase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Dfe.SignIn.Base.Framework;
using Dfe.SignIn.Core.Contracts.Audit;
using Dfe.SignIn.Core.Contracts.Users;
using Dfe.SignIn.Core.Entities.Directories;
using Dfe.SignIn.Core.Interfaces.DataAccess;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;

namespace Dfe.SignIn.Core.UseCases.Users;
Expand All @@ -11,7 +10,7 @@ namespace Dfe.SignIn.Core.UseCases.Users;
/// An interactor to change the job title of a user.
/// </summary>
public sealed class ChangeNameUseCase(
IUnitOfWorkDirectories unitOfWork,
DbDirectoriesContext unitOfWork,
IInteractionDispatcher interaction
) : Interactor<ChangeNameRequest, ChangeNameResponse>
{
Expand All @@ -22,7 +21,7 @@ public override async Task<ChangeNameResponse> InvokeAsync(
{
context.ThrowIfHasValidationErrors();

var user = await unitOfWork.Repository<UserEntity>()
var user = await unitOfWork.Users
.Where(x => x.Sub == context.Request.UserId)
.FirstOrDefaultAsync(cancellationToken) ?? throw UserNotFoundException.FromUserId(context.Request.UserId);

Expand Down
6 changes: 3 additions & 3 deletions src/Dfe.SignIn.Core.UseCases/Users/CreateUserUseCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Dfe.SignIn.Core.Contracts.Search;
using Dfe.SignIn.Core.Contracts.Users;
using Dfe.SignIn.Core.Entities.Directories;
using Dfe.SignIn.Core.Interfaces.DataAccess;
using Dfe.SignIn.Gateways.EntityFramework;
using Microsoft.EntityFrameworkCore;

namespace Dfe.SignIn.Core.UseCases.Users;
Expand All @@ -20,8 +20,8 @@
/// Review login.dfe.directories for implementation details.</para>
/// </remarks>
public sealed class CreateUserUseCase(
DbDirectoriesContext unitOfWork,
IInteractionDispatcher interaction,
IUnitOfWorkDirectories unitOfWork,
TimeProvider timeProvider
) : Interactor<CreateUserRequest, CreateUserResponse>
{
Expand All @@ -32,7 +32,7 @@
{
context.ThrowIfHasValidationErrors();

var user = await unitOfWork.Repository<UserEntity>()
var user = await unitOfWork.Users
.Where(x =>
x.Email == context.Request.EmailAddress ||
x.EntraOid == context.Request.EntraUserId)
Expand All @@ -53,7 +53,7 @@
FirstName = context.Request.FirstName,
IsEntra = true,
LastName = context.Request.LastName,
Password = "none",

Check warning on line 56 in src/Dfe.SignIn.Core.UseCases/Users/CreateUserUseCase.cs

View workflow job for this annotation

GitHub Actions / .NET checks / tests

"password" detected here, make sure this is not a hard-coded credential.

Check warning on line 56 in src/Dfe.SignIn.Core.UseCases/Users/CreateUserUseCase.cs

View workflow job for this annotation

GitHub Actions / .NET checks / tests

"password" detected here, make sure this is not a hard-coded credential.

Check warning on line 56 in src/Dfe.SignIn.Core.UseCases/Users/CreateUserUseCase.cs

View workflow job for this annotation

GitHub Actions / .NET checks / tests

"password" detected here, make sure this is not a hard-coded credential.
Salt = string.Empty,
Status = (int)AccountStatus.Active,
Sub = Guid.NewGuid(),
Expand Down
Loading
Loading