82 lines
1.8 KiB
JavaScript
82 lines
1.8 KiB
JavaScript
|
|
// src/routes/usage.routes.js
|
||
|
|
// 사용량 라우트
|
||
|
|
|
||
|
|
const express = require('express');
|
||
|
|
const { query } = require('express-validator');
|
||
|
|
const usageController = require('../controllers/usage.controller');
|
||
|
|
const { authenticateJWT } = require('../middlewares/auth.middleware');
|
||
|
|
const { validateRequest } = require('../middlewares/validation.middleware');
|
||
|
|
|
||
|
|
const router = express.Router();
|
||
|
|
|
||
|
|
// 모든 라우트에 JWT 인증 적용
|
||
|
|
router.use(authenticateJWT);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* GET /api/v1/usage
|
||
|
|
* 사용량 요약 조회
|
||
|
|
*/
|
||
|
|
router.get('/', usageController.getSummary);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* GET /api/v1/usage/daily
|
||
|
|
* 일별 사용량 조회
|
||
|
|
*/
|
||
|
|
router.get(
|
||
|
|
'/daily',
|
||
|
|
[
|
||
|
|
query('startDate')
|
||
|
|
.optional()
|
||
|
|
.isISO8601()
|
||
|
|
.withMessage('시작 날짜는 ISO 8601 형식이어야 합니다'),
|
||
|
|
query('endDate')
|
||
|
|
.optional()
|
||
|
|
.isISO8601()
|
||
|
|
.withMessage('종료 날짜는 ISO 8601 형식이어야 합니다'),
|
||
|
|
validateRequest,
|
||
|
|
],
|
||
|
|
usageController.getDailyUsage
|
||
|
|
);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* GET /api/v1/usage/monthly
|
||
|
|
* 월별 사용량 조회
|
||
|
|
*/
|
||
|
|
router.get(
|
||
|
|
'/monthly',
|
||
|
|
[
|
||
|
|
query('year')
|
||
|
|
.optional()
|
||
|
|
.isInt({ min: 2020, max: 2100 })
|
||
|
|
.withMessage('연도는 2020-2100 사이여야 합니다'),
|
||
|
|
query('month')
|
||
|
|
.optional()
|
||
|
|
.isInt({ min: 1, max: 12 })
|
||
|
|
.withMessage('월은 1-12 사이여야 합니다'),
|
||
|
|
validateRequest,
|
||
|
|
],
|
||
|
|
usageController.getMonthlyUsage
|
||
|
|
);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* GET /api/v1/usage/logs
|
||
|
|
* 사용량 로그 목록 조회
|
||
|
|
*/
|
||
|
|
router.get(
|
||
|
|
'/logs',
|
||
|
|
[
|
||
|
|
query('page')
|
||
|
|
.optional()
|
||
|
|
.isInt({ min: 1 })
|
||
|
|
.withMessage('페이지는 1 이상이어야 합니다'),
|
||
|
|
query('limit')
|
||
|
|
.optional()
|
||
|
|
.isInt({ min: 1, max: 100 })
|
||
|
|
.withMessage('한도는 1-100 사이여야 합니다'),
|
||
|
|
validateRequest,
|
||
|
|
],
|
||
|
|
usageController.getLogs
|
||
|
|
);
|
||
|
|
|
||
|
|
module.exports = router;
|