Skip to content

Commit

Permalink
Merge pull request #33 from DFE-Digital/feature/187393-create-convers…
Browse files Browse the repository at this point in the history
…ion-projects

Create conversion proj - tests failing
  • Loading branch information
sukhybhullar-nimble authored Jan 10, 2025
2 parents c8f952d + 11da0cf commit 7a9beeb
Show file tree
Hide file tree
Showing 29 changed files with 708 additions and 421 deletions.
47 changes: 4 additions & 43 deletions src/Api/Dfe.Complete.Api.Client/Generated/Contracts.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ public partial class CreateConversionProjectCommand
[Newtonsoft.Json.JsonProperty("incomingTrustUkprn", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public Ukprn? IncomingTrustUkprn { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("region", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public Region? Region { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("isDueTo2Ri", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool? IsDueTo2Ri { get; set; } = default!;

Expand All @@ -204,16 +200,15 @@ public partial class CreateConversionProjectCommand
[Newtonsoft.Json.JsonProperty("groupReferenceNumber", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? GroupReferenceNumber { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("provisionalConversionDate", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))]
public System.DateTime? ProvisionalConversionDate { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("handingOverToRegionalCaseworkService", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool? HandingOverToRegionalCaseworkService { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("handoverComments", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? HandoverComments { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("userAdId", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string? UserAdId { get; set; } = default!;

public string ToJson()
{

Expand Down Expand Up @@ -271,39 +266,6 @@ public static Ukprn FromJson(string data)

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public enum Region
{

[System.Runtime.Serialization.EnumMember(Value = @"London")]
London = 0,

[System.Runtime.Serialization.EnumMember(Value = @"SouthEast")]
SouthEast = 1,

[System.Runtime.Serialization.EnumMember(Value = @"YorkshireAndTheHumber")]
YorkshireAndTheHumber = 2,

[System.Runtime.Serialization.EnumMember(Value = @"NorthWest")]
NorthWest = 3,

[System.Runtime.Serialization.EnumMember(Value = @"EastOfEngland")]
EastOfEngland = 4,

[System.Runtime.Serialization.EnumMember(Value = @"WestMidlands")]
WestMidlands = 5,

[System.Runtime.Serialization.EnumMember(Value = @"NorthEast")]
NorthEast = 6,

[System.Runtime.Serialization.EnumMember(Value = @"SouthWest")]
SouthWest = 7,

[System.Runtime.Serialization.EnumMember(Value = @"EastMidlands")]
EastMidlands = 8,

}

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
public partial class Project : BaseAggregateRoot
{
Expand Down Expand Up @@ -365,8 +327,7 @@ public partial class Project : BaseAggregateRoot
public bool? DirectiveAcademyOrder { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("region", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public Region? Region { get; set; } = default!;
public string? Region { get; set; } = default!;

[Newtonsoft.Json.JsonProperty("academyUrn", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public Urn? AcademyUrn { get; set; } = default!;
Expand Down
45 changes: 6 additions & 39 deletions src/Api/Dfe.Complete.Api.Client/Generated/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@
"incomingTrustUkprn": {
"$ref": "#/components/schemas/Ukprn"
},
"region": {
"$ref": "#/components/schemas/Region"
},
"isDueTo2Ri": {
"type": "boolean"
},
Expand All @@ -286,15 +283,15 @@
"groupReferenceNumber": {
"type": "string"
},
"provisionalConversionDate": {
"type": "string",
"format": "date"
},
"handingOverToRegionalCaseworkService": {
"type": "boolean"
},
"handoverComments": {
"type": "string"
},
"userAdId": {
"type": "string",
"nullable": true
}
}
},
Expand All @@ -318,32 +315,6 @@
}
}
},
"Region": {
"type": "string",
"description": "",
"x-enumNames": [
"London",
"SouthEast",
"YorkshireAndTheHumber",
"NorthWest",
"EastOfEngland",
"WestMidlands",
"NorthEast",
"SouthWest",
"EastMidlands"
],
"enum": [
"London",
"SouthEast",
"YorkshireAndTheHumber",
"NorthWest",
"EastOfEngland",
"WestMidlands",
"NorthEast",
"SouthWest",
"EastMidlands"
]
},
"Project": {
"allOf": [
{
Expand Down Expand Up @@ -448,12 +419,8 @@
"nullable": true
},
"region": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/Region"
}
]
"type": "string",
"nullable": true
},
"academyUrn": {
"nullable": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Dfe.Complete.Domain.Enums;
using Dfe.Complete.Domain.Interfaces.Repositories;
using Dfe.Complete.Domain.Entities;
using Dfe.Complete.Utils;

namespace Dfe.Complete.Application.Projects.Commands.CreateProject
{
Expand All @@ -11,29 +12,60 @@ public record CreateConversionProjectCommand(
DateOnly SignificantDate,
bool IsSignificantDateProvisional,
Ukprn IncomingTrustUkprn,
Region Region,
bool IsDueTo2Ri,
bool HasAcademyOrderBeenIssued,
DateOnly AdvisoryBoardDate,
string AdvisoryBoardConditions,
string EstablishmentSharepointLink,
string IncomingTrustSharepointLink,
string GroupReferenceNumber,
DateOnly ProvisionalConversionDate,
bool HandingOverToRegionalCaseworkService,
string HandoverComments) : IRequest<ProjectId>;

public class CreateConversionProjectCommandHandler(ICompleteRepository<Project> projectRepository, ICompleteRepository<ConversionTasksData> conversionTaskRepository)
bool HandingOverToRegionalCaseworkService,
string HandoverComments,
string? UserAdId) : IRequest<ProjectId>;

public class CreateConversionProjectCommandHandler(
ICompleteRepository<Project> projectRepository,
ICompleteRepository<ConversionTasksData> conversionTaskRepository)
: IRequestHandler<CreateConversionProjectCommand, ProjectId>
{
public async Task<ProjectId> Handle(CreateConversionProjectCommand request, CancellationToken cancellationToken)
{
var projectUser = await projectRepository.GetUserByAdId(request.UserAdId, cancellationToken);
var projectUserTeam = projectUser?.Team;
var projectUserId = projectUser?.Id;

var projectTeam = EnumExtensions.FromDescription<ProjectTeam>(projectUserTeam);
var region = EnumMapper.MapTeamToRegion(projectTeam);
var regionCharValue = region.GetCharValue();

var createdAt = DateTime.UtcNow;
var conversionTaskId = Guid.NewGuid();
var projectId = new ProjectId(Guid.NewGuid());

var conversionTask = new ConversionTasksData(new TaskDataId(conversionTaskId), createdAt, createdAt);

var project = Project.CreateConversionProject(request.Urn,
var groupId =
await projectRepository.GetProjectGroupIdByIdentifierAsync(request.GroupReferenceNumber,
cancellationToken);

string team;
DateTime? assignedAt = null;
UserId? projectUserAssignedToId = null;

if (request.HandingOverToRegionalCaseworkService)
{
team = "regional_casework_services";
}
else
{
team = projectTeam.ToDescription();
assignedAt = DateTime.UtcNow;
projectUserAssignedToId = projectUserId;
}

var project = Project.CreateConversionProject(
projectId,
request.Urn,
createdAt,
createdAt,
TaskType.Conversion,
Expand All @@ -42,17 +74,27 @@ public async Task<ProjectId> Handle(CreateConversionProjectCommand request, Canc
request.SignificantDate,
request.IsSignificantDateProvisional,
request.IncomingTrustUkprn,
request.Region,
regionCharValue,
request.IsDueTo2Ri,
request.HasAcademyOrderBeenIssued,
request.AdvisoryBoardDate,
request.AdvisoryBoardConditions,
request.EstablishmentSharepointLink,
request.IncomingTrustSharepointLink,
request.GroupReferenceNumber,
request.ProvisionalConversionDate,
request.HandingOverToRegionalCaseworkService,
request.HandoverComments);
request.IncomingTrustSharepointLink,
groupId?.Value,
team,
projectUser?.Id,
projectUserAssignedToId,
assignedAt);

if (!string.IsNullOrEmpty(request.HandoverComments))
{
project.Notes.Add(new Note
{
Id = new NoteId(Guid.NewGuid()), CreatedAt = createdAt, Body = request.HandoverComments,
ProjectId = projectId, TaskIdentifier = "handover", UserId = projectUser?.Id
});
}

await conversionTaskRepository.AddAsync(conversionTask, cancellationToken);
await projectRepository.AddAsync(project, cancellationToken);
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Dfe.Complete.Domain/Entities/ConversionTasksData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ private ConversionTasksData() { }
public ConversionTasksData(
TaskDataId id,
DateTime createdAt,
DateTime updatedAt
)
DateTime updatedAt)
{
Id = id;
CreatedAt = createdAt != default ? createdAt : throw new ArgumentNullException(nameof(createdAt));
Expand Down
7 changes: 2 additions & 5 deletions src/Core/Dfe.Complete.Domain/Entities/Note.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using Dfe.Complete.Domain.Entities;
using Dfe.Complete.Domain.ValueObjects;
using Dfe.Complete.Domain.ValueObjects;

namespace Dfe.Complete.Infrastructure.Models;
namespace Dfe.Complete.Domain.Entities;

public class Note
{
Expand Down
Loading

0 comments on commit 7a9beeb

Please sign in to comment.