Skip to content

Commit

Permalink
[TS-1501] use factory to build contract domain entity
Browse files Browse the repository at this point in the history
  • Loading branch information
LBHJHeppinstall committed Jul 10, 2024
1 parent 4c24acb commit f9c978c
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AutoFixture;
using FluentAssertions;
using Hackney.Shared.HousingSearch.Factories;
using Hackney.Shared.HousingSearch.Gateways.Models.Assets;
using Hackney.Shared.HousingSearch.Gateways.Models.Contract;
using Hackney.Shared.HousingSearch.Gateways.Models.Tenures;
using Xunit;

Expand Down Expand Up @@ -44,5 +46,46 @@ public void CanConvertQueryableTempAccommodationOfficerEntityToDomain()
domainTAOfficer.FirstName.Should().Be(queryableTAOfficer.FirstName);
domainTAOfficer.LastName.Should().Be(queryableTAOfficer.LastName);
}

[Fact]
public void CanConvertQueryableAssetContractEntityToDomain()
{
var queryableAssetContract = _fixture.Create<QueryableAssetContract>();

var domainContract = queryableAssetContract.ToDomain();

domainContract.Id.Should().Be(queryableAssetContract.Id);
domainContract.TargetId.Should().Be(queryableAssetContract.TargetId);
domainContract.StartDate.Should().Be(queryableAssetContract.StartDate);
domainContract.ApprovalDate.Should().Be(queryableAssetContract.ApprovalDate);
domainContract.IsApproved.Should().Be(queryableAssetContract.IsApproved);
}

[Fact]
public void CanConvertQueryableChargesEntityToDomain()
{
var queryableCharge = _fixture.Create<QueryableCharges>();

var domainCharge = queryableCharge.ToDomain();

domainCharge.Id.Should().Be(queryableCharge.Id);
domainCharge.Type.Should().Be(queryableCharge.Type);
domainCharge.SubType.Should().Be(queryableCharge.SubType);
domainCharge.Frequency.Should().Be(queryableCharge.Frequency);
domainCharge.Amount.Should().Be(queryableCharge.Amount);
}

