Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/swagger #67

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
356 changes: 353 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pm2": "^5.3.1",
"redis": "^4.6.15"
"redis": "^4.6.15",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
},
"devDependencies": {
"eslint": "^8.57.0",
Expand Down
2 changes: 2 additions & 0 deletions src/common/modules/express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const conf = require('../../config');
const passportConfig = require('../../passport');
const router = require('../../../routes/index');
const { commonLimiter } = require('../../utils/rateLimit');
const { swaggerUi, specs } = require('../../../swagger/swagger');

module.exports = expressLoader = (app) => {
passportConfig();
Expand Down Expand Up @@ -97,6 +98,7 @@ module.exports = expressLoader = (app) => {
// Router 설정
app.use(commonLimiter);
app.use(router);
app.use('/docs', swaggerUi.serve, swaggerUi.setup(specs, { explorer: true }));

app.all('*', (req, res) => {
res.status(404).json(`Can't find ${req.originalUrl} on this server`);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/user/user.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ userRouter.get('/profile', isLoggedIn, getProfile);

// 최근 검색어
userRouter.get('/recent', isLoggedIn, recentSearches); // 최근 검색어 조회
userRouter.delete('/:searchTerm', isLoggedIn, delRecentSearch); // 최근 검색어 삭제
userRouter.delete('recent/:searchTerm', isLoggedIn, delRecentSearch); // 최근 검색어 삭제

//등록 요청
userRouter.post('/requests/:nickname/new', isLoggedIn, postWords);
userRouter.post('/requests/new', isLoggedIn, postWords);

// 요청 조회
userRouter.get('/requests', isLoggedIn, UserRequests); // 요청 목록 조회
Expand Down
55 changes: 55 additions & 0 deletions src/swagger/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @swagger
* tags:
* - name: 관리자 API
*/

/**
* @swagger
* /users/requests/all:
* get:
* summary: 전체 요청 목록 조회
* tags: [관리자 API]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: All user requests retrieved successfully
* 500:
* description: Internal server error
*/

/**
* @swagger
* /users/requests/{requestId}/status:
* post:
* summary: 개발 용어 요청 승인/반려 상태 변경
* tags: [관리자 API]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: requestId
* schema:
* type: string
* required: true
* description: Request ID to update status
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* formData:
* type: object
* requestType:
* type: string
* responses:
* 200:
* description: Request status updated successfully
* 500:
* description: Internal server error
*/
212 changes: 212 additions & 0 deletions src/swagger/request.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/**
* @swagger
* tags:
* - name: 개발 용어 API
*/

/**
* @swagger
* /words:
* get:
* summary: 전체 용어 조회
* tags:
* - 개발 용어 API
* parameters:
* - in: query
* name: limit
* schema:
* type: integer
* description: Number of words to return
* - in: query
* name: page
* schema:
* type: integer
* description: Page number
* - in: query
* name: sort
* schema:
* type: string
* enum: [asc, desc, popularity, recent]
* description: Sort order
* responses:
* 200:
* description: A list of words
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: GET_WORDS_SUCCESS
* data:
* type: array
* items:
* type: object
* properties:
* word:
* type: string
* example: exampleWord
* 400:
* description: Bad request
* 500:
* description: Internal server error
*/

/**
* @swagger
* /users/requests/new:
* post:
* summary: 개발 용어 등록/수정 요청
* tags: [개발 용어 API]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: nickname
* schema:
* type: string
* required: true
* description: Nickname for the new word request
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* formData:
* type: object
* properties:
* devTerm:
* type: string
* addInfo:
* type: string
* awkPron:
* type: string
* comPron:
* type: string
* type:
* type: string
* nickname:
* type: string
* responses:
* 200:
* description: New word request added successfully
* 500:
* description: Internal server error
*/

/**
* @swagger
* /words/checkDuplicateWord:
* post:
* summary: 개발 용어 중복 검사
* tags: [개발 용어 API]
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* word:
* type: string
* example: exampleWord
* responses:
* 200:
* description: Duplicate check result
* content:
* application/json:
* schema:
* type: object
* properties:
* message:
* type: string
* example: CHECK_DUPLICATE_REQUEST_SUCCESS
* data:
* type: object
* properties:
* isDataExist:
* type: boolean
* example: true
* 500:
* description: Internal server error
*/

/**
* @swagger
* /users/requests:
* get:
* summary: 내 요청 목록 조회
* tags: [개발 용어 API]
* security:
* - bearerAuth: []
* responses:
* 200:
* description: User requests retrieved successfully
* 500:
* description: Internal server error
*/

/**
* @swagger
* /users/requests/{requestId}:
* post:
* summary: 개발 용어 요청 수정
* tags: [개발 용어 API]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: requestId
* schema:
* type: string
* required: true
* description: Request ID to update
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* formData:
* type: object
* properties:
* devTerm:
* type: string
* addInfo:
* type: string
* awkPron:
* type: string
* comPron:
* type: string
* responses:
* 200:
* description: User request updated successfully
* 500:
* description: Internal server error
*/

/**
* @swagger
* /users/requests/{word}:
* delete:
* summary: 개발 용어 요청 삭제
* tags: [개발 용어 API]
* security:
* - bearerAuth: []
* parameters:
* - in: path
* name: word
* schema:
* type: string
* required: true
* description: Word to delete
* responses:
* 200:
* description: User request deleted successfully
* 500:
* description: Internal server error
*/
Loading