Files
TK-FB-Project/api.hyungi.net/routes/workplaceRoutes.js
Hyungi Ahn e1227a69fe feat: 설비 관리 시스템 구축
## 주요 기능
- 설비 등록/수정/삭제 기능
- 작업장별 설비 연결
- 작업장 지도에서 설비 위치 정의
- 필터링 및 검색 기능

## 백엔드
- equipments 테이블 생성 (마이그레이션)
- 설비 API (모델, 컨트롤러, 라우트) 구현
- workplaces 테이블에 layout_image 컬럼 추가

## 프론트엔드
- 설비 관리 페이지 (equipments.html)
- 설비 관리 JavaScript (equipment-management.js)
- 작업장 지도 모달 개선

## 버그 수정
- 카테고리/작업장 이미지 보존 로직 개선 (null 처리)
- 작업장 레이아웃 이미지 업로드 경로 수정 (public/uploads → uploads)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-28 09:22:57 +09:00

98 lines
3.3 KiB
JavaScript

// routes/workplaceRoutes.js
const express = require('express');
const router = express.Router();
const multer = require('multer');
const path = require('path');
const workplaceController = require('../controllers/workplaceController');
// Multer 설정 - 작업장 레이아웃 이미지 업로드
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, path.join(__dirname, '../uploads'));
},
filename: (req, file, cb) => {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
cb(null, 'workplace-layout-' + uniqueSuffix + path.extname(file.originalname));
}
});
const upload = multer({
storage,
fileFilter: (req, file, cb) => {
const allowedTypes = /jpeg|jpg|png|gif/;
const extname = allowedTypes.test(path.extname(file.originalname).toLowerCase());
const mimetype = allowedTypes.test(file.mimetype);
if (mimetype && extname) {
return cb(null, true);
} else {
cb(new Error('이미지 파일만 업로드 가능합니다 (jpeg, jpg, png, gif)'));
}
},
limits: { fileSize: 5 * 1024 * 1024 } // 5MB 제한
});
// ==================== 카테고리(공장) 관리 ====================
// CREATE 카테고리
router.post('/categories', workplaceController.createCategory);
// READ ALL 카테고리
router.get('/categories', workplaceController.getAllCategories);
// READ ACTIVE 카테고리
router.get('/categories/active/list', workplaceController.getActiveCategories);
// READ ONE 카테고리
router.get('/categories/:id', workplaceController.getCategoryById);
// UPDATE 카테고리
router.put('/categories/:id', workplaceController.updateCategory);
// DELETE 카테고리
router.delete('/categories/:id', workplaceController.deleteCategory);
// ==================== 작업장 관리 ====================
// CREATE 작업장
router.post('/', workplaceController.createWorkplace);
// READ ALL 작업장 (쿼리 파라미터로 카테고리 필터링 가능: ?category_id=1)
router.get('/', workplaceController.getAllWorkplaces);
// READ ACTIVE 작업장
router.get('/active/list', workplaceController.getActiveWorkplaces);
// READ ONE 작업장
router.get('/:id', workplaceController.getWorkplaceById);
// UPDATE 작업장
router.put('/:id', workplaceController.updateWorkplace);
// DELETE 작업장
router.delete('/:id', workplaceController.deleteWorkplace);
// ==================== 작업장 지도 영역 관리 ====================
// 카테고리 레이아웃 이미지 업로드
router.post('/categories/:id/layout-image', upload.single('image'), workplaceController.uploadCategoryLayoutImage);
// 작업장 레이아웃 이미지 업로드
router.post('/:id/layout-image', upload.single('image'), workplaceController.uploadWorkplaceLayoutImage);
// CREATE 지도 영역
router.post('/map-regions', workplaceController.createMapRegion);
// READ 카테고리별 지도 영역
router.get('/categories/:categoryId/map-regions', workplaceController.getMapRegionsByCategory);
// READ 작업장별 지도 영역
router.get('/map-regions/workplace/:workplaceId', workplaceController.getMapRegionByWorkplace);
// UPDATE 지도 영역
router.put('/map-regions/:id', workplaceController.updateMapRegion);
// DELETE 지도 영역
router.delete('/map-regions/:id', workplaceController.deleteMapRegion);
module.exports = router;