API Document
๊ฐ์ฅ ์ด๊ธฐ ๋ฉ์ธ ํ๋ฉด์์, ๋ชจ๋ ๋ถํธ์บ ํ๋ฆฌ์คํธ๋ฅผ ๋ค getํด์์ ๋ชจ๋ ๋ฆฌ๋ทฐ๋ฅผ ๋ณด์ฌ์ค๋ค.
http://localhost:4000/bootcamplists
๐ฅ Request
๐ค Response
- 200:OK
0: {label: "Code States", bootcamp_id: 1, value: 1}
1: {label: "Fast Campus", bootcamp_id: 2, value: 2}
2: {label: "Wecode", bootcamp_id: 3, value: 3}
3: {label: "Vanilla Coding", bootcamp_id: 4, value: 4}
4: {label: "Sparta Codingclub", bootcamp_id: 5, value: 5}
5: {label: "Dream Coding", bootcamp_id: 6, value: 6}
6: {label: "Nomad Coders", bootcamp_id: 7, value: 7}
7: {label: "Code Lion", bootcamp_id: 8, value: 8}
- 500: Internal Server Error
'err'
client์์ ์์ฒญํ๋ bootcampList์ bootcamp_id์ ํด๋นํ๋ ๋ฆฌ๋ทฐ ์ค active:true์ธ ๋ฆฌ๋ทฐ๋ค์ ๋ณด๋ด์ค๋ค. sesssion์ ํ์ธํ์ฌ ๋ก๊ทธ์ธ ํ ์ ์ ๋ {isLogin:true} ์ ๋ณด๋ฅผ ํจ๊ป ๋ณด๋ด์ค๋ค.
http://localhost:4000/reviews
๐ฅ Request
- Body Parameter : bootcampList
0: {label: "Code States", bootcamp_id: 1, value: 1}
1: {label: "Fast Campus", bootcamp_id: 2, value: 2}
2: {label: "Wecode", bootcamp_id: 3, value: 3}
3: {label: "Vanilla Coding", bootcamp_id: 4, value: 4}
4: {label: "Sparta Codingclub", bootcamp_id: 5, value: 5}
5: {label: "Dream Coding", bootcamp_id: 6, value: 6}
6: {label: "Nomad Coders", bootcamp_id: 7, value: 7}
7: {label: "Code Lion", bootcamp_id: 8, value: 8}
๐ค Response
- 200:OK
if (!req.session.userid) {
[{active: true
bootcamp_id: 1
bootcampname: {name: "Code States"}
comment: "์ง์ง ๋ฐฑ์ง๋ถํฐ ํ๋ก์ ํธ๋ฅผ ์งํ ํ ์ ์๋๊ฒ ์ข๋ค. "
createdAt: "2020-11-03T00:33:20.000Z"
curriculum: "๋ง์กฑ"
githublink: "https://github.com/Gracechung-sw"
id: 4
level: "์ด๋ ค์"
price: "100๋ง์ ์ด์"
recommend: "์ถ์ฒ"
updatedAt: "2020-11-03T00:33:20.000Z"
useremail: {email: "jhjyj5414@naver.com"}},{...}, {...}
]}
else{
[{active: true
bootcamp_id: 1
bootcampname: {name: "Code States"}
comment: "์ง์ง ๋ฐฑ์ง๋ถํฐ ํ๋ก์ ํธ๋ฅผ ์งํ ํ ์ ์๋๊ฒ ์ข๋ค. "
createdAt: "2020-11-03T00:33:20.000Z"
curriculum: "๋ง์กฑ"
githublink: "https://github.com/Gracechung-sw"
id: 4
level: "์ด๋ ค์"
price: "100๋ง์ ์ด์"
recommend: "์ถ์ฒ"
updatedAt: "2020-11-03T00:33:20.000Z"
useremail: {email: "jhjyj5414@naver.com"}},{...}, {...}
], {isLogin:true}
}
- 404: Not Found {"message":"Error"}
client์์ ๋ณด๋ด๋ ๋ฆฌ๋ทฐ ๋ด์ฉ์ reviews ํ ์ด๋ธ์ INSERTํ๋ค. ( ๊ธฐ์กด์ ์ด๋ฏธ ์์ฑํ ๋ถํธ์บ ํ์ ๋ํ ์ค๋ณต ์์ฑ ๋ถ๊ฐ)
http://localhost:4000/reviews/create
๐ฅ Request
- Form Data Parameters
users_id: users_id (req.session.userid),
> foreign key JOIN
bootcampname
> bootcamp_id: data.dataValues.id (bootcampname์ผ๋ก bootcamp_lists ํ
์ด๋ธ์์ id๋ฅผ find),
> foreign key JOIN
githublink: githublink,
active: true,
price: price,
level: level,
recommend: recommend,
curriculum: curriculum,
comment: comment,
๐ค Response
- 201:OK
active: true
bootcamp_id: 1
comment: "gg"
createdAt: "2020-11-03T02:48:03.144Z"
curriculum: "๋ถ๋ง์กฑ"
githublink: "https://github.com/Gracechung-sw"
id: 8
level: "์ฌ์"
price: "10๋ง์ ์ดํ"
recommend: "๋น์ถ์ฒ"
updatedAt: "2020-11-03T02:48:03.144Z"
users_id: 1
- 401: ์๋ชป๋ ๋ถํธ์บ ํ์ด๋ฆ ์ ํ ์,
'unvalid name'
- 409:
'ํด๋น ๋ถํธ์บ ํ์ ๋ํ ๋ฆฌ๋ทฐ๋ ์ด๋ฏธ ์์ฑํ์ต๋๋ค.'
- 500: Internal Server Error
'err'
user ๋ณธ์ธ์ด ์์ฑํ ๋ฆฌ๋ทฐ์นด๋๋ฅผ ์ญ์ ํ๋ค. ์ค์ ๋ก๋ soft delete๋ฅผ ๊ตฌํํ์ฌ, update ๋ฉ์๋๋ฅผ ํตํด reviews ํ ์ด๋ธ ๋ด์ active ์นผ๋ผ์ false๋ก ๋ฐ๊ฟ์ค๋ค.
http://localhost:4000/reviews/delete
๐ฅ Request
- Body Parameter :
users_id: users_id(req.session.userid),
bootcampname: bootcampname,
๐ค Response
- 201:OK
active: false
- 500: Internal Server Error
'err'
์ ์ ๊ฐ ์์ ์ด ์์ฑํ ๋ฆฌ๋ทฐ๋ฅผ ์์ ( ํ๋์ ๋ถํธ์บ ํ์ ๋ํ ์ค๋ณต ์์ ๋ฐ ๊ธฐ์ฌ ๋ถ๊ฐ )
http://localhost:4000/reviews/edit
๐ฅ Request
- Body Parameter :
users_id: users_id (req.session.userid),
bootcampname : bootcampname(๋ณ๊ฒฝ ์ํ๋ ๋ถํธ์บ ํ์ด๋ฆ)
bootcampname_before(์ ์ ๋ณ๋ ์
๋ ฅX)
> bootcamp_id: data.dataValues.id (bootcampname์ผ๋ก bootcamp_lists ํ
์ด๋ธ์์ id๋ฅผ find),
> client์์ ๋ณ๋๋ก ๋ณด๋ด์ฃผ๋ ๋ฐ์ดํฐ, ๋ฆฌ๋ทฐ ์์ ์์, ๋ณ๊ฒฝํ๊ณ ์ ํ๋ ๋ฆฌ๋ทฐ๋ฅผ ์ ํํ๋ ๊ธฐ์ค์๊ฐ ๋๋ค.
githublink: githublink,
active: true,
price: price,
level: level,
recommend: recommend,
curriculum: curriculum,
comment: comment,
๐ค Response
- 201:OK
active: true
bootcamp_id: 2
comment: "gg"
createdAt: "2020-11-03T02:48:03.144Z"
curriculum: "๋ถ๋ง์กฑ"
githublink: "https://github.com/Gracechung-sw"
id: 8
level: "์ฌ์"
price: "10๋ง์ ์ดํ"
recommend: "๋น์ถ์ฒ"
updatedAt: "2020-11-03T02:48:03.144Z"
users_id: 1
- 401 :
unvalid name
- 409 :
ํด๋น ๋ถํธ์บ ํ์ ๋ํ ๋ฆฌ๋ทฐ๋ ์ด๋ฏธ ์์ฑํ์ต๋๋ค.
- 500: Internal Server Error
'err'
ํ์๊ฐ์ API -> githubId์ ๋ํ ์ค๋ณต ๊ฐ์ ๋ฐฉ์ง๋ฅผ ์ํด findOrCreate ํ์ฉ ์์ ๋ก๊ทธ์ธ ์ฌ์ฉ์์ ๊ตฌ๋ถ์ํด, kind_login ์นผ๋ผ์ basic ๊ฐ์ ์ถ๊ฐํ๋ฉฐ DB์ ๋ฐ์ดํฐ ์ ์ฅ (client์์ ์ ๋ฌ๋๋ ๋ฐ์ดํฐ๋ ์๊ณ , ์๋ฒ์์ ์ค์ ํด์ค) ์ด๋ฉ์ผ ์ค๋ณต ๋ฐฉ์ง๋ ๋ณ๋ API ๊ตฌ์ฑ
http://localhost:4000/users/signup
๐ฅ Request
useremail: useremail,
password: password,
githubId : githubId
๐ค Response
- 200: OK
- 401 :
'ํด๋น githubId๋ก๋ ์ด๋ฏธ ๊ฐ์
๋์ด์์ต๋๋ค.
- 500: Internal Server Error
'err'
ํ์ ๊ฐ์ ์์ ์ค์๊ฐ์ผ๋ก ์๋ฒ์ ํด๋ผ์ด์ธํธ๊ฐ ํต์ ํ์ฌ, ์์ด๋ ์ค๋ณต ์ ๊ฒ
http://localhost:4000/users/signup/checkId
๐ฅ Request
useremail: e.target.value,
๐ค Response
- 200:OK
if (usersํ
์ด๋ธ์ email ๋ฐ์ดํฐ !== null) {
createdAt: "2020-11-02T13:07:51.000Z"
email: "jhjyj5414@naver.com"
githubId: "Grace"
id: 1
password: "qwerty12345"
updatedAt: "2020-11-02T13:08:49.000Z"
} else {
null
}
- 500: Internal Server Error
'err'
์ผ๋ฐํ์๊ฐ์ ์ ํตํ ๊ณ ๊ฐ
http://localhost:4000/users/login
๐ฅ Request
useremail: useremail
password: password
๐ค Response
- 200: OK
{ id: 5 }
- 401: Unauthorized
'unvalid user'
- 500: Internal Server Error
'err'
http://localhost:4000/users/logout
๐ฅ Request
๐ค Response
- 200: OK
redirect('/');
- 400: Bad Request
'you are currently not logined'
- 500: Internal Server Error
'err'
๊ฐ์ ์ ์ ๋ ฅํ githubId๋ฅผ ํตํด, ๊ฐ์ ๋ ๋ฉ์ผ find ์์ ๋ก๊ทธ์ธ์ผ๋ก ๊ฐ์ ํ ์ฌ์ฉ์๊ฐ githubId ์ ๋ ฅ ์์, ๋ฉ์ผ์ฃผ์ ์ฐพ์ ์ ์์
http://localhost:4000/users/login/findId
๐ฅ Request
githubId: githubId
๐ค Response
- 200: OK
useremail
- 400: Bad Request
'have to apply github Id'
- 409: Bad Request
'์์
๋ก๊ทธ์ธ์ผ๋ก ๊ฐ์
ํ์
จ๊ตฐ์? ์์ด๋์ฐพ๊ธฐ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค'
- 500: Internal Server Error
'err'
์ ์ ์์ฒญ์ด ์จ ๊ฑฐ๋ผ๋ฉด users ํ ์ด๋ธ์์ useremail๊ณผ githubId์ ํด๋นํ๋ row์ password๋ฅผ ์ฐพ์์ useremail์ฃผ์๋ก ๋ณด๋ด์ค ๋ค, ์๋ต์ ํ๋ค.
http://localhost:4000/users/login/findpw
๐ฅ Request
useremail: useremail,
githubId: githubId,
๐ค Response
- 200: OK
{ success: true }
- 400: Bad Request
'informations are not matched or have to sign up '
- 500: Internal Server Error
'err'
์๋ฒ์์ ์ธ์ ์ ํ์ธํด์ ๊ทธ์ ๋ง๋ ํ์์ users ํ ์ด๋ธ ์ ๋ณด์ ๊ทธ ํ์์ด ์์ฑํ reviews๋ฅผ ์๋ตํด์ค๋ค. ์ด ๋, ์์ ๋ก๊ทธ์ธ ์ด์ฉ ์ ์ ๋, ๊ฐ์ธ ์ ๋ณด๋ ๋ง์ดํ์ด์ง์์ ํ์ธ ๋ฐ ์์ ํ ์ ์๋ค.
http://localhost:4000/users/read
๐ฅ Request
๐ค Response
- 200: OK
if (์์
๋ก๊ทธ์ธ์ผ๋ก ๊ฐ์
ํ ์ ์ ) {
๊ฐ์ธ์ ๋ณด๋ฐ์ดํฐ = {}
}
if(๋ฆฌ๋ทฐ๋ฅผ ์์ฑํ ์ ์ด ์๋ ์ ์ ){
{ [{id: 1, email: "jhjyj5414@naver.com", password: "qwerty12345", githubId: "Grace", createdAt: "2020-11-02T13:07:51.000Z", โฆ},
[
{active: true
bootcamp_id: 1
bootcampname: {name: "Code States"}
comment: "์ง์ง ๋ฐฑ์ง๋ถํฐ ํ๋ก์ ํธ๋ฅผ ์งํ ํ ์ ์๋๊ฒ ์ข๋ค. "
createdAt: "2020-11-03T00:33:20.000Z"
curriculum: "๋ง์กฑ"
githublink: "https://github.com/Gracechung-sw"
id: 4
level: "์ด๋ ค์"
price: "100๋ง์ ์ด์"
recommend: "์ถ์ฒ"
updatedAt: "2020-11-03T00:33:20.000Z"
useremail: {email: "jhjyj5414@naver.com"}},
{...}, {...}
]
}
}
else{
if (์์
๋ก๊ทธ์ธ์ผ๋ก ๊ฐ์
ํ ์ ์ ) {
{{}, โฆ}
} else {
{id: 1, email: "jhjyj5414@naver.com", password: "qwerty12345", githubId: "Grace", createdAt: "2020-11-02T13:07:51.000Z", โฆ}
}
- 401:
'unvalid name'
- 500: Internal Server Error
'err'
users ํ ์ด๋ธ์ email๋ฐ์ดํฐ ์ค useremail์ ํด๋นํ๋ row์ password, githubId์ ์์ ํ๊ณ ์ธ์ ๋ ์ญ์ ํ์ฌ์ ๋ก๊ทธ์ธ ์ ์ผ๋ก ๋์๊ฐ๊ฒ ํ๋ค.
http://localhost:4000/users/edit
๐ฅ Request
useremail:useremail,
password: password,
githubId: githubId
๐ค Response
- 200:OK
'์ ๋ณด์์ ์๋ฃ'
- 400: Bad Request
'you are currently not logined'
- 500: Internal Server Error
'err'
์ธ์ ์ ํ์ธํ ๋ค ๊ทธ์ ํด๋นํ๋ ์ ์ ์ ๋ฐ์ดํฐ๋ฅผ ์ญ์ ํ๊ณ ์ธ์ ๋ ์ญ์ ํ์ฌ์ ๋ก๊ทธ์ธ ์ ์ผ๋ก ๋์๊ฐ๊ฒ ํ๋ค.
http://localhost:4000/users/delete
๐ฅ Request
๐ค Response
- 200:OK
session.destroy()
- 500: Internal Server Error
'err'
client์์ href๋ก ๋งํฌ ์ด๋ํ๊ฒ ๋๋ฉด, get method๋ก ์์ ๋ก๊ทธ์ธ ์คํ
http://localhost:4000/auth/github
๐ฅ Request
๐ค Response
- 200:OK
const githubAuthUrl =
'https://github.com/login/oauth/authorize?client_id=' +
github.clientID +
'&redirect_uri=' +
github.redirectUri;
res.redirect(githubAuthUrl)
- 500: Internal Server Error
'err'
์ ์ ๊ฐ ์์ ์ request token ์์ฒญํ๋ฉฐ redirect page๋ก ์ด๋๋๋ฉฐ, ์๋ฒ๊ฐ ์์ ์ token์ ๊ธฐ๋ฐ์ผ๋ก ์ธ์ฆ์ ์์ฒญํ๋ clientํ๋จ.
http://localhost:4000/auth/github/callback
๐ฅ Request
try {
axios.post => access token ๋ฐ์์ด
try {
axios.get => access token์ผ๋ก ์์
์์ ์ ์ ๋ฐ์ดํฐ ๋ฐ์์ด
} catch
}catch
๐ค Response
- 200:OK
{ githubId : authdata.login ๋ฐ์ดํฐํ์ฉ,
email : authdata.id ํ์ฉ,
password : authdata.node_id ํ์ฉ,
kind_login : 'social'
}
- 500: Internal Server Error
'err'