From 1513d1b5eba692d50c733e7c682c1e31d515158a Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Thu, 3 Nov 2022 20:06:46 +0100 Subject: Napravljeni kosturi za PostController i PostServices. Dodata nova kolekcija u bazi. --- Backend/Api/Api/Controllers/PostController.cs | 18 ++++++++++++++++++ Backend/Api/Api/Database/DatabaseConnection.cs | 1 + Backend/Api/Api/Interfaces/IDatabaseConnection.cs | 1 + Backend/Api/Api/Interfaces/IPostService.cs | 9 +++++++++ Backend/Api/Api/Program.cs | 1 + Backend/Api/Api/Services/PostService.cs | 22 ++++++++++++++++++++++ Backend/Api/Api/appsettings.json | 3 ++- 7 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Backend/Api/Api/Controllers/PostController.cs create mode 100644 Backend/Api/Api/Interfaces/IPostService.cs create mode 100644 Backend/Api/Api/Services/PostService.cs (limited to 'Backend/Api') diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs new file mode 100644 index 0000000..4bac0e5 --- /dev/null +++ b/Backend/Api/Api/Controllers/PostController.cs @@ -0,0 +1,18 @@ +using Api.Interfaces; +using Microsoft.AspNetCore.Mvc; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace Api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class PostController : ControllerBase + { + private readonly IPostService _postService; + public PostController(IPostService postService) + { + _postService = postService; + } + } +} diff --git a/Backend/Api/Api/Database/DatabaseConnection.cs b/Backend/Api/Api/Database/DatabaseConnection.cs index 65f4f52..c2fea05 100644 --- a/Backend/Api/Api/Database/DatabaseConnection.cs +++ b/Backend/Api/Api/Database/DatabaseConnection.cs @@ -7,5 +7,6 @@ namespace Api.Database public string ConnectionString { get; set; } = String.Empty; public string DatabaseName { get; set; } = String.Empty; public string UserCollectionName { get; set; } = String.Empty; + public string PostCollectionName { get; set; } = String.Empty; } } diff --git a/Backend/Api/Api/Interfaces/IDatabaseConnection.cs b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs index 8938127..e3fc60c 100644 --- a/Backend/Api/Api/Interfaces/IDatabaseConnection.cs +++ b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs @@ -5,5 +5,6 @@ string ConnectionString { get; set; } string DatabaseName { get; set; } string UserCollectionName { get; set; } + string PostCollectionName { get; set; } } } diff --git a/Backend/Api/Api/Interfaces/IPostService.cs b/Backend/Api/Api/Interfaces/IPostService.cs new file mode 100644 index 0000000..6c34e69 --- /dev/null +++ b/Backend/Api/Api/Interfaces/IPostService.cs @@ -0,0 +1,9 @@ +using Api.Models; + +namespace Api.Interfaces +{ + public interface IPostService + { + PostSend addPost(PostReceive post); + } +} \ No newline at end of file diff --git a/Backend/Api/Api/Program.cs b/Backend/Api/Api/Program.cs index 6c96331..9b80f3c 100644 --- a/Backend/Api/Api/Program.cs +++ b/Backend/Api/Api/Program.cs @@ -22,6 +22,7 @@ builder.Services.AddSingleton(s => builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHttpContextAccessor(); diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs new file mode 100644 index 0000000..2a5e789 --- /dev/null +++ b/Backend/Api/Api/Services/PostService.cs @@ -0,0 +1,22 @@ +using Api.Interfaces; +using Api.Models; +using MongoDB.Driver; + +namespace Api.Services +{ + public class PostService : IPostService + { + private readonly MongoClient _client; + private readonly IMongoCollection _posts; + public PostService(IDatabaseConnection settings, IMongoClient mongoClient) + { + var database = mongoClient.GetDatabase(settings.DatabaseName); + _posts = database.GetCollection(settings.PostCollectionName); + } + + public PostSend addPost(PostReceive post) + { + return null; + } + } +} diff --git a/Backend/Api/Api/appsettings.json b/Backend/Api/Api/appsettings.json index 74cfa27..2be2426 100644 --- a/Backend/Api/Api/appsettings.json +++ b/Backend/Api/Api/appsettings.json @@ -15,7 +15,8 @@ "ConnectionString": "mongodb://127.0.0.1:27017/", "DatabaseName": "Odyssey", - "UserCollectionName": "users" + "UserCollectionName": "users", + "PostCollectionName": "posts" }, "EmailCfg": { -- cgit v1.2.3 From 718a4a30cad0205e00b7d4acdee58c1b7f8cdb08 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Thu, 3 Nov 2022 20:32:42 +0100 Subject: Napravljene metode za dodavanje i vracanje objava u servisu i kontroleru. --- Backend/Api/Api/Controllers/PostController.cs | 38 +++++++++++++++++++++ Backend/Api/Api/Interfaces/IPostService.cs | 5 ++- Backend/Api/Api/Services/PostService.cs | 49 ++++++++++++++++++++++++--- 3 files changed, 87 insertions(+), 5 deletions(-) (limited to 'Backend/Api') diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs index 4bac0e5..8db68a8 100644 --- a/Backend/Api/Api/Controllers/PostController.cs +++ b/Backend/Api/Api/Controllers/PostController.cs @@ -1,4 +1,7 @@ using Api.Interfaces; +using Api.Models; +using Api.Services; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -14,5 +17,40 @@ namespace Api.Controllers { _postService = postService; } + + [HttpPost("add")] + [Authorize(Roles ="User")] + public async Task> addPost([FromBody] PostReceive post) + { + var res = await _postService.addPost(post); + if (res != null) + { + return Ok(res); + } + return BadRequest(); + } + [HttpGet] + [Authorize(Roles = "User")] + public async Task>> getAllPosts() + { + var res = await _postService.getAllPosts(); + if (res != null) + { + return Ok(res); + } + return BadRequest(); + } + [HttpGet("posts /{id}")] + [Authorize(Roles = "User")] + public async Task> getPostByid(string id) + { + var res = await _postService.getPostById(id); + if (res != null) + { + return Ok(res); + } + return BadRequest(); + } + } } diff --git a/Backend/Api/Api/Interfaces/IPostService.cs b/Backend/Api/Api/Interfaces/IPostService.cs index 6c34e69..31e80cd 100644 --- a/Backend/Api/Api/Interfaces/IPostService.cs +++ b/Backend/Api/Api/Interfaces/IPostService.cs @@ -4,6 +4,9 @@ namespace Api.Interfaces { public interface IPostService { - PostSend addPost(PostReceive post); + Task addPost(PostReceive post); + Task> getAllPosts(); + Task getPostById(string id); + PostSend postToPostSend(Post post); } } \ No newline at end of file diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs index 2a5e789..49c92cb 100644 --- a/Backend/Api/Api/Services/PostService.cs +++ b/Backend/Api/Api/Services/PostService.cs @@ -1,4 +1,5 @@ -using Api.Interfaces; +using System.Security.Claims; +using Api.Interfaces; using Api.Models; using MongoDB.Driver; @@ -8,15 +9,55 @@ namespace Api.Services { private readonly MongoClient _client; private readonly IMongoCollection _posts; - public PostService(IDatabaseConnection settings, IMongoClient mongoClient) + private readonly IHttpContextAccessor _httpContext; + public PostService(IDatabaseConnection settings, IMongoClient mongoClient, IHttpContextAccessor httpContext) { var database = mongoClient.GetDatabase(settings.DatabaseName); _posts = database.GetCollection(settings.PostCollectionName); + _httpContext = httpContext; } - public PostSend addPost(PostReceive post) + public async Task addPost(PostReceive post) { - return null; + Post p = new Post(); + p._id = ""; + p.ownerId = _httpContext.HttpContext.User.FindFirstValue("id"); + p.location = post.location; + p.description = post.description; + p.views = new List(); + p.reports = new List(); + p.ratings = new List(); + p.comments = new List(); + //add file + //add to database + return postToPostSend(p); + + } + public PostSend postToPostSend(Post post) + { + PostSend p = new PostSend(); + //Convert post to post send (TODO) + p._id = post._id; + return p; + } + + public async Task> getAllPosts() + { + List posts = await _posts.Find(_ => true).ToListAsync(); + List temp = new List(); + foreach (var post in posts) + { + temp.Add(postToPostSend(post)); + } + return temp; + } + + public async Task getPostById(string id) + { + Post p = await _posts.Find(post => post._id == id).FirstOrDefaultAsync(); + return postToPostSend(p); + } + //(TODO) ADD Delete and update } } -- cgit v1.2.3 From e39a826718441946a48e7e8c28a84933c2882d8a Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Thu, 3 Nov 2022 21:23:05 +0100 Subject: Napravljena kolekcija za fajlove. Omoguceno uplodovanje fajlova kada se dodaje objava. Dodat role za User-a u jwt-ju. --- Backend/Api/Api/.gitignore | 1 + Backend/Api/Api/Api.csproj | 4 ++ Backend/Api/Api/Controllers/PostController.cs | 2 +- Backend/Api/Api/Database/DatabaseConnection.cs | 1 + Backend/Api/Api/Interfaces/IDatabaseConnection.cs | 1 + Backend/Api/Api/Models/Post.cs | 5 ++- Backend/Api/Api/Program.cs | 5 ++- Backend/Api/Api/Services/FileService.cs | 28 +++++++++++++ Backend/Api/Api/Services/IFileService.cs | 8 ++++ Backend/Api/Api/Services/JwtService.cs | 3 +- Backend/Api/Api/Services/PostService.cs | 49 +++++++++++++++++++++-- Backend/Api/Api/appsettings.json | 13 +++--- 12 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 Backend/Api/Api/.gitignore create mode 100644 Backend/Api/Api/Services/FileService.cs create mode 100644 Backend/Api/Api/Services/IFileService.cs (limited to 'Backend/Api') diff --git a/Backend/Api/Api/.gitignore b/Backend/Api/Api/.gitignore new file mode 100644 index 0000000..f4b4ba8 --- /dev/null +++ b/Backend/Api/Api/.gitignore @@ -0,0 +1 @@ +Files/* \ No newline at end of file diff --git a/Backend/Api/Api/Api.csproj b/Backend/Api/Api/Api.csproj index 93e31b7..b09c2fd 100644 --- a/Backend/Api/Api/Api.csproj +++ b/Backend/Api/Api/Api.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs index 8db68a8..31dbeef 100644 --- a/Backend/Api/Api/Controllers/PostController.cs +++ b/Backend/Api/Api/Controllers/PostController.cs @@ -20,7 +20,7 @@ namespace Api.Controllers [HttpPost("add")] [Authorize(Roles ="User")] - public async Task> addPost([FromBody] PostReceive post) + public async Task> addPost([FromForm]PostReceive post) { var res = await _postService.addPost(post); if (res != null) diff --git a/Backend/Api/Api/Database/DatabaseConnection.cs b/Backend/Api/Api/Database/DatabaseConnection.cs index c2fea05..24b2b08 100644 --- a/Backend/Api/Api/Database/DatabaseConnection.cs +++ b/Backend/Api/Api/Database/DatabaseConnection.cs @@ -8,5 +8,6 @@ namespace Api.Database public string DatabaseName { get; set; } = String.Empty; public string UserCollectionName { get; set; } = String.Empty; public string PostCollectionName { get; set; } = String.Empty; + public string FileCollectionName { get; set; } = String.Empty; } } diff --git a/Backend/Api/Api/Interfaces/IDatabaseConnection.cs b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs index e3fc60c..744461b 100644 --- a/Backend/Api/Api/Interfaces/IDatabaseConnection.cs +++ b/Backend/Api/Api/Interfaces/IDatabaseConnection.cs @@ -6,5 +6,6 @@ string DatabaseName { get; set; } string UserCollectionName { get; set; } string PostCollectionName { get; set; } + string FileCollectionName { get; set; } } } diff --git a/Backend/Api/Api/Models/Post.cs b/Backend/Api/Api/Models/Post.cs index 456fcea..ee84e0f 100644 --- a/Backend/Api/Api/Models/Post.cs +++ b/Backend/Api/Api/Models/Post.cs @@ -1,5 +1,6 @@ using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson; +using System.ComponentModel.DataAnnotations; namespace Api.Models { @@ -9,7 +10,7 @@ namespace Api.Models [BsonRepresentation(BsonType.ObjectId)] public string _id { get; set; } public string ownerId { get; set; } - public Location location { get; set; } + public string locationId { get; set; } public string description { get; set; } public List views { get; set; } public List reports { get; set; } @@ -22,7 +23,7 @@ namespace Api.Models [BsonId] [BsonRepresentation(BsonType.ObjectId)] public string _id { get; set; } - public Location location { get; set; } + public string locationId { get; set; } public string description { get; set; } public List images { get; set; } diff --git a/Backend/Api/Api/Program.cs b/Backend/Api/Api/Program.cs index 9b80f3c..8dee088 100644 --- a/Backend/Api/Api/Program.cs +++ b/Backend/Api/Api/Program.cs @@ -23,6 +23,7 @@ builder.Services.AddSingleton(s => builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHttpContextAccessor(); @@ -70,11 +71,11 @@ if (app.Environment.IsDevelopment()) app.UseSwaggerUI(); } -app.UseAuthorization(); + //Add Authentication app.UseAuthentication(); - +app.UseAuthorization(); app.MapControllers(); app.Run(); diff --git a/Backend/Api/Api/Services/FileService.cs b/Backend/Api/Api/Services/FileService.cs new file mode 100644 index 0000000..1937c10 --- /dev/null +++ b/Backend/Api/Api/Services/FileService.cs @@ -0,0 +1,28 @@ +using Api.Interfaces; +using Api.Models; +using MongoDB.Driver; +using File = Api.Models.File; + +namespace Api.Services +{ + public class FileService : IFileService + { + private readonly MongoClient _client; + private readonly IMongoCollection _files; + private readonly IHttpContextAccessor _httpContext; + public FileService(IDatabaseConnection settings, IMongoClient mongoClient) + { + var database = mongoClient.GetDatabase(settings.DatabaseName); + _files = database.GetCollection(settings.FileCollectionName); + } + public async Task add(File file) + { + await _files.InsertOneAsync(file); + return file; + } + public async Task getById(string id) + { + return await _files.Find(file => file._id == id).FirstOrDefaultAsync(); + } + } +} diff --git a/Backend/Api/Api/Services/IFileService.cs b/Backend/Api/Api/Services/IFileService.cs new file mode 100644 index 0000000..269e202 --- /dev/null +++ b/Backend/Api/Api/Services/IFileService.cs @@ -0,0 +1,8 @@ +namespace Api.Services +{ + public interface IFileService + { + Task add(Models.File file); + Task getById(string id); + } +} \ No newline at end of file diff --git a/Backend/Api/Api/Services/JwtService.cs b/Backend/Api/Api/Services/JwtService.cs index fbf5724..c199484 100644 --- a/Backend/Api/Api/Services/JwtService.cs +++ b/Backend/Api/Api/Services/JwtService.cs @@ -24,7 +24,8 @@ namespace Api.Services var key = Encoding.ASCII.GetBytes(_config.GetSection("AppSettings:JwtToken").Value); var tokenDescriptor = new SecurityTokenDescriptor { - Subject = new ClaimsIdentity(new[] { new Claim("id", user._id) }), + Subject = new ClaimsIdentity(new[] { new Claim("id", user._id), + new Claim("role","User")}), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs index 49c92cb..2f29366 100644 --- a/Backend/Api/Api/Services/PostService.cs +++ b/Backend/Api/Api/Services/PostService.cs @@ -10,11 +10,13 @@ namespace Api.Services private readonly MongoClient _client; private readonly IMongoCollection _posts; private readonly IHttpContextAccessor _httpContext; - public PostService(IDatabaseConnection settings, IMongoClient mongoClient, IHttpContextAccessor httpContext) + private readonly IFileService _fileService; + public PostService(IDatabaseConnection settings, IMongoClient mongoClient, IHttpContextAccessor httpContext, IFileService fileService) { var database = mongoClient.GetDatabase(settings.DatabaseName); _posts = database.GetCollection(settings.PostCollectionName); _httpContext = httpContext; + _fileService = fileService; } public async Task addPost(PostReceive post) @@ -22,14 +24,53 @@ namespace Api.Services Post p = new Post(); p._id = ""; p.ownerId = _httpContext.HttpContext.User.FindFirstValue("id"); - p.location = post.location; + + p.locationId = post.locationId; p.description = post.description; p.views = new List(); p.reports = new List(); p.ratings = new List(); p.comments = new List(); - //add file - //add to database + p.images = new List(); + + var folderPath = Path.Combine(Directory.GetCurrentDirectory(), "Files", p.ownerId); + if (!Directory.Exists(folderPath)) + { + Directory.CreateDirectory(folderPath); + } + + foreach (var image in post.images) + { + var filename = image.FileName; + var ext=Path.GetExtension(filename).ToLowerInvariant(); + var name = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant(); + var fullPath=Path.Combine(folderPath, name); + int i = 0; + while (System.IO.File.Exists(fullPath)) + { + i++; + fullPath=Path.Combine(folderPath, name+i.ToString()+ext); + } + using(var stream=new FileStream(fullPath, FileMode.Create)) + { + await image.CopyToAsync(stream); + } + var f = new Models.File(); + f.path = fullPath; + f._id = ""; + f=await _fileService.add(f); + p.images.Add(f); + + } + await _posts.InsertOneAsync(p); + + + + + + + + return postToPostSend(p); } diff --git a/Backend/Api/Api/appsettings.json b/Backend/Api/Api/appsettings.json index 2be2426..d506b33 100644 --- a/Backend/Api/Api/appsettings.json +++ b/Backend/Api/Api/appsettings.json @@ -11,14 +11,15 @@ } }, "AllowedHosts": "*", - "DatabaseSettings": { + "DatabaseSettings": { - "ConnectionString": "mongodb://127.0.0.1:27017/", - "DatabaseName": "Odyssey", - "UserCollectionName": "users", - "PostCollectionName": "posts" + "ConnectionString": "mongodb://127.0.0.1:27017/", + "DatabaseName": "Odyssey", + "UserCollectionName": "users", + "PostCollectionName": "posts", + "FileCollectionName": "files" - }, + }, "EmailCfg": { "Email": "oddyssey.brzodolokacije@gmail.com", "SmtpServer": "smtp.gmail.com", -- cgit v1.2.3 From 43b5ce5b1c2a0976142a41e77f7caeb378dfd5ba Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Thu, 3 Nov 2022 21:36:59 +0100 Subject: Dodata kolekcija za lokacije. Napravljen kontroler i servis za lokacije. Todo(google maps api). --- Backend/Api/Api/Controllers/LocationController.cs | 54 +++++++++++++++++++++++ Backend/Api/Api/Database/DatabaseConnection.cs | 1 + Backend/Api/Api/Interfaces/IDatabaseConnection.cs | 1 + Backend/Api/Api/Interfaces/IFileService.cs | 8 ++++ Backend/Api/Api/Interfaces/ILocationService.cs | 11 +++++ Backend/Api/Api/Program.cs | 1 + Backend/Api/Api/Services/IFileService.cs | 8 ---- Backend/Api/Api/Services/LocationService.cs | 32 ++++++++++++++ Backend/Api/Api/appsettings.json | 3 +- 9 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 Backend/Api/Api/Controllers/LocationController.cs create mode 100644 Backend/Api/Api/Interfaces/IFileService.cs create mode 100644 Backend/Api/Api/Interfaces/ILocationService.cs delete mode 100644 Backend/Api/Api/Services/IFileService.cs create mode 100644 Backend/Api/Api/Services/LocationService.cs (limited to 'Backend/Api') 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> 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>> getAllPosts() + { + var res = await _locationService.getAllLocation(); + if (res != null) + { + return Ok(res); + } + return BadRequest(); + } + [HttpGet("loc /{id}")] + [Authorize(Roles = "User")] + public async Task> 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/Interfaces/IFileService.cs b/Backend/Api/Api/Interfaces/IFileService.cs new file mode 100644 index 0000000..e736305 --- /dev/null +++ b/Backend/Api/Api/Interfaces/IFileService.cs @@ -0,0 +1,8 @@ +namespace Api.Interfaces +{ + public interface IFileService + { + Task add(Models.File file); + Task getById(string id); + } +} \ No newline at end of file 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 add(Location loc); + Task getById(string id); + Task> 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(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHttpContextAccessor(); diff --git a/Backend/Api/Api/Services/IFileService.cs b/Backend/Api/Api/Services/IFileService.cs deleted file mode 100644 index 269e202..0000000 --- a/Backend/Api/Api/Services/IFileService.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Api.Services -{ - public interface IFileService - { - Task add(Models.File file); - Task getById(string id); - } -} \ No newline at end of file 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 _locations; + private readonly IHttpContextAccessor _httpContext; + public LocationService(IDatabaseConnection settings, IMongoClient mongoClient) + { + var database = mongoClient.GetDatabase(settings.DatabaseName); + _locations = database.GetCollection(settings.FileCollectionName); + } + public async Task add(Location loc) + { + //TODO GOOGLE MAPS API CALL FOR info + await _locations.InsertOneAsync(loc); + return loc; + } + public async Task getById(string id) + { + return await _locations.Find(loc => loc._id == id).FirstOrDefaultAsync(); + } + public async Task> 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": { -- cgit v1.2.3 From 759414e3138e02a540cbb74a9675d6dec6362004 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Thu, 3 Nov 2022 21:39:34 +0100 Subject: Typo fix. --- Backend/Api/Api/Services/LocationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Backend/Api') diff --git a/Backend/Api/Api/Services/LocationService.cs b/Backend/Api/Api/Services/LocationService.cs index b44f983..629c2a7 100644 --- a/Backend/Api/Api/Services/LocationService.cs +++ b/Backend/Api/Api/Services/LocationService.cs @@ -12,7 +12,7 @@ namespace Api.Services public LocationService(IDatabaseConnection settings, IMongoClient mongoClient) { var database = mongoClient.GetDatabase(settings.DatabaseName); - _locations = database.GetCollection(settings.FileCollectionName); + _locations = database.GetCollection(settings.LocationCollectionName); } public async Task add(Location loc) { -- cgit v1.2.3 From 3ba0c0557213a9444211b58a6a65ff4a2af09ea3 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Thu, 3 Nov 2022 21:54:29 +0100 Subject: fixed typo. --- Backend/Api/Api/Models/Location.cs | 2 +- Client/BrzoDoLokacije/app/src/main/res/layout/post_preview.xml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'Backend/Api') diff --git a/Backend/Api/Api/Models/Location.cs b/Backend/Api/Api/Models/Location.cs index 5e723e4..8cc4377 100644 --- a/Backend/Api/Api/Models/Location.cs +++ b/Backend/Api/Api/Models/Location.cs @@ -11,7 +11,7 @@ namespace Api.Models public String name { get; set; } public String city { get; set; } public String country { get; set; } - public String adress { get; set; } + public String address { get; set; } public double latitude { get; set; } public double longitude { get; set; } public LocationType type { get; set; } diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/post_preview.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/post_preview.xml index abbd549..48a3289 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/post_preview.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/post_preview.xml @@ -4,7 +4,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_padding="5dp" android:layout_margin="0dp" android:background="@drawable/rounded_picture_background" android:clipToOutline="true" @@ -14,7 +13,6 @@ android:id="@+id/imageView8" android:layout_width="match_parent" android:layout_height="330dp" - android:layout_padding="0dp" android:outlineProvider="background" android:src="@drawable/b1" app:layout_constraintBottom_toBottomOf="parent" -- cgit v1.2.3