From f8b5a5eed843cdd0e94f96be072043f47c5db956 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Sat, 5 Nov 2022 15:18:18 +0100 Subject: Kada se dodaje lokacija omoguceno da se koristi MapQuest geocoder da se nadju kordinate tog mesta i da se upisu u lokaciju. --- Backend/Api/Api/Api.csproj | 3 +++ Backend/Api/Api/Services/LocationService.cs | 18 ++++++++++++++++-- Backend/Api/Api/appsettings.json | 19 ++++++++++--------- 3 files changed, 29 insertions(+), 11 deletions(-) (limited to 'Backend') 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 @@ + + + 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 _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(settings.LocationCollectionName); + _configuration = configuration; + var _mapQuestApiKey = _configuration.GetSection("AppSettings:MapQuestApiKey").Value; + _geocoder = new MapQuestGeocoder(_mapQuestApiKey); + } public async Task add(Location loc) { - //TODO GOOGLE MAPS API CALL FOR info + IEnumerable
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 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" -- cgit v1.2.3