diff --git a/Part_4/blog-list/controllers/blogs.js b/Part_4/blog-list/controllers/blogs.js index 1a162c1..93ad6c9 100644 --- a/Part_4/blog-list/controllers/blogs.js +++ b/Part_4/blog-list/controllers/blogs.js @@ -34,6 +34,19 @@ blogsRouter.post('/', userExtracter, async (request, response) => { response.status(201).json(savedBlog) }) +blogsRouter.post('/:id/comments', userExtracter, async (request, response) => { + const { comment } = request.body + const blogToAddComment = await Blog.findById(request.params.id) + + console.log(blogToAddComment) + blogToAddComment.comments = blogToAddComment.comments.concat(comment) + await blogToAddComment.save() + + console.log(blogToAddComment) + console.log(comment) + response.status(200).end() +}) + blogsRouter.delete('/:id', userExtracter, async (request, response) => { const blogToDel = await Blog.findById(request.params.id) diff --git a/Part_4/blog-list/models/blog.js b/Part_4/blog-list/models/blog.js index 94fc223..1a25e73 100644 --- a/Part_4/blog-list/models/blog.js +++ b/Part_4/blog-list/models/blog.js @@ -8,7 +8,10 @@ const blogSchema = new mongoose.Schema({ user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' - } + }, + comments : [ + { type: String } + ] }) blogSchema.set('toJSON', { diff --git a/Part_7/bloglist-frontend/src/components/BlogView.js b/Part_7/bloglist-frontend/src/components/BlogView.js index 291fd97..dbec252 100644 --- a/Part_7/bloglist-frontend/src/components/BlogView.js +++ b/Part_7/bloglist-frontend/src/components/BlogView.js @@ -97,6 +97,16 @@ const BlogView = () => { {user.username === blog.user.username ? ( ) : null} +

Comments

+ ) }