Files
M-Project/backend/main.py
Hyungi Ahn 3cf485f3f2 feat: 수신함 워크플로우 백엔드 완전 구현
🔧 Models & Schemas:
- 새로운 ENUM 클래스 추가:
  * ReviewStatus: pending_review, in_progress, completed, disposed
  * DisposalReasonType: duplicate, invalid_report, not_applicable, spam, custom

- Issue 모델 확장 (8개 새 필드):
  * review_status: 수신함 워크플로우 상태 (기본값: pending_review)
  * disposal_reason: 폐기 사유 ENUM
  * custom_disposal_reason: 사용자 정의 폐기 사유
  * disposed_at: 폐기 처리 시간
  * reviewed_by_id: 검토자 FK (users.id)
  * reviewed_at: 검토 완료 시간
  * original_data: 원본 데이터 보존 (JSONB)
  * modification_log: 수정 이력 추적 (JSONB)

- User 모델 관계 수정:
  * issues: 신고한 부적합 (foreign_keys 명시)
  * reviewed_issues: 검토한 부적합 (새로 추가)

🎯 Pydantic Schemas:
- 기존 Issue 스키마에 워크플로우 필드 추가
- 수신함 전용 스키마들:
  * IssueDisposalRequest: 폐기 요청
  * IssueReviewRequest: 검토/수정 요청
  * IssueStatusUpdateRequest: 상태 변경 요청
  * InboxIssue: 수신함용 간소화 모델
  * ModificationLogEntry: 수정 이력 항목

🚀 API Endpoints (/api/inbox):
- GET /: 수신함 부적합 목록 (프로젝트 필터링, 페이징)
- POST /{id}/dispose: 부적합 폐기 처리 (관리자 전용)
- POST /{id}/review: 부적합 검토/수정 (관리자 전용)
- POST /{id}/status: 최종 상태 결정 (관리자 전용)
- GET /{id}/history: 수정 이력 조회
- GET /statistics: 수신함 통계

🔒 Security & Validation:
- 관리자 전용 액션 (폐기, 검토, 상태변경)
- 사용자 정의 폐기 사유 검증
- 프로젝트 존재 여부 확인
- 상태 변경 로직 검증

📊 Data Preservation:
- 원본 데이터 자동 보존 (최초 1회)
- 모든 수정사항 이력 추적
- 검토자 및 시간 기록
- 폐기 사유 및 시간 기록

🎯 Workflow Logic:
업로드(pending_review) → 수신함 검토 → [폐기→폐기함] or [승인→관리함]
- 폐기: disposed 상태, 폐기함으로
- 승인: in_progress/completed 상태, 관리함으로
- 모든 변경사항 추적 및 보존

Result:
 수신함 워크플로우 백엔드 100% 완성
 DB 스키마와 완벽 동기화
 데이터 무결성 및 추적성 보장
 RESTful API 설계 준수
 관리자 권한 기반 보안 적용
2025-10-25 12:08:14 +09:00

69 lines
1.9 KiB
Python

from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import uvicorn
from database.database import engine, get_db
from database.models import Base
from routers import auth, issues, daily_work, reports, projects, page_permissions, inbox
from services.auth_service import create_admin_user
# 데이터베이스 테이블 생성
# 메타데이터 캐시 클리어
Base.metadata.clear()
Base.metadata.create_all(bind=engine)
# FastAPI 앱 생성
app = FastAPI(
title="M-Project API",
description="작업보고서 시스템 API",
version="1.0.0"
)
# CORS 설정 (완전 개방 - CORS 문제 해결)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=False, # * origin과 credentials는 함께 사용 불가
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allow_headers=["*"],
expose_headers=["*"]
)
# 라우터 등록
app.include_router(auth.router)
app.include_router(issues.router)
app.include_router(inbox.router) # 수신함 라우터 추가
app.include_router(daily_work.router)
app.include_router(reports.router)
app.include_router(projects.router)
app.include_router(page_permissions.router)
# 시작 시 관리자 계정 생성
@app.on_event("startup")
async def startup_event():
db = next(get_db())
create_admin_user(db)
db.close()
# 루트 엔드포인트
@app.get("/")
async def root():
return {"message": "M-Project API", "version": "1.0.0"}
# 헬스체크
@app.get("/api/health")
async def health_check():
return {"status": "healthy"}
# 전역 예외 처리
@app.exception_handler(Exception)
async def global_exception_handler(request: Request, exc: Exception):
return JSONResponse(
status_code=500,
content={"detail": f"Internal server error: {str(exc)}"}
)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)