Skip to content

Commit

Permalink
Add ListAllAsync method to IAnalysisRepository and
Browse files Browse the repository at this point in the history
AnalysisRepository
  • Loading branch information
yorickdewid committed Jan 3, 2024
1 parent 2d815d2 commit cb84167
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ public interface IAnalysisRepository
/// <param name="id">External identifier.</param>
/// <param name="tenantId">Tenant identifier.</param>
Task RegisterProductMismatch(string id, Guid tenantId);

/// <summary>
/// Retrieve all <typeparamref name="AnalysisProduct"/>.
/// </summary>
/// <returns>List of <typeparamref name="AnalysisProduct"/>.</returns>
IAsyncEnumerable<AnalysisProduct> ListAllAsync(Navigation navigation);
}
49 changes: 48 additions & 1 deletion src/FunderMaps.Data/Repositories/AnalysisRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dapper;
using FunderMaps.Core;
using FunderMaps.Core.Interfaces.Repositories;
using FunderMaps.Core.Types;
using FunderMaps.Core.Types.Products;
Expand Down Expand Up @@ -26,7 +27,7 @@ public async Task<AnalysisProduct> GetAsync(string id)
mrs.building_id,
mrs.external_building_id,
a.id as address_id,
a.external_id as address_external_id,
a.external_id as address_external_id,
mrs.neighborhood_id,
mrs.construction_year,
mrs.construction_year_reliability,
Expand Down Expand Up @@ -180,4 +181,50 @@ private static AnalysisProduct MapFromReader(DbDataReader reader, int offset = 0
UnclassifiedRisk = reader.GetFieldValue<FoundationRisk?>(offset++),
RecoveryType = reader.GetFieldValue<RecoveryType?>(offset++),
};

/// <summary>
/// Retrieve all <see cref="AnalysisProduct"/>.
/// </summary>
/// <returns>List of <see cref="AnalysisProduct"/>.</returns>
public async IAsyncEnumerable<AnalysisProduct> ListAllAsync(Navigation navigation)
{
var sql = @"
SELECT
mrs.building_id,
mrs.external_building_id,
mrs.neighborhood_id,
mrs.construction_year,
mrs.construction_year_reliability,
mrs.foundation_type,
mrs.foundation_type_reliability,
mrs.restoration_costs,
mrs.height,
mrs.velocity,
mrs.ground_water_level,
mrs.ground_level,
mrs.soil,
mrs.surface_area,
mrs.damage_cause,
mrs.enforcement_term,
mrs.overall_quality,
mrs.inquiry_type,
mrs.drystand,
mrs.drystand_risk,
mrs.drystand_risk_reliability,
mrs.bio_infection_risk,
mrs.bio_infection_risk_reliability,
mrs.dewatering_depth,
mrs.dewatering_depth_risk,
mrs.dewatering_depth_risk_reliability,
mrs.unclassified_risk,
mrs.recovery_type
FROM data.model_risk_static mrs";

await using var connection = DbContextFactory.DbProvider.ConnectionScope();

foreach (var item in await connection.QueryAsync<AnalysisProduct>(sql, navigation))
{
yield return item;
}
}
}

0 comments on commit cb84167

Please sign in to comment.