From 0584fececf5d545abcc410d76c6317925d292239 Mon Sep 17 00:00:00 2001 From: danjov Date: Tue, 11 Oct 2022 14:56:12 +0200 Subject: [PATCH] Remove obsolete migration endpoint --- .../GemeindeMigrationController.cs | 62 ------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/Controllers/GemeindeMigrationController.cs diff --git a/src/Controllers/GemeindeMigrationController.cs b/src/Controllers/GemeindeMigrationController.cs deleted file mode 100644 index d619626..0000000 --- a/src/Controllers/GemeindeMigrationController.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace EWS; - -[ApiController] -[Route("[controller]")] -public class GemeindeMigrationController : ControllerBase -{ - private readonly EwsContext context; - private readonly DataService dataService; - - public GemeindeMigrationController(EwsContext context, DataService dataService) - { - this.context = context; - this.dataService = dataService; - } - - [HttpGet("/migrategemeinden")] - public async Task MigrateGemeinden([FromQuery] bool dryRun = true) - { - int found = 0; - Dictionary notFound = new(), errors = new(); - - // Only consider Standorte with Bohrungen - var standorteToMigrate = context.Standorte.Include(x => x.Bohrungen).Where(x => x.Bohrungen != null && x.Bohrungen.Any()).ToList(); - - await Parallel.ForEachAsync(standorteToMigrate, async (standort, _) => - { - var standortId = $"{standort.Id}: {standort.Bezeichnung}"; - - // Query data service for Gemeinde data with Bohrungen points - var geometries = standort.Bohrungen!.Where(x => x.Geometrie != null).Select(x => x.Geometrie).ToList(); - - try - { - var dataServiceResponse = await dataService.GetAsync(geometries!).ConfigureAwait(false); - var gemeinde = dataServiceResponse.Gemeinde; - if (string.IsNullOrEmpty(gemeinde)) - { - notFound.Add(standortId, string.Join(", ", geometries.Select(x => x.AsText()))); - } - else - { - found++; - standort.Gemeinde = gemeinde; - } - } - catch (Exception ex) - { - errors.Add(standortId, ex.Message); - } - }).ConfigureAwait(false); - - if (!dryRun) - { - context.SaveChangesWithoutUpdatingChangeInformation(); - } - - return new JsonResult(new { Total = standorteToMigrate.Count, Success = found, NotFoundCount = notFound.Count, NotFound = notFound, ErrorCount = errors.Count, Errors = errors }); - } -}