From 5fe51ab1d587fc7f76a72aa060eb8971f088609c Mon Sep 17 00:00:00 2001 From: hyungi Date: Fri, 24 Oct 2025 12:24:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20localStorage=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20=EB=B0=8F=20=EC=8B=9C=EC=8A=A4=ED=85=9C=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - localStorage와 DB ID 불일치 문제 해결 - 프로젝트별 보고서 시간 필터링 수정 - 일반 사용자에게 일일공수 메뉴 숨김 - 공통 헤더 및 인증 시스템 구현 - 프로젝트별 일일공수 분리 기능 추가 (ProjectDailyWork 모델) - IssuesAPI에서 project_id 누락 문제 수정 - 사용자 인증 통합 (TokenManager 기반) --- backend/database/models.py | 14 ++ backend/database/schemas.py | 20 +- .../009_add_project_daily_works_table.sql | 25 +++ backend/routers/issues.py | 3 + frontend/index.html | 182 +++++++++++------- frontend/issue-view.html | 26 +-- frontend/static/js/api.js | 1 + frontend/static/js/auth-common.js | 68 +++++++ frontend/static/js/common-header.js | 106 ++++++++++ 9 files changed, 358 insertions(+), 87 deletions(-) create mode 100644 backend/migrations/009_add_project_daily_works_table.sql create mode 100644 frontend/static/js/auth-common.js create mode 100644 frontend/static/js/common-header.js diff --git a/backend/database/models.py b/backend/database/models.py index c1a17a7..1ab0eba 100644 --- a/backend/database/models.py +++ b/backend/database/models.py @@ -93,3 +93,17 @@ class DailyWork(Base): # Relationships created_by = relationship("User", back_populates="daily_works") + +class ProjectDailyWork(Base): + __tablename__ = "project_daily_works" + + id = Column(Integer, primary_key=True, index=True) + date = Column(DateTime, nullable=False, index=True) + project_id = Column(BigInteger, ForeignKey("projects.id"), nullable=False) + hours = Column(Float, nullable=False) + created_by_id = Column(Integer, ForeignKey("users.id")) + created_at = Column(DateTime, default=get_kst_now) + + # Relationships + project = relationship("Project") + created_by = relationship("User") diff --git a/backend/database/schemas.py b/backend/database/schemas.py index a26dad7..8b08e80 100644 --- a/backend/database/schemas.py +++ b/backend/database/schemas.py @@ -62,7 +62,7 @@ class LoginRequest(BaseModel): class IssueBase(BaseModel): category: IssueCategory description: str - project_id: Optional[int] = None + project_id: int class IssueCreate(IssueBase): photo: Optional[str] = None # Base64 encoded image @@ -162,3 +162,21 @@ class ReportSummary(BaseModel): category_stats: CategoryStats completed_issues: int average_resolution_time: float + +# Project Daily Work schemas +class ProjectDailyWorkBase(BaseModel): + date: datetime + project_id: int + hours: float + +class ProjectDailyWorkCreate(ProjectDailyWorkBase): + pass + +class ProjectDailyWork(ProjectDailyWorkBase): + id: int + created_by_id: int + created_at: datetime + project: Project + + class Config: + from_attributes = True diff --git a/backend/migrations/009_add_project_daily_works_table.sql b/backend/migrations/009_add_project_daily_works_table.sql new file mode 100644 index 0000000..3a479d9 --- /dev/null +++ b/backend/migrations/009_add_project_daily_works_table.sql @@ -0,0 +1,25 @@ +-- 프로젝트별 일일공수 테이블 생성 +CREATE TABLE project_daily_works ( + id SERIAL PRIMARY KEY, + date DATE NOT NULL, + project_id BIGINT NOT NULL REFERENCES projects(id) ON DELETE CASCADE, + hours FLOAT NOT NULL, + created_by_id INTEGER NOT NULL REFERENCES users(id), + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP +); + +-- 인덱스 생성 +CREATE INDEX idx_project_daily_works_date ON project_daily_works(date); +CREATE INDEX idx_project_daily_works_project_id ON project_daily_works(project_id); +CREATE INDEX idx_project_daily_works_date_project ON project_daily_works(date, project_id); + +-- 기존 일일공수 데이터를 프로젝트별로 마이그레이션 (M Project로) +INSERT INTO project_daily_works (date, project_id, hours, created_by_id, created_at) +SELECT + date::date, + 1, -- M Project ID + total_hours, + created_by_id, + created_at +FROM daily_works +WHERE total_hours > 0; diff --git a/backend/routers/issues.py b/backend/routers/issues.py index e3feaa6..c07e4b8 100644 --- a/backend/routers/issues.py +++ b/backend/routers/issues.py @@ -17,6 +17,8 @@ async def create_issue( current_user: User = Depends(get_current_user), db: Session = Depends(get_db) ): + print(f"DEBUG: 받은 issue 데이터: {issue}") + print(f"DEBUG: project_id: {issue.project_id}") # 이미지 저장 photo_path = None photo_path2 = None @@ -34,6 +36,7 @@ async def create_issue( photo_path=photo_path, photo_path2=photo_path2, reporter_id=current_user.id, + project_id=issue.project_id, status=IssueStatus.new ) db.add(db_issue) diff --git a/frontend/index.html b/frontend/index.html index 713f16a..61c3186 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -196,7 +196,7 @@