// src/routes/api-key.routes.js // API 키 라우트 const express = require('express'); const { body, param } = require('express-validator'); const apiKeyController = require('../controllers/api-key.controller'); const { authenticateJWT } = require('../middlewares/auth.middleware'); const { validateRequest } = require('../middlewares/validation.middleware'); const router = express.Router(); // 모든 라우트에 JWT 인증 적용 router.use(authenticateJWT); /** * POST /api/v1/api-keys * API 키 발급 */ router.post( '/', [ body('name') .trim() .isLength({ min: 1, max: 100 }) .withMessage('API 키 이름은 1-100자 사이여야 합니다'), body('expiresInDays') .optional() .isInt({ min: 1, max: 365 }) .withMessage('만료 기간은 1-365일 사이여야 합니다'), body('permissions') .optional() .isArray() .withMessage('권한은 배열이어야 합니다'), validateRequest, ], apiKeyController.create ); /** * GET /api/v1/api-keys * API 키 목록 조회 */ router.get('/', apiKeyController.list); /** * GET /api/v1/api-keys/:id * API 키 상세 조회 */ router.get( '/:id', [ param('id') .isUUID() .withMessage('유효한 API 키 ID가 아닙니다'), validateRequest, ], apiKeyController.get ); /** * PATCH /api/v1/api-keys/:id * API 키 수정 */ router.patch( '/:id', [ param('id') .isUUID() .withMessage('유효한 API 키 ID가 아닙니다'), body('name') .optional() .trim() .isLength({ min: 1, max: 100 }) .withMessage('API 키 이름은 1-100자 사이여야 합니다'), body('status') .optional() .isIn(['active', 'revoked']) .withMessage('상태는 active 또는 revoked여야 합니다'), validateRequest, ], apiKeyController.update ); /** * DELETE /api/v1/api-keys/:id * API 키 폐기 */ router.delete( '/:id', [ param('id') .isUUID() .withMessage('유효한 API 키 ID가 아닙니다'), validateRequest, ], apiKeyController.revoke ); module.exports = router;