Skip to content

Commit

Permalink
fix: integration projections
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy authored and ArneD committed Feb 5, 2024
1 parent f80bb21 commit f30afeb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static string Map(this StreetNameStatus status)
}
}

public static void UpdateNameByLanguage(this StreetNameVersion item, Language? language, string value)
public static void UpdateNameByLanguage(this StreetNameVersion item, Language? language, string? value)
{
switch (language)
{
Expand All @@ -46,7 +46,7 @@ public static void UpdateNameByLanguage(this StreetNameVersion item, Language? l
}
}

public static void UpdateHomonymAdditionByLanguage(this StreetNameVersion item, Language? language, string value)
public static void UpdateHomonymAdditionByLanguage(this StreetNameVersion item, Language? language, string? value)
{
switch (language)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ await context.NewStreetNameVersion(
await context.NewStreetNameVersion(
message.Message.StreetNameId,
message,
entity => { entity.UpdateNameByLanguage(message.Message.Language, string.Empty); },
entity => { entity.UpdateNameByLanguage(message.Message.Language, null); },
ct);
});

Expand All @@ -80,7 +80,7 @@ await context.NewStreetNameVersion(
await context.NewStreetNameVersion(
message.Message.StreetNameId,
message,
entity => { entity.UpdateNameByLanguage(message.Message.Language, string.Empty); },
entity => { entity.UpdateNameByLanguage(message.Message.Language, null); },
ct);
});

Expand All @@ -107,7 +107,7 @@ await context.NewStreetNameVersion(
await context.NewStreetNameVersion(
message.Message.StreetNameId,
message,
entity => { entity.UpdateHomonymAdditionByLanguage(message.Message.Language, string.Empty); },
entity => { entity.UpdateHomonymAdditionByLanguage(message.Message.Language, null); },
ct);
});

Expand All @@ -116,7 +116,7 @@ await context.NewStreetNameVersion(
await context.NewStreetNameVersion(
message.Message.StreetNameId,
message,
entity => { entity.UpdateHomonymAdditionByLanguage(message.Message.Language, string.Empty); },
entity => { entity.UpdateHomonymAdditionByLanguage(message.Message.Language, null); },
ct);
});

Expand All @@ -143,10 +143,7 @@ await context.NewStreetNameVersion(
await context.NewStreetNameVersion(
message.Message.StreetNameId,
message,
item =>
{
item.IsRemoved = true;
},
item => { item.IsRemoved = true; },
ct);
});

Expand Down Expand Up @@ -267,16 +264,20 @@ await context.NewStreetNameVersion(

When<Envelope<MunicipalityNisCodeWasChanged>>(async (context, message, ct) =>
{
var streetNamePersistentLocalIds = await context.StreetNameVersions.Where(x => x.MunicipalityId == message.Message.MunicipalityId)
.Select(x => x.PersistentLocalId)
.ToListAsync(ct);

foreach (var persistentLocalId in streetNamePersistentLocalIds)
var persistentLocalIds = context
.StreetNameVersions
.Local
.Where(s =>
s.MunicipalityId == message.Message.MunicipalityId)
.Union(context.StreetNameVersions.Where(s =>
s.MunicipalityId == message.Message.MunicipalityId))
.Select(s => s.PersistentLocalId);

foreach (var persistentLocalId in persistentLocalIds)
{
await context.NewStreetNameVersion(persistentLocalId, message, item =>
{
item.NisCode = message.Message.NisCode;
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
}
});
Expand Down Expand Up @@ -341,7 +342,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
item.Status = StreetNameStatus.Current;
item.OsloStatus = StreetNameStatus.Current.Map();
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -351,7 +351,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
item.Status = StreetNameStatus.Proposed;
item.OsloStatus = StreetNameStatus.Proposed.Map();
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -361,7 +360,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
item.Status = StreetNameStatus.Rejected;
item.OsloStatus = StreetNameStatus.Rejected.Map();
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -371,7 +369,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
item.Status = StreetNameStatus.Proposed;
item.OsloStatus = StreetNameStatus.Proposed.Map();
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -381,7 +378,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
item.Status = StreetNameStatus.Retired;
item.OsloStatus = StreetNameStatus.Retired.Map();
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -391,7 +387,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
item.Status = StreetNameStatus.Retired;
item.OsloStatus = StreetNameStatus.Retired.Map();
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -401,7 +396,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
item.Status = StreetNameStatus.Current;
item.OsloStatus = StreetNameStatus.Current.Map();
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -411,7 +405,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
foreach (var (language, value) in message.Message.StreetNameNames)
item.UpdateNameByLanguage(language, value);
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -421,7 +414,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
foreach (var (language, value) in message.Message.StreetNameNames)
item.UpdateNameByLanguage(language, value);
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -431,7 +423,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
{
foreach (var (language, value) in message.Message.HomonymAdditions)
item.UpdateHomonymAdditionByLanguage(language, value);
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand Down Expand Up @@ -460,8 +451,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
throw new ArgumentOutOfRangeException();
}
}

item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});

Expand All @@ -470,7 +459,6 @@ await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, i
await context.NewStreetNameVersion(message.Message.PersistentLocalId, message, item =>
{
item.IsRemoved = true;
item.VersionTimestamp = message.Message.Provenance.Timestamp;
}, ct);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ await ct.StreetNameVersions
expectedLatestItem.PersistentLocalId.Should().Be(persistentLocalId);
expectedLatestItem.NisCode.Should().Be(streetNameWasRegistered.NisCode);

expectedLatestItem.NameDutch.Should().BeEmpty();
expectedLatestItem.NameDutch.Should().BeNull();

expectedLatestItem.Namespace.Should().Be(Namespace);
expectedLatestItem.Puri.Should().Be($"{Namespace}/{persistentLocalId}");
Expand Down Expand Up @@ -930,7 +930,7 @@ await ct.StreetNameVersions
expectedLatestItem.PersistentLocalId.Should().Be(persistentLocalId);
expectedLatestItem.NisCode.Should().Be(streetNameWasRegistered.NisCode);

expectedLatestItem.NameDutch.Should().BeEmpty();
expectedLatestItem.NameDutch.Should().BeNull();

expectedLatestItem.Namespace.Should().Be(Namespace);
expectedLatestItem.Puri.Should().Be($"{Namespace}/{persistentLocalId}");
Expand Down Expand Up @@ -1080,7 +1080,7 @@ await ct.StreetNameVersions
expectedLatestItem.PersistentLocalId.Should().Be(persistentLocalId);
expectedLatestItem.NisCode.Should().Be(streetNameWasRegistered.NisCode);

expectedLatestItem.HomonymAdditionDutch.Should().BeEmpty();
expectedLatestItem.HomonymAdditionDutch.Should().BeNull();

expectedLatestItem.Namespace.Should().Be(Namespace);
expectedLatestItem.Puri.Should().Be($"{Namespace}/{persistentLocalId}");
Expand Down Expand Up @@ -1137,7 +1137,7 @@ await ct.StreetNameVersions
expectedLatestItem.PersistentLocalId.Should().Be(persistentLocalId);
expectedLatestItem.NisCode.Should().Be(streetNameWasRegistered.NisCode);

expectedLatestItem.HomonymAdditionDutch.Should().BeEmpty();
expectedLatestItem.HomonymAdditionDutch.Should().BeNull();

expectedLatestItem.Namespace.Should().Be(Namespace);
expectedLatestItem.Puri.Should().Be($"{Namespace}/{persistentLocalId}");
Expand Down

0 comments on commit f30afeb

Please sign in to comment.