robin*

기본 판과 스레드 get/post 메소드 구현

const app = require('./server');
const db = require('./db');
app.get('/board/:bid', async(req, res) => {
let board = await db.get('board').findOne({name: req.params.bid});
if(!board) {
res.status(404).json({error: 'Board not found'});
}
let threads = await db.get('thread').find({board: board._id}, {sort: '-lastUpdated', limit: 20});
res.json({threads: threads})
});
app.post('/board/:bid/thread', async(req, res) => {
if(!req.body.title || !req.body.content) {
res.status(400).json({error: 'Invalid input'});
}
let board = await db.get('board').findOne({name: req.params.bid});
if(!board) {
res.status(404).json({error: 'Board not found'});
}
let thread = await db.get('thread').insert({board: board._id, title: req.body.title, content: req.body.content, lastUpdated: Date.now()});
res.json({thread});
});
app.get('/borad/:bid/thread/:tid', async(req, res) => {
let thread = await db.get('thread').findOne(req.params.tid);
if(!thread) {
res.status(404).json({error: 'Thread not found'});
}
res.json(thread);
});
\ No newline at end of file