aboutsummaryrefslogtreecommitdiff
path: root/Backend
diff options
context:
space:
mode:
Diffstat (limited to 'Backend')
-rw-r--r--Backend/Api/Api/Api.csproj3
-rw-r--r--Backend/Api/Api/Controllers/AuthController.cs11
-rw-r--r--Backend/Api/Api/Interfaces/IUserService.cs2
-rw-r--r--Backend/Api/Api/Services/LocationService.cs18
-rw-r--r--Backend/Api/Api/Services/PostService.cs10
-rw-r--r--Backend/Api/Api/Services/UserService.cs4
-rw-r--r--Backend/Api/Api/appsettings.json19
7 files changed, 44 insertions, 23 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/Controllers/AuthController.cs b/Backend/Api/Api/Controllers/AuthController.cs
index cbd5eb8..abb7adc 100644
--- a/Backend/Api/Api/Controllers/AuthController.cs
+++ b/Backend/Api/Api/Controllers/AuthController.cs
@@ -37,6 +37,17 @@ namespace Api.Controllers
return Ok();
}
+ [HttpPost("refreshJwt")]
+ [Authorize(Roles ="User")]
+ public async Task<ActionResult<string>> refreshJwt()
+ {
+ var jwt = await _userService.RenewToken();
+ if (jwt != null)
+ {
+ return Ok(jwt);
+ }
+ return BadRequest("Pogresno uneti podaci");
+ }
[HttpPost("login")]
public async Task<ActionResult<string>> Login([FromBody] Login creds)
{
diff --git a/Backend/Api/Api/Interfaces/IUserService.cs b/Backend/Api/Api/Interfaces/IUserService.cs
index 218c67a..db2eac1 100644
--- a/Backend/Api/Api/Interfaces/IUserService.cs
+++ b/Backend/Api/Api/Interfaces/IUserService.cs
@@ -12,7 +12,7 @@ namespace Api.Interfaces
Task<User> deleteUser(String email);
Task<User> getUserById(string id);
- Task<string> RenewToken(string existingToken);
+ Task<string> RenewToken();
Task<string> Login(Login login);
Task<string> Register(Register register);
Task<Boolean> VerifyUser(VerifyUser login);
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/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs
index 2f29366..0a12f39 100644
--- a/Backend/Api/Api/Services/PostService.cs
+++ b/Backend/Api/Api/Services/PostService.cs
@@ -23,7 +23,7 @@ namespace Api.Services
{
Post p = new Post();
p._id = "";
- p.ownerId = _httpContext.HttpContext.User.FindFirstValue("id");
+ p.ownerId = _httpContext.HttpContext.User.FindFirstValue("id").ToString();
p.locationId = post.locationId;
p.description = post.description;
@@ -63,14 +63,6 @@ namespace Api.Services
}
await _posts.InsertOneAsync(p);
-
-
-
-
-
-
-
-
return postToPostSend(p);
}
diff --git a/Backend/Api/Api/Services/UserService.cs b/Backend/Api/Api/Services/UserService.cs
index 034c494..5fd61f6 100644
--- a/Backend/Api/Api/Services/UserService.cs
+++ b/Backend/Api/Api/Services/UserService.cs
@@ -163,9 +163,9 @@ namespace Api.Services
return false;
}
- public async Task<string> RenewToken(string existingToken)
+ public async Task<string> RenewToken()
{
- var id = _jwtService.TokenToId(existingToken);
+ var id = await UserIdFromJwt();
if (id == null)
return null;
var user = await getUserById(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"