Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS-1501] extend AssetContract with additional fields #78

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
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,48 @@ 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);
LBHTKarki marked this conversation as resolved.
Show resolved Hide resolved
domainContract.TargetId.Should().Be(queryableAssetContract.TargetId);
domainContract.StartDate.Should().Be(queryableAssetContract.StartDate);
domainContract.ApprovalDate.Should().Be(queryableAssetContract.ApprovalDate);
domainContract.IsApproved.Should().Be(queryableAssetContract.IsApproved);
domainContract.Charges.Should().BeEquivalentTo(queryableAssetContract.Charges);
domainContract.RelatedPeople.Should().BeEquivalentTo(queryableAssetContract.RelatedPeople);
}

[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);
}
}
}
}
23 changes: 4 additions & 19 deletions Hackney.Shared.HousingSearch/Domain/Asset/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,13 @@ namespace Hackney.Shared.HousingSearch.Domain.Asset
{
public class Contract
{
public static Contract Create(string id, string targetId, string targetType, IEnumerable<Charges> charges)
{
return new Contract(
id,
targetId,
targetType,
charges
);
}
public Contract() { }

private Contract(string id, string targetId, string targetType, IEnumerable<Charges> charges)
{
Id = id;
TargetId = targetId;
TargetType = targetType;
Charges = charges;
}

public string Id { get; set; }
public string TargetId { get; set; }
public string TargetType { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? ApprovalDate { get; set; }
public bool? IsApproved { get; set; }
public IEnumerable<Charges> Charges { get; set; }
public IEnumerable<RelatedPeople> RelatedPeople { get; set; }
}
}
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; }
}
}
}
28 changes: 6 additions & 22 deletions Hackney.Shared.HousingSearch/Domain/Contract/Contract.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
using Hackney.Shared.HousingSearch.Domain.Contract;
using Hackney.Shared.HousingSearch.Gateways.Models.Contract;
using Hackney.Shared.HousingSearch.Gateways.Models.Contract;
using System;
using System.Collections.Generic;

namespace Hackney.Shared.HousingSearch.Domain.Contract
{
public class Contract
{
public static Contract Create(string id, string targetId, string targetType, IEnumerable<QueryableCharges> charges)
{
LBHTKarki marked this conversation as resolved.
Show resolved Hide resolved
return new Contract(
id,
targetId,
targetType,
charges
);
}
public Contract() { }

private Contract(string id, string targetId, string targetType, IEnumerable<QueryableCharges> charges)
{
Id = id;
TargetId = targetId;
TargetType = targetType;
Charges = charges;
}

public string Id { get; set; }
public string TargetId { get; set; }
public string TargetType { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? ApprovalDate { get; set; }
public bool? IsApproved { get; set; }
public IEnumerable<QueryableCharges> Charges { get; set; }
public IEnumerable<QueryableRelatedPeople> RelatedPeople { get; set; }
}
}
}
10 changes: 10 additions & 0 deletions Hackney.Shared.HousingSearch/Domain/Contract/RelatedPeople.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Hackney.Shared.HousingSearch.Domain.Contract
{
public class RelatedPeople
{
public string Id { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public string Name { get; set; }
}
}
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());
}

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());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Hackney.Shared.HousingSearch.Domain.Asset;
using Hackney.Shared.HousingSearch.Factories;
using Nest;
using Asset = Hackney.Shared.HousingSearch.Domain.Asset.Asset;

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

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

return Asset.CreateAll(
Id,
Expand Down Expand Up @@ -218,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,22 +1,20 @@
using Hackney.Shared.HousingSearch.Gateways.Models.Contract;
using System;
using Hackney.Shared.HousingSearch.Gateways.Models.Contract;
using Nest;
using System;
using System.Collections.Generic;
using System.Text;

namespace Hackney.Shared.HousingSearch.Gateways.Models.Assets
{
public class QueryableAssetContract
{
public Domain.Contract.Contract Create()
{
return Domain.Contract.Contract.Create(Id, TargetId, TargetType, Charges);
}

[Text(Name = "id")]
public string Id { get; set; }
public string TargetId { get; set; }
public string TargetType { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? ApprovalDate { get; set; }
public bool? IsApproved { get; set; }
public IEnumerable<QueryableCharges> Charges { get; set; }
public IEnumerable<QueryableRelatedPeople> RelatedPeople { 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
@@ -0,0 +1,13 @@
using Hackney.Shared.HousingSearch.Domain.Contract;
using Nest;

namespace Hackney.Shared.HousingSearch.Gateways.Models.Contract
{
public class QueryableRelatedPeople
{
[Text(Name = "id")] public string Id { get; set; }
public string Type { get; set; }
public string SubType { get; set; }
public string Name { get; set; }
}
}
Loading