- Swagger 패키지 설치 및 설정: * swagger-jsdoc, swagger-ui-express 패키지 추가 * /api-docs 엔드포인트에서 Swagger UI 제공 * /api-docs.json 엔드포인트에서 JSON 스펙 제공 - 포괄적인 Swagger 설정 파일 생성: * config/swagger.js: OpenAPI 3.0 스펙 정의 * 공통 스키마 정의 (User, Worker, Project, Task, DailyWorkReport) * 표준 응답 스키마 (SuccessResponse, ErrorResponse, PaginatedResponse) * JWT Bearer 인증 스키마 설정 - API 문서화 적용: * Authentication API: 로그인 엔드포인트 문서화 * Workers API: 전체 CRUD 작업 문서화 * 상세한 요청/응답 스키마 및 예시 포함 * 에러 코드별 응답 정의 - Swagger UI 커스터마이징: * 브랜딩 및 UI 개선 * 인증 토큰 지속성 설정 * 필터링 및 탐색 기능 활성화 - 접근 방법: * http://localhost:20005/api-docs - Swagger UI * http://localhost:20005/api-docs.json - JSON 스펙
228 lines
6.5 KiB
JavaScript
228 lines
6.5 KiB
JavaScript
/**
|
|
* @swagger
|
|
* tags:
|
|
* name: Workers
|
|
* description: 작업자 관리 API
|
|
*/
|
|
|
|
const express = require('express');
|
|
const router = express.Router();
|
|
const workerController = require('../controllers/workerController');
|
|
|
|
/**
|
|
* @swagger
|
|
* /api/workers:
|
|
* post:
|
|
* tags: [Workers]
|
|
* summary: 작업자 생성
|
|
* description: 새로운 작업자를 생성합니다.
|
|
* security:
|
|
* - bearerAuth: []
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* required:
|
|
* - worker_name
|
|
* properties:
|
|
* worker_name:
|
|
* type: string
|
|
* example: "김철수"
|
|
* position:
|
|
* type: string
|
|
* example: "용접공"
|
|
* department:
|
|
* type: string
|
|
* example: "생산부"
|
|
* phone:
|
|
* type: string
|
|
* example: "010-1234-5678"
|
|
* email:
|
|
* type: string
|
|
* format: email
|
|
* example: "worker@technicalkorea.com"
|
|
* responses:
|
|
* 201:
|
|
* description: 작업자 생성 성공
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/SuccessResponse'
|
|
* 400:
|
|
* description: 잘못된 요청
|
|
* 401:
|
|
* description: 인증 필요
|
|
* 500:
|
|
* description: 서버 오류
|
|
* get:
|
|
* tags: [Workers]
|
|
* summary: 전체 작업자 조회
|
|
* description: 모든 작업자 목록을 조회합니다.
|
|
* security:
|
|
* - bearerAuth: []
|
|
* responses:
|
|
* 200:
|
|
* description: 작업자 목록 조회 성공
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* success:
|
|
* type: boolean
|
|
* example: true
|
|
* message:
|
|
* type: string
|
|
* example: "작업자 목록 조회 성공"
|
|
* data:
|
|
* type: array
|
|
* items:
|
|
* $ref: '#/components/schemas/Worker'
|
|
* meta:
|
|
* type: object
|
|
* properties:
|
|
* count:
|
|
* type: integer
|
|
* example: 10
|
|
* 401:
|
|
* description: 인증 필요
|
|
* 500:
|
|
* description: 서버 오류
|
|
*/
|
|
router.post('/', workerController.createWorker);
|
|
router.get('/', workerController.getAllWorkers);
|
|
|
|
/**
|
|
* @swagger
|
|
* /api/workers/{worker_id}:
|
|
* get:
|
|
* tags: [Workers]
|
|
* summary: 특정 작업자 조회
|
|
* description: ID로 특정 작업자 정보를 조회합니다.
|
|
* security:
|
|
* - bearerAuth: []
|
|
* parameters:
|
|
* - in: path
|
|
* name: worker_id
|
|
* required: true
|
|
* schema:
|
|
* type: integer
|
|
* description: 작업자 ID
|
|
* responses:
|
|
* 200:
|
|
* description: 작업자 조회 성공
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* success:
|
|
* type: boolean
|
|
* example: true
|
|
* message:
|
|
* type: string
|
|
* example: "작업자 조회 성공"
|
|
* data:
|
|
* $ref: '#/components/schemas/Worker'
|
|
* 400:
|
|
* description: 잘못된 작업자 ID
|
|
* 401:
|
|
* description: 인증 필요
|
|
* 404:
|
|
* description: 작업자를 찾을 수 없음
|
|
* 500:
|
|
* description: 서버 오류
|
|
* put:
|
|
* tags: [Workers]
|
|
* summary: 작업자 정보 수정
|
|
* description: 작업자 정보를 수정합니다.
|
|
* security:
|
|
* - bearerAuth: []
|
|
* parameters:
|
|
* - in: path
|
|
* name: worker_id
|
|
* required: true
|
|
* schema:
|
|
* type: integer
|
|
* description: 작업자 ID
|
|
* requestBody:
|
|
* required: true
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* worker_name:
|
|
* type: string
|
|
* example: "김철수"
|
|
* position:
|
|
* type: string
|
|
* example: "용접공"
|
|
* department:
|
|
* type: string
|
|
* example: "생산부"
|
|
* phone:
|
|
* type: string
|
|
* example: "010-1234-5678"
|
|
* email:
|
|
* type: string
|
|
* format: email
|
|
* example: "worker@technicalkorea.com"
|
|
* responses:
|
|
* 200:
|
|
* description: 작업자 수정 성공
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* $ref: '#/components/schemas/SuccessResponse'
|
|
* 400:
|
|
* description: 잘못된 요청
|
|
* 401:
|
|
* description: 인증 필요
|
|
* 404:
|
|
* description: 작업자를 찾을 수 없음
|
|
* 500:
|
|
* description: 서버 오류
|
|
* delete:
|
|
* tags: [Workers]
|
|
* summary: 작업자 삭제
|
|
* description: 작업자를 삭제합니다.
|
|
* security:
|
|
* - bearerAuth: []
|
|
* parameters:
|
|
* - in: path
|
|
* name: worker_id
|
|
* required: true
|
|
* schema:
|
|
* type: integer
|
|
* description: 작업자 ID
|
|
* responses:
|
|
* 200:
|
|
* description: 작업자 삭제 성공
|
|
* content:
|
|
* application/json:
|
|
* schema:
|
|
* type: object
|
|
* properties:
|
|
* success:
|
|
* type: boolean
|
|
* example: true
|
|
* message:
|
|
* type: string
|
|
* example: "작업자가 성공적으로 삭제되었습니다."
|
|
* 400:
|
|
* description: 잘못된 작업자 ID
|
|
* 401:
|
|
* description: 인증 필요
|
|
* 404:
|
|
* description: 작업자를 찾을 수 없음
|
|
* 500:
|
|
* description: 서버 오류
|
|
*/
|
|
router.get('/:worker_id', workerController.getWorkerById);
|
|
router.put('/:worker_id', workerController.updateWorker);
|
|
router.delete('/:worker_id', workerController.removeWorker);
|
|
|
|
module.exports = router; |