diff --git a/backend/app/routers/dashboard.py b/backend/app/routers/dashboard.py index 4a4abb8..1af2731 100644 --- a/backend/app/routers/dashboard.py +++ b/backend/app/routers/dashboard.py @@ -425,3 +425,73 @@ async def get_quick_actions( except Exception as e: logger.error(f"Quick actions error: {str(e)}") raise HTTPException(status_code=500, detail=f"빠른 작업 조회 실패: {str(e)}") + + +@router.patch("/projects/{project_id}") +async def update_project_name( + project_id: int, + job_name: str = Query(..., description="새 프로젝트 이름"), + current_user: dict = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + 프로젝트 이름 수정 + + Args: + project_id: 프로젝트 ID + job_name: 새 프로젝트 이름 + + Returns: + dict: 수정 결과 + """ + try: + # 프로젝트 존재 확인 + query = text("SELECT * FROM projects WHERE id = :project_id") + result = db.execute(query, {"project_id": project_id}).fetchone() + + if not result: + raise HTTPException(status_code=404, detail="프로젝트를 찾을 수 없습니다") + + # 프로젝트 이름 업데이트 + update_query = text(""" + UPDATE projects + SET job_name = :job_name, + updated_at = CURRENT_TIMESTAMP + WHERE id = :project_id + RETURNING * + """) + + updated = db.execute(update_query, { + "job_name": job_name, + "project_id": project_id + }).fetchone() + + db.commit() + + # 활동 로그 기록 + ActivityLogger.log_activity( + db=db, + user_id=current_user.get('user_id'), + action="UPDATE_PROJECT", + target_type="PROJECT", + target_id=project_id, + details=f"프로젝트 이름 변경: {job_name}" + ) + + return { + "success": True, + "message": "프로젝트 이름이 수정되었습니다", + "project": { + "id": updated.id, + "job_no": updated.job_no, + "job_name": updated.job_name, + "official_project_code": updated.official_project_code + } + } + + except HTTPException: + raise + except Exception as e: + db.rollback() + logger.error(f"프로젝트 수정 실패: {str(e)}") + raise HTTPException(status_code=500, detail=f"프로젝트 수정 실패: {str(e)}") diff --git a/frontend/src/pages/ProjectsPage.jsx b/frontend/src/pages/ProjectsPage.jsx index fdbc366..eadb59b 100644 --- a/frontend/src/pages/ProjectsPage.jsx +++ b/frontend/src/pages/ProjectsPage.jsx @@ -4,6 +4,39 @@ const ProjectsPage = ({ user }) => { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); const [showCreateForm, setShowCreateForm] = useState(false); + const [editingProject, setEditingProject] = useState(null); + const [editedName, setEditedName] = useState(''); + + // 프로젝트 이름 편집 시작 + const startEditing = (project) => { + setEditingProject(project.id); + setEditedName(project.name); + }; + + // 프로젝트 이름 저장 + const saveProjectName = async (projectId) => { + try { + // TODO: API 호출하여 프로젝트 이름 업데이트 + // await api.patch(`/dashboard/projects/${projectId}?job_name=${encodeURIComponent(editedName)}`); + + // 임시: 로컬 상태만 업데이트 + setProjects(projects.map(p => + p.id === projectId ? { ...p, name: editedName } : p + )); + + setEditingProject(null); + setEditedName(''); + } catch (error) { + console.error('프로젝트 이름 수정 실패:', error); + alert('프로젝트 이름 수정에 실패했습니다.'); + } + }; + + // 편집 취소 + const cancelEditing = () => { + setEditingProject(null); + setEditedName(''); + }; useEffect(() => { // 실제로는 API에서 프로젝트 데이터를 가져올 예정 @@ -224,8 +257,62 @@ const ProjectsPage = ({ user }) => { }} onMouseEnter={(e) => e.currentTarget.style.background = '#f7fafc'} onMouseLeave={(e) => e.currentTarget.style.background = 'transparent'}> -