aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbranislav.radivojevic <wafflemynxyt@gmail.com>2022-12-05 17:10:49 +0100
committerbranislav.radivojevic <wafflemynxyt@gmail.com>2022-12-05 17:10:49 +0100
commitaae690368dc3f60d18c3564cd4c1603820defec1 (patch)
treed614c7e73cebb49bc139467d3b387431b42b2de8
parentebd729276cdbe9212230e04c5716ba8cc54cb443 (diff)
Najpopularniji post za svaku lokaciju u radiusu
-rw-r--r--Backend/Api/Api/Controllers/LocationController.cs22
-rw-r--r--Backend/Api/Api/Interfaces/IPostService.cs1
-rw-r--r--Backend/Api/Api/Services/LocationService.cs2
-rw-r--r--Backend/Api/Api/Services/PostService.cs25
4 files changed, 49 insertions, 1 deletions
diff --git a/Backend/Api/Api/Controllers/LocationController.cs b/Backend/Api/Api/Controllers/LocationController.cs
index ba9c9a8..ac093bb 100644
--- a/Backend/Api/Api/Controllers/LocationController.cs
+++ b/Backend/Api/Api/Controllers/LocationController.cs
@@ -12,9 +12,11 @@ namespace Api.Controllers
public class LocationController : ControllerBase
{
private readonly ILocationService _locationService;
- public LocationController(ILocationService locationService)
+ private readonly IPostService _postService;
+ public LocationController(ILocationService locationService, IPostService postService)
{
_locationService = locationService;
+ _postService = postService;
}
[HttpPost("add")]
@@ -74,5 +76,23 @@ namespace Api.Controllers
return Ok(ret);
}
}
+
+ [HttpGet("searchradius")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<List<Location>>> bestPostsForLocationInRadius(double latitude, double longitude, double radius)
+ {
+ Coords coords = new Coords();
+ if (latitude != null && longitude != null)
+ {
+ coords.latitude = (double)latitude;
+ coords.longitude = (double)longitude;
+ }
+ List<PostSend> ret = new List<PostSend>();
+ ret = await _postService.BestPostForAllLocationsInRadius(coords, radius);
+ if (ret != null && ret.Count > 0)
+ return Ok(ret);
+ return BadRequest();
+
+ }
}
}
diff --git a/Backend/Api/Api/Interfaces/IPostService.cs b/Backend/Api/Api/Interfaces/IPostService.cs
index 69846b0..84d32ef 100644
--- a/Backend/Api/Api/Interfaces/IPostService.cs
+++ b/Backend/Api/Api/Interfaces/IPostService.cs
@@ -29,5 +29,6 @@ namespace Api.Interfaces
Task<List<PostSend>> Recommended(string userid);
Task<Boolean> addRemoveFavourite(string postId);
Task<List<Trending>> TrendingTags();
+ Task<List<PostSend>> BestPostForAllLocationsInRadius(Coords coords, double radius);
}
} \ No newline at end of file
diff --git a/Backend/Api/Api/Services/LocationService.cs b/Backend/Api/Api/Services/LocationService.cs
index afb3b5b..55a52e7 100644
--- a/Backend/Api/Api/Services/LocationService.cs
+++ b/Backend/Api/Api/Services/LocationService.cs
@@ -99,5 +99,7 @@ namespace Api.Services
}
return tosend;
}
+
+
}
}
diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs
index 777389b..6f7c455 100644
--- a/Backend/Api/Api/Services/PostService.cs
+++ b/Backend/Api/Api/Services/PostService.cs
@@ -626,6 +626,31 @@ namespace Api.Services
return tosend;
}
+
+ public async Task<List<PostSend>> BestPostForAllLocationsInRadius(Coords coords, double radius)
+ {
+ if (coords == null)
+ return null;
+ var lista = await _locations.Find(_ => true).ToListAsync();
+ var inradius = new List<Location>();
+ var tosend = new List<PostSend>();
+ if (lista != null)
+ {
+ foreach (var elem in lista)
+ {
+ if (Math.Abs(elem.latitude - coords.latitude) < radius && Math.Abs(elem.longitude - coords.longitude) < radius)
+ inradius.Add(elem);
+ }
+ foreach (var elem in inradius)
+ {
+ var locposts = await SearchPosts(elem._id, 0, 1, 1);
+ var best = locposts.posts.Take(1).FirstOrDefault();
+ if(best != null)
+ tosend.Add(best);
+ }
+ }
+ return tosend;
+ }
}
}