홍지윤

Update Project directory

- edit page 띄우기 완료
- edit 기능까지 구현 완료!
......@@ -7,8 +7,8 @@ var postSchema = mongoose.Schema({
address:{type:String, required:[true, 'address is required!']},
body:{type:String, required:[true, 'Content is required!']},
author:{type:mongoose.Schema.Types.ObjectId, ref:'user', required:true},
createdAt:{type:Date, default:Date.now},
updatedAt:{type:Date},
createdAt:{type:Date, default:Date.now()},
updatedAt:{type:Date}
});
......
......@@ -4,6 +4,7 @@ var Post = require('../models/Post');
var util = require('../util');
// Post home
router.get('/', function(req, res){
Post.find({})
......@@ -55,8 +56,8 @@ router.get('/:id/edit', util.isLoggedin, checkPermission, function(req, res){
var errors = req.flash('errors')[0] || {};
if(!post){
Post.findOne({_id:req.params.id}, function(err, post){
if(err){return res.join(err)};
res.render('posts/edit', {posts:post, errors:errors});
if(err){return res.json(err)};
res.render('posts/edit', {post:post, errors:errors});
});
}
else{
......@@ -73,9 +74,9 @@ router.put('/:id', util.isLoggedin, checkPermission, function(req, res){
if(err){
req.flash('post', req.body),
req.flash('errors', util.parseError(err));
return res.redirect('/posts/'+ req.params,id + '/edit');
return res.redirect('/posts/'+ req.params.id + '/edit');
};
res.redirect('posts/' + req.params.id);
res.redirect('/posts/' + req.params.id);
});
});
......
......@@ -28,13 +28,21 @@
</div>
<div class="form-group">
<label for="address">address</label>
<input type="text" id="address" name="address" value="<%= post.address %>" class="form-control <%= (errors.address)?'is-invalid':'' %>">
<% if(errors.address){ %>
<span class="invalid-feedback"><%= errors.address.message %></span>
<% } %>
</div>
<div class="form-group">
<label for="body">Body</label>
<textarea id="body" name="body" rows="5" class="form-control <%= (errors.body)?'is-invalid':''%>"><%= post.body %></textarea>
<% if(errors.body){ %>
<span class="invalid-feedback"><%= errors.body.message %></span>
<% } %>
</div>
<% if(errors.unhandled){ %>
<div class="invalid-feedback b-block">
<%= errors.unhandled %>
......@@ -49,5 +57,6 @@
</form>
</div>
<%- include('../partials/gmap') %>
</body>
</html>
\ No newline at end of file
......