배송/화물현황과 리스크/알림(api 활용, 공공데이터 복구시 대체될 가능성 있음)
This commit is contained in:
116
backend-node/src/controllers/deliveryController.ts
Normal file
116
backend-node/src/controllers/deliveryController.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* 배송/화물 관리 컨트롤러
|
||||
*/
|
||||
|
||||
import { Request, Response } from 'express';
|
||||
import * as deliveryService from '../services/deliveryService';
|
||||
|
||||
/**
|
||||
* GET /api/delivery/status
|
||||
* 배송 현황 조회
|
||||
*/
|
||||
export async function getDeliveryStatus(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const data = await deliveryService.getDeliveryStatus();
|
||||
res.json({
|
||||
success: true,
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배송 현황 조회 실패:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '배송 현황 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/delivery/delayed
|
||||
* 지연 배송 목록 조회
|
||||
*/
|
||||
export async function getDelayedDeliveries(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const deliveries = await deliveryService.getDelayedDeliveries();
|
||||
res.json({
|
||||
success: true,
|
||||
data: deliveries,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('지연 배송 조회 실패:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '지연 배송 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/delivery/issues
|
||||
* 고객 이슈 목록 조회
|
||||
*/
|
||||
export async function getCustomerIssues(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { status } = req.query;
|
||||
const issues = await deliveryService.getCustomerIssues(status as string);
|
||||
res.json({
|
||||
success: true,
|
||||
data: issues,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('고객 이슈 조회 실패:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '고객 이슈 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /api/delivery/:id/status
|
||||
* 배송 상태 업데이트
|
||||
*/
|
||||
export async function updateDeliveryStatus(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { status, delayReason } = req.body;
|
||||
|
||||
await deliveryService.updateDeliveryStatus(id, status, delayReason);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: '배송 상태가 업데이트되었습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('배송 상태 업데이트 실패:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '배송 상태 업데이트에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /api/delivery/issues/:id/status
|
||||
* 고객 이슈 상태 업데이트
|
||||
*/
|
||||
export async function updateIssueStatus(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { status } = req.body;
|
||||
|
||||
await deliveryService.updateIssueStatus(id, status);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: '이슈 상태가 업데이트되었습니다.',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('이슈 상태 업데이트 실패:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '이슈 상태 업데이트에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
124
backend-node/src/controllers/riskAlertController.ts
Normal file
124
backend-node/src/controllers/riskAlertController.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* 리스크/알림 컨트롤러
|
||||
*/
|
||||
|
||||
import { Request, Response } from 'express';
|
||||
import { RiskAlertService } from '../services/riskAlertService';
|
||||
import { RiskAlertCacheService } from '../services/riskAlertCacheService';
|
||||
|
||||
const riskAlertService = new RiskAlertService();
|
||||
const cacheService = RiskAlertCacheService.getInstance();
|
||||
|
||||
export class RiskAlertController {
|
||||
/**
|
||||
* 전체 알림 조회 (캐시된 데이터 - 빠름!)
|
||||
* GET /api/risk-alerts
|
||||
*/
|
||||
async getAllAlerts(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const { alerts, lastUpdated } = cacheService.getCachedAlerts();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: alerts,
|
||||
count: alerts.length,
|
||||
lastUpdated: lastUpdated,
|
||||
cached: true,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ 전체 알림 조회 오류:', error.message);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '알림 조회 중 오류가 발생했습니다.',
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 전체 알림 강제 갱신 (실시간 조회)
|
||||
* POST /api/risk-alerts/refresh
|
||||
*/
|
||||
async refreshAlerts(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const alerts = await cacheService.forceRefresh();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: alerts,
|
||||
count: alerts.length,
|
||||
message: '알림이 갱신되었습니다.',
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ 알림 갱신 오류:', error.message);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '알림 갱신 중 오류가 발생했습니다.',
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 날씨 특보 조회
|
||||
* GET /api/risk-alerts/weather
|
||||
*/
|
||||
async getWeatherAlerts(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const alerts = await riskAlertService.getWeatherAlerts();
|
||||
|
||||
// 프론트엔드 직접 호출용: alerts 배열만 반환
|
||||
res.json(alerts);
|
||||
} catch (error: any) {
|
||||
console.error('❌ 날씨 특보 조회 오류:', error.message);
|
||||
res.status(500).json([]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 교통사고 조회
|
||||
* GET /api/risk-alerts/accidents
|
||||
*/
|
||||
async getAccidentAlerts(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const alerts = await riskAlertService.getAccidentAlerts();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: alerts,
|
||||
count: alerts.length,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ 교통사고 조회 오류:', error.message);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '교통사고 조회 중 오류가 발생했습니다.',
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 도로공사 조회
|
||||
* GET /api/risk-alerts/roadworks
|
||||
*/
|
||||
async getRoadworkAlerts(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const alerts = await riskAlertService.getRoadworkAlerts();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: alerts,
|
||||
count: alerts.length,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('❌ 도로공사 조회 오류:', error.message);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: '도로공사 조회 중 오류가 발생했습니다.',
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user