mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-15 01:54:43 +00:00
Integrate NetTopologySuite and create CoordinateData mapping (#250)
This commit is contained in:
@@ -17,9 +17,16 @@ namespace Features.Breweries.Repository;
|
||||
/// yields the UDT's serialized bytes as a plain <c>varbinary</c> value that Dapper can bind directly.
|
||||
/// </remarks>
|
||||
public class BreweryRepository(ISqlConnectionFactory connectionFactory)
|
||||
: Database.Connection.DapperRepository(connectionFactory),
|
||||
: DapperRepository(connectionFactory),
|
||||
IBreweryRepository
|
||||
{
|
||||
private const int GeographySrid = 4326;
|
||||
|
||||
static BreweryRepository()
|
||||
{
|
||||
SqlMapper.AddTypeHandler(new CoordinateDataTypeHandler());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<BreweryPost?> GetByIdAsync(Guid id)
|
||||
{
|
||||
@@ -226,7 +233,10 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory)
|
||||
AddressLine1 = @AddressLine1,
|
||||
AddressLine2 = @AddressLine2,
|
||||
PostalCode = @PostalCode,
|
||||
Coordinates = @Coordinates
|
||||
Coordinates = CASE
|
||||
WHEN @Latitude IS NULL THEN NULL
|
||||
ELSE geography::Point(@Latitude, @Longitude, @Srid)
|
||||
END
|
||||
WHERE BreweryPostID = @BreweryPostId
|
||||
""",
|
||||
new
|
||||
@@ -236,7 +246,9 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory)
|
||||
brewery.Location.AddressLine1,
|
||||
brewery.Location.AddressLine2,
|
||||
brewery.Location.PostalCode,
|
||||
brewery.Location.Coordinates,
|
||||
Latitude = brewery.Location.Coordinates?.Latitude,
|
||||
Longitude = brewery.Location.Coordinates?.Longitude,
|
||||
Srid = GeographySrid,
|
||||
},
|
||||
transaction
|
||||
)
|
||||
@@ -260,7 +272,10 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory)
|
||||
@AddressLine1,
|
||||
@AddressLine2,
|
||||
@PostalCode,
|
||||
@Coordinates)
|
||||
CASE
|
||||
WHEN @Latitude IS NULL THEN NULL
|
||||
ELSE geography::Point(@Latitude, @Longitude, @Srid)
|
||||
END)
|
||||
""",
|
||||
new
|
||||
{
|
||||
@@ -270,7 +285,9 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory)
|
||||
brewery.Location.AddressLine1,
|
||||
brewery.Location.AddressLine2,
|
||||
brewery.Location.PostalCode,
|
||||
brewery.Location.Coordinates,
|
||||
Latitude = brewery.Location.Coordinates?.Latitude,
|
||||
Longitude = brewery.Location.Coordinates?.Longitude,
|
||||
Srid = GeographySrid,
|
||||
},
|
||||
transaction
|
||||
)
|
||||
@@ -394,7 +411,10 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory)
|
||||
@AddressLine1,
|
||||
@AddressLine2,
|
||||
@PostalCode,
|
||||
@Coordinates)
|
||||
CASE
|
||||
WHEN @Latitude IS NULL THEN NULL
|
||||
ELSE geography::Point(@Latitude, @Longitude, @Srid)
|
||||
END)
|
||||
""",
|
||||
new
|
||||
{
|
||||
@@ -404,7 +424,9 @@ public class BreweryRepository(ISqlConnectionFactory connectionFactory)
|
||||
brewery.Location.AddressLine1,
|
||||
brewery.Location.AddressLine2,
|
||||
brewery.Location.PostalCode,
|
||||
brewery.Location.Coordinates,
|
||||
Latitude = brewery.Location.Coordinates?.Latitude,
|
||||
Longitude = brewery.Location.Coordinates?.Longitude,
|
||||
Srid = GeographySrid,
|
||||
},
|
||||
transaction
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user