mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 13:51:14 +00:00
6099d1c86b
Batch 23 of refactor 03-code-quality-refactoring (4 tasks, 5 SP):
- AZ-376 (C23): Delete unused FindExistingTileAsync from
ITileRepository / TileRepository. No callers; method also took the
obsolete `version` arg removed by C06/AZ-357.
- AZ-378 (C25): Repository _logger discipline.
TileRepository.GetTilesByRegionAsync now emits LogWarning when the
query exceeds SlowQueryThresholdMs (500 ms). RegionRepository and
RouteRepository drop the unused ILogger<TRepo> field, parameter, and
using; Program.cs DI registrations updated.
- AZ-379 (C26): Extract `private const string ColumnList` per repo
(TileRepository, RegionRepository, RouteRepository); SELECTs use
$@"SELECT {ColumnList} FROM ..." (C# 10+ const interpolation).
INSERT/UPDATE/DELETE unchanged; route_points single-site SELECT left
inline.
- AZ-380 (C27): Delete dead alias GeoUtils.CalculatePolygonDiagonalDistance.
Tests: +9 new (RepositoryRefactorTests x8, GeoUtilsRefactorTests x1)
covering each AC via reflection / file-content assertions; pattern
mirrors ToolingConfigurationTests (b22) and AcceptanceCriteriaRT2Tests
(b19). Unit suite 181 -> 190, all green. dotnet format clean.
Code review: PASS_WITH_WARNINGS (3 Low findings, all informational or
out-of-scope for this batch). See
_docs/03_implementation/reviews/batch_23_review.md.
Cumulative review counter 2/3; next K=3 review fires after batch 24.
Co-authored-by: Cursor <cursoragent@cursor.com>
93 lines
3.4 KiB
C#
93 lines
3.4 KiB
C#
using Dapper;
|
|
using Npgsql;
|
|
using SatelliteProvider.Common.Enums;
|
|
using SatelliteProvider.DataAccess.Models;
|
|
|
|
namespace SatelliteProvider.DataAccess.Repositories;
|
|
|
|
public class RegionRepository : IRegionRepository
|
|
{
|
|
private const string ColumnList = @"id, latitude, longitude, size_meters as SizeMeters,
|
|
zoom_level as ZoomLevel, status,
|
|
csv_file_path as CsvFilePath, summary_file_path as SummaryFilePath,
|
|
tiles_downloaded as TilesDownloaded, tiles_reused as TilesReused,
|
|
stitch_tiles as StitchTiles,
|
|
created_at as CreatedAt, updated_at as UpdatedAt";
|
|
|
|
private readonly string _connectionString;
|
|
|
|
public RegionRepository(string connectionString)
|
|
{
|
|
_connectionString = connectionString;
|
|
}
|
|
|
|
public async Task<RegionEntity?> GetByIdAsync(Guid id)
|
|
{
|
|
using var connection = new NpgsqlConnection(_connectionString);
|
|
const string sql = $@"
|
|
SELECT {ColumnList}
|
|
FROM regions
|
|
WHERE id = @Id";
|
|
|
|
var region = await connection.QuerySingleOrDefaultAsync<RegionEntity>(sql, new { Id = id });
|
|
return region;
|
|
}
|
|
|
|
public async Task<IEnumerable<RegionEntity>> GetByStatusAsync(RegionStatus status)
|
|
{
|
|
using var connection = new NpgsqlConnection(_connectionString);
|
|
const string sql = $@"
|
|
SELECT {ColumnList}
|
|
FROM regions
|
|
WHERE status = @Status
|
|
ORDER BY created_at ASC";
|
|
|
|
return await connection.QueryAsync<RegionEntity>(sql, new { Status = status });
|
|
}
|
|
|
|
public async Task<Guid> InsertAsync(RegionEntity region)
|
|
{
|
|
using var connection = new NpgsqlConnection(_connectionString);
|
|
const string sql = @"
|
|
INSERT INTO regions (id, latitude, longitude, size_meters, zoom_level,
|
|
status, csv_file_path, summary_file_path,
|
|
tiles_downloaded, tiles_reused, stitch_tiles,
|
|
created_at, updated_at)
|
|
VALUES (@Id, @Latitude, @Longitude, @SizeMeters, @ZoomLevel,
|
|
@Status, @CsvFilePath, @SummaryFilePath,
|
|
@TilesDownloaded, @TilesReused, @StitchTiles,
|
|
@CreatedAt, @UpdatedAt)
|
|
RETURNING id";
|
|
|
|
return await connection.ExecuteScalarAsync<Guid>(sql, region);
|
|
}
|
|
|
|
public async Task<int> UpdateAsync(RegionEntity region)
|
|
{
|
|
using var connection = new NpgsqlConnection(_connectionString);
|
|
const string sql = @"
|
|
UPDATE regions
|
|
SET latitude = @Latitude,
|
|
longitude = @Longitude,
|
|
size_meters = @SizeMeters,
|
|
zoom_level = @ZoomLevel,
|
|
status = @Status,
|
|
csv_file_path = @CsvFilePath,
|
|
summary_file_path = @SummaryFilePath,
|
|
tiles_downloaded = @TilesDownloaded,
|
|
tiles_reused = @TilesReused,
|
|
stitch_tiles = @StitchTiles,
|
|
updated_at = @UpdatedAt
|
|
WHERE id = @Id";
|
|
|
|
return await connection.ExecuteAsync(sql, region);
|
|
}
|
|
|
|
public async Task<int> DeleteAsync(Guid id)
|
|
{
|
|
using var connection = new NpgsqlConnection(_connectionString);
|
|
const string sql = "DELETE FROM regions WHERE id = @Id";
|
|
return await connection.ExecuteAsync(sql, new { Id = id });
|
|
}
|
|
}
|