diff options
author | Jelena Petrovic <jelenapetrovic.7119@gmail.com> | 2022-11-28 17:38:42 +0100 |
---|---|---|
committer | Jelena Petrovic <jelenapetrovic.7119@gmail.com> | 2022-11-28 17:38:42 +0100 |
commit | c20758b0194ecd6fbf50afbd808801542a8f292d (patch) | |
tree | e57be44d8defce758a5e07afb625be289d8f1ad3 /Backend | |
parent | e4f4d06678b01028d1434865e721cd49707f822f (diff) |
dodavanje samo novog komentara u vec ucitane komentare #58
Diffstat (limited to 'Backend')
-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 | 16 |
3 files changed, 15 insertions, 5 deletions
diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs index 4c6fbac..ec5829e 100644 --- a/Backend/Api/Api/Controllers/PostController.cs +++ b/Backend/Api/Api/Controllers/PostController.cs @@ -98,7 +98,7 @@ namespace Api.Controllers [HttpPost("posts/{id}/addcomment")] [Authorize(Roles = "User")] - public async Task<ActionResult<Comment>> addComment([FromBody] CommentReceive cmnt,string id) + public async Task<ActionResult<CommentSend>> addComment([FromBody] CommentReceive cmnt,string id) { var userid = await _userService.UserIdFromJwt(); var c = await _postService.AddComment(cmnt, userid, id); diff --git a/Backend/Api/Api/Interfaces/IPostService.cs b/Backend/Api/Api/Interfaces/IPostService.cs index 5b04dc3..9bf71d5 100644 --- a/Backend/Api/Api/Interfaces/IPostService.cs +++ b/Backend/Api/Api/Interfaces/IPostService.cs @@ -10,7 +10,7 @@ namespace Api.Interfaces Task<PostSend> postToPostSend(Post post); Task<Boolean> AddOrReplaceRating(RatingReceive rating, string userid); Task<Boolean> RemoveRating(string postid, string userid); - Task<Comment> AddComment(CommentReceive cmnt, string userid, string postid); + Task<CommentSend> AddComment(CommentReceive cmnt, string userid, string postid); Task<List<CommentSend>> ListComments(string postid); Task<List<CommentSend>> CascadeComments(string parentid, Post p); Task<Boolean> DeleteComments(string postid, string cmntid,string userid); diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs index 0676d74..e59c735 100644 --- a/Backend/Api/Api/Services/PostService.cs +++ b/Backend/Api/Api/Services/PostService.cs @@ -178,20 +178,30 @@ namespace Api.Services } return false; } - public async Task<Comment> AddComment(CommentReceive cmnt,string userid,string postid) + public async Task<CommentSend> AddComment(CommentReceive cmnt,string userid,string postid) { Post p = await _posts.Find(post => post._id == postid).FirstOrDefaultAsync(); if (p != null) { - Comment c= new Comment(); + Comment c = new Comment(); + CommentSend c1= new CommentSend(); c.parentId = cmnt.parentId; + c1.parentId = cmnt.parentId; c.userId = userid; + c1.userId = userid; c.comment = cmnt.comment; + c1.comment = cmnt.comment; c.timestamp = DateTime.Now.ToUniversalTime(); + c1.timestamp = c.timestamp; c._id = ObjectId.GenerateNewId().ToString(); + c1._id = c._id; + var user = await _users.Find(x => x._id == c.userId).FirstOrDefaultAsync(); + if (user != null) + c1.username = user.username; + else c1.username = "Deleted user"; p.comments.Add(c); await _posts.ReplaceOneAsync(x => x._id == postid, p); - return c; + return c1; } return null; } |