[Fact]
public void CanConvertQueryableRelatedPeopleEntityToDomain()
{
var queryableRelatedPerson = _fixture.Create<QueryableRelatedPeople>();

var domainRelatedPerson = queryableRelatedPerson.ToDomain();

domainRelatedPerson.Id.Should().Be(queryableRelatedPerson.Id);
domainRelatedPerson.Type.Should().Be(queryableRelatedPerson.Type);
domainRelatedPerson.SubType.Should().Be(queryableRelatedPerson.SubType);
domainRelatedPerson.Name.Should().Be(queryableRelatedPerson.Name);
}
}
}
}
29 changes: 0 additions & 29 deletions Hackney.Shared.HousingSearch/Domain/Asset/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,6 @@ namespace Hackney.Shared.HousingSearch.Domain.Asset
{
public class Contract
{
public static Contract Create(string id, string targetId, string targetType, DateTime? startDate, DateTime? approvalDate,
bool? isApproved, IEnumerable<Charges> charges, IEnumerable<RelatedPeople> relatedPeople)
{
return new Contract(
id,
targetId,
targetType,
startDate,
approvalDate,
isApproved,
charges,
relatedPeople
);
}
public Contract() { }

private Contract(string id, string targetId, string targetType, DateTime? startDate, DateTime? approvalDate,
bool? isApproved, IEnumerable<Charges> charges, IEnumerable<RelatedPeople> relatedPeople)
{
Id = id;
TargetId = targetId;
TargetType = targetType;
StartDate = startDate;
ApprovalDate = approvalDate;
IsApproved = isApproved;
Charges = charges;
RelatedPeople = relatedPeople;
}

public string Id { get; set; }
public string TargetId { get; set; }
public string TargetType { get; set; }
Expand Down
24 changes: 2 additions & 22 deletions Hackney.Shared.HousingSearch/Domain/Contract/Charges.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Hackney.Shared.HousingSearch.Domain.Contract
namespace Hackney.Shared.HousingSearch.Domain.Contract
{
public class Charges
{
public Charges() { }

public static Charges Create(string id, string type, string subType, string frequency, decimal? amount)
{
return new Charges(id, type, subType, frequency, amount);
}

private Charges(string id, string type, string subType, string frequency, decimal? amount)
{
Id = id;
Type = type;
SubType = subType;
Frequency = frequency;
Amount = amount;
}

public string Id { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public string Frequency { get; set; }
public decimal? Amount { get; set; }
}
}
}
15 changes: 0 additions & 15 deletions Hackney.Shared.HousingSearch/Domain/Contract/RelatedPeople.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
{
public class RelatedPeople
{
public RelatedPeople() { }

public static RelatedPeople Create(string id, string type, string subType, string name)
{
return new RelatedPeople(id, type, subType, name);
}

private RelatedPeople(string id, string type, string subType, string name)
{
Id = id;
Type = type;
SubType = subType;
Name = name;
}

public string Id { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
Expand Down
61 changes: 58 additions & 3 deletions Hackney.Shared.HousingSearch/Factories/DomainFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
using System.Collections.Generic;
using System.Linq;
using System;
using Hackney.Shared.HousingSearch.Domain.Contract;
using RelatedEntity = Hackney.Shared.HousingSearch.Domain.Process.RelatedEntity;
using PatchAssignment = Hackney.Shared.HousingSearch.Domain.Process.PatchAssignment;
using Hackney.Shared.HousingSearch.Domain.Tenure;
using Hackney.Shared.HousingSearch.Gateways.Models.Assets;
using Hackney.Shared.HousingSearch.Gateways.Models.Contract;
using Hackney.Shared.HousingSearch.Gateways.Models.Tenures;

namespace Hackney.Shared.HousingSearch.Factories
Expand Down Expand Up @@ -50,8 +53,12 @@ public static DomainProcess ToDomain(this QueryableProcess entity)
PatchAssignment = entity.PatchAssignment?.ToDomain(),
RelatedEntities = entity.RelatedEntities.ToDomain(),
State = entity.State,
ProcessStartedAt = (entity.ProcessStartedAt is null ? (DateTime?)null : DateTime.Parse(entity.ProcessStartedAt)),
StateStartedAt = (entity.StateStartedAt is null ? (DateTime?)null : DateTime.Parse(entity.StateStartedAt))
ProcessStartedAt = (entity.ProcessStartedAt is null
? (DateTime?)null
: DateTime.Parse(entity.ProcessStartedAt)),
StateStartedAt = (entity.StateStartedAt is null
? (DateTime?)null
: DateTime.Parse(entity.StateStartedAt))
};
}

Expand All @@ -74,5 +81,53 @@ public static TempAccommodationOfficer ToDomain(this QueryableTempAccommodationO
LastName = entity.LastName
};
}

public static Domain.Asset.Contract ToDomain(this QueryableAssetContract entity)
{
return new Domain.Asset.Contract
{
Id = entity.Id,
TargetId = entity.TargetId,
TargetType = entity.TargetType,
StartDate = entity.StartDate,
ApprovalDate = entity.ApprovalDate,
IsApproved = entity.IsApproved,
Charges = entity.Charges?.ToDomain(),
RelatedPeople = entity.RelatedPeople?.ToDomain(),
};
}

public static Charges ToDomain(this QueryableCharges entity)
{
return new Charges
{
Id = entity.Id,
Type = entity.Type,
SubType = entity.SubType,
Frequency = entity.Frequency,
Amount = entity.Amount
};
}

public static IEnumerable<Charges> ToDomain(this IEnumerable<QueryableCharges> charges)
{
return charges.Select(x => x.ToDomain()).ToList();
}

public static RelatedPeople ToDomain(this QueryableRelatedPeople entity)
{
return new RelatedPeople
{
Id = entity.Id,
Type = entity.Type,
SubType = entity.SubType,
Name = entity.Name
};
}

public static IEnumerable<RelatedPeople> ToDomain(this IEnumerable<QueryableRelatedPeople> relatedPeople)
{
return relatedPeople.Select(x => x.ToDomain()).ToList();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using Hackney.Shared.HousingSearch.Factories;
using Nest;
using Asset = Hackney.Shared.HousingSearch.Domain.Asset.Asset;

Expand Down Expand Up @@ -157,18 +157,7 @@ public Asset CreateAll()
AssetLocation.FloorNo
);

var contract = AssetContract == null
? null
: Domain.Asset.Contract.Create(
AssetContract.Id,
AssetContract.TargetId,
AssetContract.TargetType,
AssetContract.StartDate,
AssetContract.ApprovalDate,
AssetContract.IsApproved,
AssetContract.Charges?.Select(p => p.Create()).ToList(),
AssetContract.RelatedPeople?.Select(p => p.Create()).ToList()
);
var contract = AssetContract?.ToDomain();

return Asset.CreateAll(
Id,
Expand Down Expand Up @@ -220,6 +209,7 @@ public Asset CreateAll()
public QueryableAssetManagement AssetManagement { get; set; }

public QueryableAssetLocation AssetLocation { get; set; }

public QueryableAssetContract AssetContract { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
using Hackney.Shared.HousingSearch.Domain.Contract;
using Nest;
using System;
using System.Collections.Generic;
using System.Text;
using Nest;

namespace Hackney.Shared.HousingSearch.Gateways.Models.Contract
{
public class QueryableCharges
{
public Charges Create()
{
return Charges.Create(
Id,
Type,
SubType,
Frequency,
Amount
);
}
[Text(Name = "id")]
public string Id { get; set; }
[Text(Name = "id")] public string Id { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public string Frequency { get; set; }
public decimal? Amount { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@ namespace Hackney.Shared.HousingSearch.Gateways.Models.Contract
{
public class QueryableRelatedPeople
{
public RelatedPeople Create()
{
return RelatedPeople.Create(
Id,
Type,
SubType,
Name
);
}
[Text(Name = "id")]
public string Id { get; set; }
[Text(Name = "id")] public string Id { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public string Name { get; set; }
}
}
}

0 comments on commit f9c978c

Please sign in to comment.