diff options
author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-11-05 15:18:18 +0100 |
---|---|---|
committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-11-05 15:18:18 +0100 |
commit | f8b5a5eed843cdd0e94f96be072043f47c5db956 (patch) | |
tree | 67331bf00ff11196798eaaca7d7adbf3677fe190 /Backend | |
parent | 146a732982f096bfdb3e3ed56300233736f90c21 (diff) |
Kada se dodaje lokacija omoguceno da se koristi MapQuest geocoder da se nadju kordinate tog mesta i da se upisu u lokaciju.
Diffstat (limited to 'Backend')
-rw-r--r-- | Backend/Api/Api/Api.csproj | 3 | ||||
-rw-r--r-- | Backend/Api/Api/Services/LocationService.cs | 18 | ||||
-rw-r--r-- | Backend/Api/Api/appsettings.json | 19 |
3 files changed, 29 insertions, 11 deletions
diff --git a/Backend/Api/Api/Api.csproj b/Backend/Api/Api/Api.csproj index b09c2fd..80898fd 100644 --- a/Backend/Api/Api/Api.csproj +++ b/Backend/Api/Api/Api.csproj @@ -7,6 +7,9 @@ </PropertyGroup> <ItemGroup> + <PackageReference Include="Geocoding.Core" Version="4.0.1" /> + <PackageReference Include="Geocoding.Google" Version="4.0.1" /> + <PackageReference Include="Geocoding.MapQuest" Version="4.0.1" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.10" /> <PackageReference Include="MongoDB.Driver" Version="2.18.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> diff --git a/Backend/Api/Api/Services/LocationService.cs b/Backend/Api/Api/Services/LocationService.cs index 629c2a7..292fc0e 100644 --- a/Backend/Api/Api/Services/LocationService.cs +++ b/Backend/Api/Api/Services/LocationService.cs @@ -1,6 +1,11 @@ using Api.Interfaces; using Api.Models; +using Geocoding; +using Geocoding.Google; +using Geocoding.MapQuest; using MongoDB.Driver; +using ZstdSharp.Unsafe; +using Location = Api.Models.Location; namespace Api.Services { @@ -9,15 +14,24 @@ namespace Api.Services private readonly MongoClient _client; private readonly IMongoCollection<Location> _locations; private readonly IHttpContextAccessor _httpContext; - public LocationService(IDatabaseConnection settings, IMongoClient mongoClient) + private IConfiguration _configuration; + private MapQuestGeocoder _geocoder; + public LocationService(IDatabaseConnection settings, IMongoClient mongoClient, IConfiguration configuration) { var database = mongoClient.GetDatabase(settings.DatabaseName); _locations = database.GetCollection<Location>(settings.LocationCollectionName); + _configuration = configuration; + var _mapQuestApiKey = _configuration.GetSection("AppSettings:MapQuestApiKey").Value; + _geocoder = new MapQuestGeocoder(_mapQuestApiKey); + } public async Task<Location> add(Location loc) { - //TODO GOOGLE MAPS API CALL FOR info + IEnumerable<Address> adresses = await _geocoder.GeocodeAsync(loc.name+" "+loc.address+" "+loc.city+" "+loc.country); + loc.latitude = adresses.First().Coordinates.Latitude; + loc.longitude=adresses.First().Coordinates.Longitude; await _locations.InsertOneAsync(loc); + return loc; } public async Task<Location> getById(string id) diff --git a/Backend/Api/Api/appsettings.json b/Backend/Api/Api/appsettings.json index b7f25b2..22d91dc 100644 --- a/Backend/Api/Api/appsettings.json +++ b/Backend/Api/Api/appsettings.json @@ -1,8 +1,9 @@ { - "AppSettings": { - "JwtToken": "PjrVqQJ1P2VOkuWLw7NaZUluT4z7bkau", - "EmailToken": "e8X8c0lm9KS7itWi3wgE6BiPXR21WPvO" - }, + "AppSettings": { + "JwtToken": "PjrVqQJ1P2VOkuWLw7NaZUluT4z7bkau", + "EmailToken": "e8X8c0lm9KS7itWi3wgE6BiPXR21WPvO", + "MapQuestApiKey": "47oeviBUoCI2JxWzNARmCtrH9fDp5Mtk" //msbs#556ASDFGGSGSD + }, "Logging": { "LogLevel": { @@ -21,11 +22,11 @@ "LocationCollectionname": "locations" }, - "EmailCfg": { - "Email": "oddyssey.brzodolokacije@gmail.com", - "SmtpServer": "smtp.gmail.com", - "Password": "nrokhfcwahfbqnpp" //msbs#556 - }, + "EmailCfg": { + "Email": "oddyssey.brzodolokacije@gmail.com", + "SmtpServer": "smtp.gmail.com", + "Password": "nrokhfcwahfbqnpp" //msbs#556 + }, "URLs": { "localhost": "http://localhost:5279/", "actual":"add url when back put onto server" |