Skip to content

Commit

Permalink
feat: add kbo number as prop on ES projections
Browse files Browse the repository at this point in the history
  • Loading branch information
koenmetsu authored and CumpsD committed Mar 10, 2020
1 parent fdf0b5b commit e913fdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Organisation :
IEventHandler<OrganisationCreatedFromKbo>,
IEventHandler<OrganisationInfoUpdated>,
IEventHandler<OrganisationInfoUpdatedFromKbo>,
IEventHandler<OrganisationCoupledWithKbo>,
IEventHandler<PurposeUpdated>
{
private readonly Elastic _elastic;
Expand Down Expand Up @@ -72,6 +73,7 @@ public void Handle(DbConnection dbConnection, DbTransaction dbTransaction, IEnve
ShortName = message.Body.ShortName,
Validity = new Period(message.Body.ValidFrom, message.Body.ValidTo),
Description = message.Body.Description,
KboNumber = message.Body.KboNumber,
ShowOnVlaamseOverheidSites = message.Body.ShowOnVlaamseOverheidSites,
Purposes = message.Body.Purposes.Select(x => new OrganisationDocument.Purpose(x.Id, x.Name)).ToList(),
};
Expand Down Expand Up @@ -109,6 +111,18 @@ public void Handle(DbConnection dbConnection, DbTransaction dbTransaction, IEnve
_elastic.Try(() => _elastic.WriteClient.IndexDocument(organisationDocument).ThrowOnFailure());
}

public void Handle(DbConnection dbConnection, DbTransaction dbTransaction, IEnvelope<OrganisationCoupledWithKbo> message)
{
var organisationDocument = _elastic.TryGet(() => _elastic.WriteClient.Get<OrganisationDocument>(message.Body.OrganisationId).ThrowOnFailure().Source);

organisationDocument.ChangeId = message.Number;
organisationDocument.ChangeTime = message.Timestamp;

organisationDocument.KboNumber = message.Body.KboNumber;

_elastic.Try(() => _elastic.WriteClient.IndexDocument(organisationDocument).ThrowOnFailure());
}

public void Handle(DbConnection dbConnection, DbTransaction dbTransaction, IEnvelope<PurposeUpdated> message)
{
// Update all which use this type, and put the changeId on them too!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class OrganisationDocument : IDocument
public string ShortName { get; set; }
public Period Validity { get; set; }
public string Description { get; set; }
public string KboNumber { get; set; }
public bool? ShowOnVlaamseOverheidSites { get; set; }

public OrganisationDocument() { }
Expand Down Expand Up @@ -53,6 +54,9 @@ public static TypeMappingDescriptor<OrganisationDocument> Mapping(TypeMappingDes
.Name(p => p.Description)
.Analyzer("dutch"))
.Keyword(k => k
.Name(p => p.KboNumber))
.Boolean(b => b
.Name(p => p.ShowOnVlaamseOverheidSites))
Expand Down

0 comments on commit e913fdb

Please sign in to comment.