diff options
-rw-r--r-- | Backend/Api/Api/Controllers/PostController.cs | 2 | ||||
-rw-r--r-- | Backend/Api/Api/Interfaces/IPostService.cs | 2 | ||||
-rw-r--r-- | Backend/Api/Api/Services/PostService.cs | 21 |
3 files changed, 18 insertions, 7 deletions
diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs index 62f77f1..a61ee2e 100644 --- a/Backend/Api/Api/Controllers/PostController.cs +++ b/Backend/Api/Api/Controllers/PostController.cs @@ -42,7 +42,7 @@ namespace Api.Controllers } return BadRequest(); } - [HttpGet("posts /{id}")] + [HttpGet("posts/{id}")] [Authorize(Roles = "User")] public async Task<ActionResult<PostSend>> getPostByid(string id) { diff --git a/Backend/Api/Api/Interfaces/IPostService.cs b/Backend/Api/Api/Interfaces/IPostService.cs index 31e80cd..29a824a 100644 --- a/Backend/Api/Api/Interfaces/IPostService.cs +++ b/Backend/Api/Api/Interfaces/IPostService.cs @@ -7,6 +7,6 @@ namespace Api.Interfaces Task<PostSend> addPost(PostReceive post); Task<List<PostSend>> getAllPosts(); Task<PostSend> getPostById(string id); - PostSend postToPostSend(Post post); + Task<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 0a12f39..e9a56d2 100644 --- a/Backend/Api/Api/Services/PostService.cs +++ b/Backend/Api/Api/Services/PostService.cs @@ -11,12 +11,14 @@ namespace Api.Services private readonly IMongoCollection<Post> _posts; private readonly IHttpContextAccessor _httpContext; private readonly IFileService _fileService; - public PostService(IDatabaseConnection settings, IMongoClient mongoClient, IHttpContextAccessor httpContext, IFileService fileService) + private readonly ILocationService _locationService; + public PostService(IDatabaseConnection settings, IMongoClient mongoClient, IHttpContextAccessor httpContext, IFileService fileService,ILocationService locationService) { var database = mongoClient.GetDatabase(settings.DatabaseName); _posts = database.GetCollection<Post>(settings.PostCollectionName); _httpContext = httpContext; _fileService = fileService; + _locationService = locationService; } public async Task<PostSend> addPost(PostReceive post) @@ -63,14 +65,23 @@ namespace Api.Services } await _posts.InsertOneAsync(p); - return postToPostSend(p); + return await postToPostSend(p); } - public PostSend postToPostSend(Post post) + public async Task<PostSend> postToPostSend(Post post) { PostSend p = new PostSend(); //Convert post to post send (TODO) p._id = post._id; + p.ownerId = post.ownerId; + p.description = post.description; + p.location = await _locationService.getById(post.locationId); + p.images = post.images; + p.views = 1;//Default values todo + p.ratings = 1; + p.comments = null; + + return p; } @@ -80,7 +91,7 @@ namespace Api.Services List<PostSend> temp = new List<PostSend>(); foreach (var post in posts) { - temp.Add(postToPostSend(post)); + temp.Add(await postToPostSend(post)); } return temp; } @@ -88,7 +99,7 @@ namespace Api.Services public async Task<PostSend> getPostById(string id) { Post p = await _posts.Find(post => post._id == id).FirstOrDefaultAsync(); - return postToPostSend(p); + return await postToPostSend(p); } //(TODO) ADD Delete and update |