aboutsummaryrefslogtreecommitdiff
path: root/Backend
diff options
context:
space:
mode:
Diffstat (limited to 'Backend')
-rw-r--r--Backend/Api/Api/Controllers/LocationController.cs54
-rw-r--r--Backend/Api/Api/Database/DatabaseConnection.cs1
-rw-r--r--Backend/Api/Api/Interfaces/IDatabaseConnection.cs1
-rw-r--r--Backend/Api/Api/Interfaces/IFileService.cs (renamed from Backend/Api/Api/Services/IFileService.cs)2
-rw-r--r--Backend/Api/Api/Interfaces/ILocationService.cs11
-rw-r--r--Backend/Api/Api/Program.cs1
-rw-r--r--Backend/Api/Api/Services/LocationService.cs32
-rw-r--r--Backend/Api/Api/appsettings.json3
8 files changed, 103 insertions, 2 deletions
diff --git a/Backend/Api/Api/Controllers/LocationController.cs b/Backend/Api/Api/Controllers/LocationController.cs
new file mode 100644
index 0000000..bb0b0ab
--- /dev/null
+++ b/Backend/Api/Api/Controllers/LocationController.cs
@@ -0,0 +1,54 @@
+using Api.Interfaces;
+using Api.Models;
+using Microsoft.AspNetCore.Authorization;
+using System.Data;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Api.Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class LocationController : ControllerBase
+ {
+ private readonly ILocationService _locationService;
+ public LocationController(ILocationService locationService)
+ {
+ _locationService = locationService;
+ }
+
+ [HttpPost("add")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<Location>> addPost([FromBody] Location loc)
+ {
+ var res = await _locationService.add(loc);
+ if (res != null)
+ {
+ return Ok(res);
+ }
+ return BadRequest();
+ }
+ [HttpGet]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<List<Location>>> getAllPosts()
+ {
+ var res = await _locationService.getAllLocation();
+ if (res != null)
+ {
+ return Ok(res);
+ }
+ return BadRequest();
+ }
+ [HttpGet("loc /{id}")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<Location>> getLocationByid(string id)
+ {
+ var res = await _locationService.getById(id);
+ if (res != null)
+ {
+ return Ok(res);
+ }
+ return BadRequest();
+ }
+ }
+}
diff --git a/Backend/Api/Api/Database/DatabaseConnection.cs b/Backend/Api/Api/Database/DatabaseConnection.cs
index 24b2b08..f26b88e 100644
--- a/Backend/Api/Api/Database/DatabaseConnection.cs
+++ b/Backend/Api/Api/Database/DatabaseConnection.cs
@@ -9,5 +9,6 @@ namespace Api.Database
public string UserCollectionName { get; set; } = String.Empty;
public string PostCollectionName { get; set; } = String.Empty;
public string FileCollectionName { get; set; } = String.Empty;
+ public string LocationCollectionName { get; set; } = String.Empty;
}
}
diff --git a/Backend/Api/Api/Interfaces/IDatabaseConnection.cs b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs
index 744461b..17b5262 100644
--- a/Backend/Api/Api/Interfaces/IDatabaseConnection.cs
+++ b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs
@@ -7,5 +7,6 @@
string UserCollectionName { get; set; }
string PostCollectionName { get; set; }
string FileCollectionName { get; set; }
+ string LocationCollectionName { get; set; }
}
}
diff --git a/Backend/Api/Api/Services/IFileService.cs b/Backend/Api/Api/Interfaces/IFileService.cs
index 269e202..e736305 100644
--- a/Backend/Api/Api/Services/IFileService.cs
+++ b/Backend/Api/Api/Interfaces/IFileService.cs
@@ -1,4 +1,4 @@
-namespace Api.Services
+namespace Api.Interfaces
{
public interface IFileService
{
diff --git a/Backend/Api/Api/Interfaces/ILocationService.cs b/Backend/Api/Api/Interfaces/ILocationService.cs
new file mode 100644
index 0000000..16e00a0
--- /dev/null
+++ b/Backend/Api/Api/Interfaces/ILocationService.cs
@@ -0,0 +1,11 @@
+using Api.Models;
+
+namespace Api.Interfaces
+{
+ public interface ILocationService
+ {
+ Task<Location> add(Location loc);
+ Task<Location> getById(string id);
+ Task<List<Location>> getAllLocation();
+ }
+} \ No newline at end of file
diff --git a/Backend/Api/Api/Program.cs b/Backend/Api/Api/Program.cs
index 8dee088..16b0241 100644
--- a/Backend/Api/Api/Program.cs
+++ b/Backend/Api/Api/Program.cs
@@ -24,6 +24,7 @@ builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IJwtService, JwtService>();
builder.Services.AddScoped<IPostService,PostService>();
builder.Services.AddScoped<IFileService,FileService>();
+builder.Services.AddScoped<ILocationService,LocationService>();
builder.Services.AddHttpContextAccessor();
diff --git a/Backend/Api/Api/Services/LocationService.cs b/Backend/Api/Api/Services/LocationService.cs
new file mode 100644
index 0000000..b44f983
--- /dev/null
+++ b/Backend/Api/Api/Services/LocationService.cs
@@ -0,0 +1,32 @@
+using Api.Interfaces;
+using Api.Models;
+using MongoDB.Driver;
+
+namespace Api.Services
+{
+ public class LocationService : ILocationService
+ {
+ private readonly MongoClient _client;
+ private readonly IMongoCollection<Location> _locations;
+ private readonly IHttpContextAccessor _httpContext;
+ public LocationService(IDatabaseConnection settings, IMongoClient mongoClient)
+ {
+ var database = mongoClient.GetDatabase(settings.DatabaseName);
+ _locations = database.GetCollection<Location>(settings.FileCollectionName);
+ }
+ public async Task<Location> add(Location loc)
+ {
+ //TODO GOOGLE MAPS API CALL FOR info
+ await _locations.InsertOneAsync(loc);
+ return loc;
+ }
+ public async Task<Location> getById(string id)
+ {
+ return await _locations.Find(loc => loc._id == id).FirstOrDefaultAsync();
+ }
+ public async Task<List<Location>> getAllLocation()
+ {
+ return await _locations.Find(_=>true).ToListAsync();
+ }
+ }
+}
diff --git a/Backend/Api/Api/appsettings.json b/Backend/Api/Api/appsettings.json
index d506b33..b7f25b2 100644
--- a/Backend/Api/Api/appsettings.json
+++ b/Backend/Api/Api/appsettings.json
@@ -17,7 +17,8 @@
"DatabaseName": "Odyssey",
"UserCollectionName": "users",
"PostCollectionName": "posts",
- "FileCollectionName": "files"
+ "FileCollectionName": "files",
+ "LocationCollectionname": "locations"
},
"EmailCfg": {