Toggle navigation
Toggle navigation
This project
Loading...
Sign in
201side
/
floater
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
robin*
2020-12-07 22:39:33 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f8c408c0dcebeeee5f3b163afcbc71752e87ad27
f8c408c0
1 parent
b7a0a1bd
기본 판과 스레드 get/post 메소드 구현
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
src/routes/board.js
src/routes/board.js
0 → 100644
View file @
f8c408c
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
Please
register
or
login
to post a comment