Skip to content

API Document

Hazel_Song edited this page Nov 4, 2020 · 8 revisions

GET Get bootcamplists

๊ฐ€์žฅ ์ดˆ๊ธฐ ๋ฉ”์ธ ํ™”๋ฉด์—์„œ, ๋ชจ๋“  ๋ถ€ํŠธ์บ ํ”„๋ฆฌ์ŠคํŠธ๋ฅผ ๋‹ค 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'

POST Post Reviews

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"}

POST Create Reviews

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'

PUT Delete Reviews

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'

PUT Edit Reviews

์œ ์ €๊ฐ€ ์ž์‹ ์ด ์ž‘์„ฑํ•œ ๋ฆฌ๋ทฐ๋ฅผ ์ˆ˜์ • ( ํ•˜๋‚˜์˜ ๋ถ€ํŠธ์บ ํ”„์— ๋Œ€ํ•œ ์ค‘๋ณต ์ˆ˜์ • ๋ฐ ๊ธฐ์žฌ ๋ถˆ๊ฐ€ )

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'

POST Signup

ํšŒ์›๊ฐ€์ž… 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'

POST Check UserId

ํšŒ์› ๊ฐ€์ž…์‹œ์— ์‹ค์‹œ๊ฐ„์œผ๋กœ ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ํ†ต์‹ ํ•˜์—ฌ, ์•„์ด๋”” ์ค‘๋ณต ์ ๊ฒ€

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'

POST Login

์ผ๋ฐ˜ํšŒ์›๊ฐ€์ž…์„ ํ†ตํ•œ ๊ณ ๊ฐ

http://localhost:4000/users/login

๐Ÿ“ฅ Request

useremail: useremail
password: password

๐Ÿ“ค Response

  • 200: OK
{ id: 5 }
  • 401: Unauthorized
'unvalid user'
  • 500: Internal Server Error
'err'

POST Logout

http://localhost:4000/users/logout

๐Ÿ“ฅ Request

๐Ÿ“ค Response

  • 200: OK
redirect('/');
  • 400: Bad Request
'you are currently not logined'
  • 500: Internal Server Error
'err'

POST Find UserId

๊ฐ€์ž… ์‹œ ์ž…๋ ฅํ•œ 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'

POST Find UserPw

์ •์ƒ ์š”์ฒญ์ด ์˜จ ๊ฑฐ๋ผ๋ฉด 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'

GET Read Mypage

์„œ๋ฒ„์—์„œ ์„ธ์…˜์„ ํ™•์ธํ•ด์„œ ๊ทธ์— ๋งž๋Š” ํšŒ์›์˜ 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'

PUT Edit UserInfo

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'

DELETE Delete UserInfo

์„ธ์…˜์„ ํ™•์ธํ•œ ๋’ค ๊ทธ์— ํ•ด๋‹นํ•˜๋Š” ์œ ์ €์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•˜๊ณ  ์„ธ์…˜๋„ ์‚ญ์ œํ•˜์—ฌ์„œ ๋กœ๊ทธ์ธ ์ „์œผ๋กœ ๋Œ์•„๊ฐ€๊ฒŒ ํ•œ๋‹ค.

http://localhost:4000/users/delete

๐Ÿ“ฅ Request

๐Ÿ“ค Response

  • 200:OK
session.destroy()
  • 500: Internal Server Error
'err'

GET social login page

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'

GET social login / redirect page

์œ ์ €๊ฐ€ ์†Œ์…œ์— 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'