From 698fe05a66df818fbcd11b3d36428f6a254da259 Mon Sep 17 00:00:00 2001 From: Mark Youngman Date: Thu, 9 Jan 2025 14:33:31 +0000 Subject: [PATCH] EES-5707 Remove geojson cache file after updating data block with map chart --- .../Services/DataBlockService.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/DataBlockService.cs b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/DataBlockService.cs index 8366c78f0ad..2d3237ff71b 100644 --- a/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/DataBlockService.cs +++ b/src/GovUk.Education.ExploreEducationStatistics.Admin/Services/DataBlockService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using AutoMapper; +using GovUk.Education.ExploreEducationStatistics.Admin.Cache; using GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces; using GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces.Cache; using GovUk.Education.ExploreEducationStatistics.Admin.Services.Interfaces.Security; @@ -217,7 +218,7 @@ public async Task> Update( .OnSuccessDo(dataBlock => _userService.CheckCanUpdateReleaseVersion(dataBlock.ReleaseVersion)) .OnSuccessDo(async dataBlockVersion => { - // TODO EES-753 Alter this when multiple charts are supported + // Remove old infographic file if using a new file var infographicChart = dataBlockVersion.Charts.OfType().FirstOrDefault(); var updatedInfographicChart = updateRequest.Charts.OfType().FirstOrDefault(); @@ -229,6 +230,14 @@ await _releaseFileService.Delete(releaseVersionId: dataBlockVersion.ReleaseVersi fileId: new Guid(infographicChart.FileId)); } + // If has map chart, remove geojson cache + var mapChart = dataBlockVersion.Charts.OfType().FirstOrDefault(); + if (mapChart != null) + { + await _cacheService.DeleteItemAsync( + new LocationsForDataBlockCacheKey(dataBlockVersion, mapChart.BoundaryLevel)); + } + _mapper.Map(updateRequest, dataBlockVersion.ContentBlock); _context.DataBlocks.Update(dataBlockVersion.ContentBlock);