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 @@