- 목록 관리 페이지에 고급 필터링 시스템 추가 - 프로젝트별, 검토상태별, 날짜별 필터링 - 검토 완료/필요 항목 시각적 구분 및 정렬 - 해결 시간 입력 + 확인 버튼으로 검토 완료 처리 - 부적합 조회 페이지에 동일한 필터링 기능 적용 - 검토 상태에 따른 카드 스타일링 (음영 처리) - JavaScript 템플릿 리터럴 오류 수정 - 보고서 페이지 프로젝트별 분석 기능 추가 - 프로젝트 선택 드롭다운 추가 - 총 작업 공수를 프로젝트별 일일공수 데이터로 계산 - 부적합 처리 시간, 카테고리 분석, 상세 목록 모두 프로젝트별 필터링 - localStorage 키 이름 통일 (daily-work-data)
127 lines
3.8 KiB
Python
127 lines
3.8 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
from database.database import get_db
|
|
from database.models import Project, User, UserRole
|
|
from database.schemas import ProjectCreate, ProjectUpdate, Project as ProjectSchema
|
|
from routers.auth import get_current_user
|
|
|
|
router = APIRouter(
|
|
prefix="/api/projects",
|
|
tags=["projects"]
|
|
)
|
|
|
|
def check_admin_permission(current_user: User = Depends(get_current_user)):
|
|
"""관리자 권한 확인"""
|
|
if current_user.role != UserRole.admin:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_403_FORBIDDEN,
|
|
detail="관리자 권한이 필요합니다."
|
|
)
|
|
return current_user
|
|
|
|
@router.post("/", response_model=ProjectSchema)
|
|
async def create_project(
|
|
project: ProjectCreate,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(check_admin_permission)
|
|
):
|
|
"""프로젝트 생성 (관리자만)"""
|
|
# Job No. 중복 확인
|
|
existing_project = db.query(Project).filter(Project.job_no == project.job_no).first()
|
|
if existing_project:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
detail="이미 존재하는 Job No.입니다."
|
|
)
|
|
|
|
# 프로젝트 생성
|
|
db_project = Project(
|
|
job_no=project.job_no,
|
|
project_name=project.project_name,
|
|
created_by_id=current_user.id
|
|
)
|
|
|
|
db.add(db_project)
|
|
db.commit()
|
|
db.refresh(db_project)
|
|
|
|
return db_project
|
|
|
|
@router.get("/", response_model=List[ProjectSchema])
|
|
async def get_projects(
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
active_only: bool = True,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""프로젝트 목록 조회"""
|
|
query = db.query(Project)
|
|
|
|
if active_only:
|
|
query = query.filter(Project.is_active == True)
|
|
|
|
projects = query.offset(skip).limit(limit).all()
|
|
return projects
|
|
|
|
@router.get("/{project_id}", response_model=ProjectSchema)
|
|
async def get_project(
|
|
project_id: int,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user)
|
|
):
|
|
"""특정 프로젝트 조회"""
|
|
project = db.query(Project).filter(Project.id == project_id).first()
|
|
if not project:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="프로젝트를 찾을 수 없습니다."
|
|
)
|
|
return project
|
|
|
|
@router.put("/{project_id}", response_model=ProjectSchema)
|
|
async def update_project(
|
|
project_id: int,
|
|
project_update: ProjectUpdate,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(check_admin_permission)
|
|
):
|
|
"""프로젝트 수정 (관리자만)"""
|
|
project = db.query(Project).filter(Project.id == project_id).first()
|
|
if not project:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="프로젝트를 찾을 수 없습니다."
|
|
)
|
|
|
|
# 업데이트할 필드만 수정
|
|
update_data = project_update.dict(exclude_unset=True)
|
|
for field, value in update_data.items():
|
|
setattr(project, field, value)
|
|
|
|
db.commit()
|
|
db.refresh(project)
|
|
|
|
return project
|
|
|
|
@router.delete("/{project_id}")
|
|
async def delete_project(
|
|
project_id: int,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(check_admin_permission)
|
|
):
|
|
"""프로젝트 삭제 (비활성화) (관리자만)"""
|
|
project = db.query(Project).filter(Project.id == project_id).first()
|
|
if not project:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="프로젝트를 찾을 수 없습니다."
|
|
)
|
|
|
|
# 실제 삭제 대신 비활성화
|
|
project.is_active = False
|
|
db.commit()
|
|
|
|
return {"message": "프로젝트가 삭제되었습니다."}
|