Skip to content

Commit

Permalink
Fix a couple of endpoints with lazy loading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kvam committed Jan 17, 2025
1 parent 74b6624 commit 4a0286e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
using api.Context;
using api.Context.Extensions;
using api.Features.Cases.Recalculation;
using api.Features.ProjectIntegrity;
using api.ModelMapping;
using api.Models;

using Microsoft.EntityFrameworkCore;

namespace api.Features.Assets.CaseAssets.DrainageStrategies;

public class UpdateDrainageStrategyService(
DcdDbContext context,
IConversionMapperService conversionMapperService,
IProjectIntegrityService projectIntegrityService,
IRecalculationService recalculationService)
public class UpdateDrainageStrategyService(DcdDbContext context, IRecalculationService recalculationService)
{
public async Task UpdateDrainageStrategy(
Guid projectId,
Guid caseId,
Guid drainageStrategyId,
UpdateDrainageStrategyDto updatedDrainageStrategyDto)
{
await projectIntegrityService.EntityIsConnectedToProject<DrainageStrategy>(projectId, drainageStrategyId);

var existingDrainageStrategy = await context.DrainageStrategies.SingleAsync(x => x.Id == drainageStrategyId);

var projectPk = await context.GetPrimaryKeyForProjectId(projectId);

var project = await context.Projects.SingleAsync(p => p.Id == projectPk);

conversionMapperService.MapToEntity(updatedDrainageStrategyDto, existingDrainageStrategy, drainageStrategyId, project.PhysicalUnit);
var existingDrainageStrategy = await context.DrainageStrategies.SingleAsync(x => x.ProjectId == projectId && x.Id == drainageStrategyId);

existingDrainageStrategy.NGLYield = updatedDrainageStrategyDto.NGLYield;
existingDrainageStrategy.ProducerCount = updatedDrainageStrategyDto.ProducerCount;
existingDrainageStrategy.GasInjectorCount = updatedDrainageStrategyDto.GasInjectorCount;
existingDrainageStrategy.WaterInjectorCount = updatedDrainageStrategyDto.WaterInjectorCount;
existingDrainageStrategy.ArtificialLift = updatedDrainageStrategyDto.ArtificialLift;
existingDrainageStrategy.GasSolution = updatedDrainageStrategyDto.GasSolution;

await context.UpdateCaseModifyTime(caseId);
await recalculationService.SaveChangesAndRecalculateAsync(caseId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public async Task AddOrUpdateSurfCostProfile(

var surf = await context.Surfs
.Include(t => t.CostProfile)
.Include(x => x.CostProfileOverride)
.SingleAsync(t => t.Id == surfId);

if (surf.CostProfile != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ public DrainageStrategyProfile()
CreateMap<ImportedElectricityOverride, ImportedElectricityOverrideDto>();
CreateMap<Co2Intensity, Co2IntensityDto>();

CreateMap<UpdateDrainageStrategyDto, DrainageStrategy>();

CreateMap<CreateImportedElectricityOverrideDto, ImportedElectricityOverride>()
.ForMember(
dest => dest.Values,
Expand Down

0 comments on commit 4a0286e

Please sign in to comment.