Showing
1 changed file
with
17 additions
and
1 deletions
... | @@ -13,8 +13,9 @@ app.get('/board/:bid', async(req, res) => { | ... | @@ -13,8 +13,9 @@ app.get('/board/:bid', async(req, res) => { |
13 | res.render('threadslist', {board, threads}); | 13 | res.render('threadslist', {board, threads}); |
14 | }); | 14 | }); |
15 | 15 | ||
16 | +/* | ||
16 | app.post('/board/:bid/thread', async(req, res) => { | 17 | app.post('/board/:bid/thread', async(req, res) => { |
17 | - if(!req.body.title || !req.body.content) { | 18 | + if(!req.body.title || !req.body.content) { // |
18 | res.status(400).json({error: 'Invalid input'}); | 19 | res.status(400).json({error: 'Invalid input'}); |
19 | } | 20 | } |
20 | let board = await db.get('board').findOne({name: req.params.bid}); | 21 | let board = await db.get('board').findOne({name: req.params.bid}); |
... | @@ -24,6 +25,21 @@ app.post('/board/:bid/thread', async(req, res) => { | ... | @@ -24,6 +25,21 @@ app.post('/board/:bid/thread', async(req, res) => { |
24 | let thread = await db.get('thread').insert({board: board._id, title: req.body.title, content: req.body.content, lastUpdated: Date.now(), count: 1}); | 25 | let thread = await db.get('thread').insert({board: board._id, title: req.body.title, content: req.body.content, lastUpdated: Date.now(), count: 1}); |
25 | res.json({thread}); | 26 | res.json({thread}); |
26 | }); | 27 | }); |
28 | +*/ | ||
29 | + | ||
30 | +app.post('/board/:bid', async(req, res) => { | ||
31 | + if(!req.body.title || !req.body.content) { | ||
32 | + res.status(400).send('제목이나 내용을 써주세요.'); | ||
33 | + return; | ||
34 | + } | ||
35 | + let board = await db.get('board').findOne({name:req.params.bid}); | ||
36 | + if (!board) { | ||
37 | + res.status(404).send('그런 판은 우리에게 있을 수 없어.'); | ||
38 | + } | ||
39 | + let thread = await db.get('thread').insert({board: board._id, title: req.body.title, content: req.body.content, lastUpdated: Date.now(), count: 1}); | ||
40 | + res.redirect('/thread/'+thread.insertedIds); | ||
41 | +}); | ||
42 | + | ||
27 | app.get('/borad/:bid/thread/:tid', async(req, res) => { | 43 | app.get('/borad/:bid/thread/:tid', async(req, res) => { |
28 | let thread = await db.get('thread').findOne(req.params.tid); | 44 | let thread = await db.get('thread').findOne(req.params.tid); |
29 | if(!thread) { | 45 | if(!thread) { | ... | ... |
-
Please register or login to post a comment