🐛 Refactor to fix GeoIP
This commit is contained in:
		| @@ -1,7 +1,6 @@ | ||||
| using MaxMind.GeoIP2; | ||||
| using Microsoft.Extensions.Options; | ||||
| using NetTopologySuite.Geometries; | ||||
| using Point = NetTopologySuite.Geometries.Point; | ||||
|  | ||||
| namespace DysonNetwork.Shared.GeoIp; | ||||
|  | ||||
| @@ -15,7 +14,7 @@ public class GeoIpService(IOptions<GeoIpOptions> options) | ||||
|     private readonly string _databasePath = options.Value.DatabasePath; | ||||
|     private readonly GeometryFactory _geometryFactory = new(new PrecisionModel(), 4326); // 4326 is the SRID for WGS84 | ||||
|      | ||||
|     public Point? GetPointFromIp(string? ipAddress) | ||||
|     public GeoPoint? GetPointFromIp(string? ipAddress) | ||||
|     { | ||||
|         if (string.IsNullOrEmpty(ipAddress)) | ||||
|             return null; | ||||
| @@ -28,9 +27,14 @@ public class GeoIpService(IOptions<GeoIpOptions> options) | ||||
|             if (city?.Location is not { HasCoordinates: true }) | ||||
|                 return null; | ||||
|  | ||||
|             return _geometryFactory.CreatePoint(new Coordinate( | ||||
|                 city.Location.Longitude ?? 0, | ||||
|                 city.Location.Latitude ?? 0)); | ||||
|             return new GeoPoint() | ||||
|             { | ||||
|                 City = city.City.Name, | ||||
|                 Country = city.Country.Name, | ||||
|                 CountryCode = city.Country.IsoCode, | ||||
|                 Longitude = city.Location.Longitude, | ||||
|                 Latitude = city.Location.Latitude, | ||||
|             }; | ||||
|         } | ||||
|         catch (Exception) | ||||
|         { | ||||
|   | ||||
							
								
								
									
										10
									
								
								DysonNetwork.Shared/GeoIp/GeoPoint.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								DysonNetwork.Shared/GeoIp/GeoPoint.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| namespace DysonNetwork.Shared.GeoIp; | ||||
|  | ||||
| public class GeoPoint | ||||
| { | ||||
|     public double? Latitude { get; set; } | ||||
|     public double? Longitude { get; set; } | ||||
|     public string? CountryCode { get; set; } | ||||
|     public string? Country { get; set; } | ||||
|     public string? City { get; set; } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user