From d077e8dfb5791ec196f0dcfe1555ece43bfafae4 Mon Sep 17 00:00:00 2001 From: uhmtoto Date: Wed, 16 Oct 2019 13:04:46 +0900 Subject: [PATCH 1/6] docs: add auth route information --- src/router/auth/index.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/router/auth/index.js b/src/router/auth/index.js index 0498ea2..88ddd14 100644 --- a/src/router/auth/index.js +++ b/src/router/auth/index.js @@ -5,16 +5,42 @@ import controllers from './controllers' const router = Router() +/** + * 디미고 계정 정보를 받아 에코를 가입합니다. + * @route POST /auth/join + * @group Auth - 인증 관련 메소드 + * @param {string} username.query.required - 사용자 이름 + * @param {string} password.query.required - 사용자 비밀번호 + * @returns {object} 200 - 사용자 정보 + * @returns {Error} 401 - 일치하는 계정이 디미고 API에 존재하지 않습니다. + */ router.post('/join', [ check('username').isString().not().isEmpty(), check('password').isString().not().isEmpty() ], checkValidation, controllers.Join) +/** + * 디미고 계정 정보를 받아 에코에서의 토큰을 발행합니다. + * @route POST /auth/login + * @group Auth - 인증 관련 메소드 + * @param {string} username.query.required - 사용자 이름 + * @param {string} password.query.required - 사용자 비밀번호 + * @returns {object} 200 - Access 토큰과 Refresh 토큰을 반환합니다. + * @returns {Error} 401 - 일치하는 에코 계정 정보가 존재하지 않습니다. + */ router.post('/login', [ check('username').isString().not().isEmpty(), check('password').isString().not().isEmpty() ], checkValidation, controllers.Login) +/** + * Refresh 토큰으로 새로운 Access 토큰과 Refresh 토큰을 발행합니다. + * @route POST /auth/refresh + * @group Auth - 인증 관련 메소드 + * @returns {object} 200 - Access 토큰과 Refresh 토큰을 반환합니다. + * @returns {Error} 401 - 토큰이 Refresh 용이 아니거나 인증에 실패했습니다. + * @security JWT - Refresh 토큰이 Bearer로 Authorization 헤더에 존재해야 합니다. + */ router.post('/refresh', controllers.Refresh) export default router From 27533d34af470c05ef265e221a7b04289792c935 Mon Sep 17 00:00:00 2001 From: uhmtoto Date: Wed, 16 Oct 2019 14:08:36 +0900 Subject: [PATCH 2/6] docs: add comment route information --- src/router/auth/index.js | 1 - src/router/comment/index.js | 29 +++++++++++++++++++++++++++++ swagger.json | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/router/auth/index.js b/src/router/auth/index.js index 88ddd14..9c25237 100644 --- a/src/router/auth/index.js +++ b/src/router/auth/index.js @@ -39,7 +39,6 @@ router.post('/login', [ * @group Auth - 인증 관련 메소드 * @returns {object} 200 - Access 토큰과 Refresh 토큰을 반환합니다. * @returns {Error} 401 - 토큰이 Refresh 용이 아니거나 인증에 실패했습니다. - * @security JWT - Refresh 토큰이 Bearer로 Authorization 헤더에 존재해야 합니다. */ router.post('/refresh', controllers.Refresh) diff --git a/src/router/comment/index.js b/src/router/comment/index.js index f9342cf..ddc79c3 100644 --- a/src/router/comment/index.js +++ b/src/router/comment/index.js @@ -11,15 +11,44 @@ const router = Router() router.get('/:userId', (req, res, next) => {}) +/** + * 새로운 댓글을 생성합니다 + * @route POST /comment + * @group Comment - 댓글 관련 메소드 + * @param {string} content.query.required - 댓글 내용 + * @param {objectId} target.query.required - 댓글 대상 (게시물 ObjectId) + * @returns {object} 200 - 생성한 댓글을 반환합니다. + * @returns {Error} 404 - 대상 게시물이 존재하지 않습니다. + */ router.post('/', [ check('content').isString().not().isEmpty(), check('target').custom(isObjectId) ], checkValidation, needAuthorization, controllers.CreateComment) +/** + * 댓글을 삭제합니다. + * @route DELETE /comment/:commentId + * @group Comment - 댓글 관련 메소드 + * @param {objectId} content.param - 댓글 ObjectId + * @returns {null} 204 - 댓글이 정상적으로 삭제되었습니다. + * @returns {Error} 403 - 권한이 없습니다. + * @returns {Error} 404 - 댓글이 존재하지 않습니다. + */ router.delete('/:commentId', [ check('commentId').custom(isObjectId) ], checkValidation, needAuthorization, controllers.DeleteComment) +/** + * 댓글을 수정합니다. + * @route PUT /comment/:commentId + * @group Comment - 댓글 관련 메소드 + * @param {objectId} content.param - 댓글 ObjectId + * @param {string} content.query.required - 댓글 내용 + * @param {objectId} target.query.required - 댓글 대상 (게시물 ObjectId) + * @returns {null} 200 - 수정된 댓글을 반환합니다. + * @returns {Error} 403 - 권한이 없습니다. + * @returns {Error} 404 - 댓글이 존재하지 않습니다. + */ router.put('/:commentId', [ check('commentId').custom(isObjectId), check('content').isString().not().isEmpty() diff --git a/swagger.json b/swagger.json index a04c029..448373e 100644 --- a/swagger.json +++ b/swagger.json @@ -9,7 +9,7 @@ "produces": [ "application/json" ], - "schemes": ["https"], + "schemes": ["http"], "securityDefinitions": { "JWT": { "type": "apiKey", From 4a06157d430b3019aff801609b23cb35be341013 Mon Sep 17 00:00:00 2001 From: uhmtoto Date: Wed, 16 Oct 2019 14:11:31 +0900 Subject: [PATCH 3/6] docs: add post route information --- src/router/post/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/router/post/index.js b/src/router/post/index.js index 15b7ccd..9bb458b 100644 --- a/src/router/post/index.js +++ b/src/router/post/index.js @@ -12,11 +12,28 @@ router.get('/brief', (req, res, next) => {}) router.get('/start/:startPage/end/:endPage', (req, res, next) => {}) +/** + * 새로운 게시물을 생성합니다 + * @route POST /post + * @group Post - 게시물 관련 메소드 + * @param {string} title.query.required - 게시물 제목 + * @param {string} content.query.required - 게시물 내용 + * @returns {object} 200 - 생성한 게시물을 반환합니다. + */ router.post('/', [ check('title').isString().not().isEmpty(), check('content').isString().not().isEmpty() ], checkValidation, needAuthorization, controllers.CreatePost) +/** + * 게시물을 삭제합니다. + * @route DELETE /post/:postId + * @group Post - 게시물 관련 메소드 + * @param {string} postId.query.required - 게시물 ObjectId + * @returns {object} 204 - 게시물이 정상적으로 삭제되었습니다. + * @returns {Error} 403 - 권한이 없습니다. + * @returns {Error} 404 - 댓글이 존재하지 않습니다. + */ router.delete('/:postId', needAuthorization, controllers.DeletePost) router.put('/:postId', (req, res, next) => {}) From f434103763d20e8e5aae550701719d590c23236f Mon Sep 17 00:00:00 2001 From: uhmtoto Date: Wed, 16 Oct 2019 14:21:07 +0900 Subject: [PATCH 4/6] docs: all routes --- src/router/auth/index.js | 5 +---- src/router/comment/index.js | 6 ------ src/router/post/index.js | 3 --- src/router/subscription/index.js | 16 ++++++++++++++++ src/router/tag/index.js | 20 ++++++++++++++++++++ 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/router/auth/index.js b/src/router/auth/index.js index 9c25237..89da3da 100644 --- a/src/router/auth/index.js +++ b/src/router/auth/index.js @@ -9,8 +9,6 @@ const router = Router() * 디미고 계정 정보를 받아 에코를 가입합니다. * @route POST /auth/join * @group Auth - 인증 관련 메소드 - * @param {string} username.query.required - 사용자 이름 - * @param {string} password.query.required - 사용자 비밀번호 * @returns {object} 200 - 사용자 정보 * @returns {Error} 401 - 일치하는 계정이 디미고 API에 존재하지 않습니다. */ @@ -23,10 +21,9 @@ router.post('/join', [ * 디미고 계정 정보를 받아 에코에서의 토큰을 발행합니다. * @route POST /auth/login * @group Auth - 인증 관련 메소드 - * @param {string} username.query.required - 사용자 이름 - * @param {string} password.query.required - 사용자 비밀번호 * @returns {object} 200 - Access 토큰과 Refresh 토큰을 반환합니다. * @returns {Error} 401 - 일치하는 에코 계정 정보가 존재하지 않습니다. + * @returns {Error} 409 - 이미 가입된 계정입니다. */ router.post('/login', [ check('username').isString().not().isEmpty(), diff --git a/src/router/comment/index.js b/src/router/comment/index.js index ddc79c3..06db53b 100644 --- a/src/router/comment/index.js +++ b/src/router/comment/index.js @@ -15,8 +15,6 @@ router.get('/:userId', (req, res, next) => {}) * 새로운 댓글을 생성합니다 * @route POST /comment * @group Comment - 댓글 관련 메소드 - * @param {string} content.query.required - 댓글 내용 - * @param {objectId} target.query.required - 댓글 대상 (게시물 ObjectId) * @returns {object} 200 - 생성한 댓글을 반환합니다. * @returns {Error} 404 - 대상 게시물이 존재하지 않습니다. */ @@ -29,7 +27,6 @@ router.post('/', [ * 댓글을 삭제합니다. * @route DELETE /comment/:commentId * @group Comment - 댓글 관련 메소드 - * @param {objectId} content.param - 댓글 ObjectId * @returns {null} 204 - 댓글이 정상적으로 삭제되었습니다. * @returns {Error} 403 - 권한이 없습니다. * @returns {Error} 404 - 댓글이 존재하지 않습니다. @@ -42,9 +39,6 @@ router.delete('/:commentId', [ * 댓글을 수정합니다. * @route PUT /comment/:commentId * @group Comment - 댓글 관련 메소드 - * @param {objectId} content.param - 댓글 ObjectId - * @param {string} content.query.required - 댓글 내용 - * @param {objectId} target.query.required - 댓글 대상 (게시물 ObjectId) * @returns {null} 200 - 수정된 댓글을 반환합니다. * @returns {Error} 403 - 권한이 없습니다. * @returns {Error} 404 - 댓글이 존재하지 않습니다. diff --git a/src/router/post/index.js b/src/router/post/index.js index 9bb458b..172222b 100644 --- a/src/router/post/index.js +++ b/src/router/post/index.js @@ -16,8 +16,6 @@ router.get('/start/:startPage/end/:endPage', (req, res, next) => {}) * 새로운 게시물을 생성합니다 * @route POST /post * @group Post - 게시물 관련 메소드 - * @param {string} title.query.required - 게시물 제목 - * @param {string} content.query.required - 게시물 내용 * @returns {object} 200 - 생성한 게시물을 반환합니다. */ router.post('/', [ @@ -29,7 +27,6 @@ router.post('/', [ * 게시물을 삭제합니다. * @route DELETE /post/:postId * @group Post - 게시물 관련 메소드 - * @param {string} postId.query.required - 게시물 ObjectId * @returns {object} 204 - 게시물이 정상적으로 삭제되었습니다. * @returns {Error} 403 - 권한이 없습니다. * @returns {Error} 404 - 댓글이 존재하지 않습니다. diff --git a/src/router/subscription/index.js b/src/router/subscription/index.js index 57df16c..7cdeccb 100644 --- a/src/router/subscription/index.js +++ b/src/router/subscription/index.js @@ -9,10 +9,26 @@ import { const router = Router() +/** + * 태그를 구독합니다 + * @route POST /subscription/:tagId + * @group Subscription - 구독 관련 메소드 + * @returns {object} - 생성한 구독 모델을 반환합니다. + * @returns {Error} 403 - 권한이 없습니다. + * @returns {Error} 404 - 태그가 존재하지 않습니다. + * @returns {Error} 409 - 이미 구독한 태그입니다. + */ router.post('/:tagId', [ check('tagId').custom(isObjectId) ], checkValidation, needAuthorization, controllers.CreateSubscription) +/** + * 태그의 구독을 취소합니다 + * @route DELETE /subscription/:tagId + * @group Subscription - 구독 관련 메소드 + * @returns {object} 204 - 구독이 정상적으로 취소되었습니다. + * @returns {Error} 404 - 구독하지 않은 태그입니다. + */ router.delete('/:subscriptionId', [ check('subscriptionId').custom(isObjectId) ], checkValidation, needAuthorization, controllers.CancelSubscription) diff --git a/src/router/tag/index.js b/src/router/tag/index.js index fadfdf1..9924507 100644 --- a/src/router/tag/index.js +++ b/src/router/tag/index.js @@ -8,14 +8,34 @@ import { const router = Router() +/** + * 자신이 볼 수 있는 태그를 모두 반환합니다. + * @route GET /tag + * @group Tag - 태그 관련 메소드 + * @returns {object} - 모든 태그를 반환합니다. + */ router.get('/', needAuthorization, controllers.GetAllTags) +/** + * 새로운 태그를 생성합니다. + * @route POST /tag + * @group Tag - 태그 관련 메소드 + * @returns {object} - 새로운 태그를 반환합니다. + */ router.post('/', [ check('name').isString().not().isEmpty(), check('description').isString().not().isEmpty(), check('joinOption').isIn(['P', 'R', 'O']) ], checkValidation, needAuthorization, controllers.CreateTag) +/** + * 태그를 삭제합니다. + * @route POST /tag + * @group Tag - 태그 관련 메소드 + * @returns {object} 204 - 태그를 정상적으로 삭제했습니다. + * @returns {Error} 403 - 권한이 없습니다. + * @returns {Error} 404 - 존재하지 않는 태그입니다. + */ router.delete('/:tagId', needAuthorization, controllers.DeleteTag) router.put('/:tagId', (req, res, next) => {}) From 7739a79c299b5986b1c1f36bc568ed2dbfaeb464 Mon Sep 17 00:00:00 2001 From: uhmtoto Date: Wed, 16 Oct 2019 14:22:11 +0900 Subject: [PATCH 5/6] fix(docs): method for delete tag --- src/router/tag/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/tag/index.js b/src/router/tag/index.js index 9924507..a07101d 100644 --- a/src/router/tag/index.js +++ b/src/router/tag/index.js @@ -30,7 +30,7 @@ router.post('/', [ /** * 태그를 삭제합니다. - * @route POST /tag + * @route DELETE /tag * @group Tag - 태그 관련 메소드 * @returns {object} 204 - 태그를 정상적으로 삭제했습니다. * @returns {Error} 403 - 권한이 없습니다. From bb02da2aa721dbdb6df6569bda653b01eb3f0e3c Mon Sep 17 00:00:00 2001 From: uhmtoto Date: Wed, 16 Oct 2019 14:23:44 +0900 Subject: [PATCH 6/6] docs: add https scheme --- swagger.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger.json b/swagger.json index 448373e..d39fb42 100644 --- a/swagger.json +++ b/swagger.json @@ -9,7 +9,7 @@ "produces": [ "application/json" ], - "schemes": ["http"], + "schemes": ["http", "https"], "securityDefinitions": { "JWT": { "type": "apiKey",