Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Makefile
run:
uvicorn main:app --host 0.0.0.0 --port 8080 --reload --http h11
uvicorn main:app --host 0.0.0.0 --port 8080 --reload --http h11
26 changes: 26 additions & 0 deletions models/checklist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from sqlalchemy import Column, Integer, String, Enum, TIMESTAMP, text
from sqlalchemy.orm import relationship

class User(Base):
__tablename__ = "user"

u_id = Column(Integer, primary_key=True, autoincrement=True) # PK
id = Column(String(50), unique=True, nullable=False) # 로그인 ID
email = Column(String(150), unique=True, nullable=False)
password = Column(String(255), nullable=False)
provider = Column(
Enum("local", "google", "kakao", "naver", name="provider_enum"),
nullable=False,
server_default="local",
)
created_at = Column(
TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP")
)
updated_at = Column(
TIMESTAMP,
nullable=False,
server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
)

# 역참조: checklist 목록
checklists = relationship("Checklist", back_populates="user", cascade="all, delete-orphan")
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ langchain-community
langchain-core
langchain-openai
langchain-ollama
bitsandbytes
47 changes: 47 additions & 0 deletions routers/checklist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 변경/설명:
# - POST /checklists : 생성 전용
# - PATCH /checklists/{id}/clear : is_clear 0/1 설정
# - get_current_user는 user.u_id 제공 가정
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session

from app.schemas.checklist import ChecklistCreate, ChecklistClearUpdate
from app.models import Checklist # Checklist(u_id, checklist_title, is_clear)
from app.dependencies import get_db, get_current_user

router = APIRouter(prefix="/checklists", tags=["checklists"])

@router.post("", status_code=status.HTTP_201_CREATED)
def create_checklist(
req: ChecklistCreate,
db: Session = Depends(get_db),
user=Depends(get_current_user),
):
obj = Checklist(
u_id=user.u_id, # ← 프로젝트의 사용자 키에 맞게
checklist_title=req.checklist_title,
is_clear=0 # 기본 0(미완)
)
db.add(obj)
db.commit()
db.refresh(obj)
return {"id": obj.id, "checklist_title": obj.checklist_title, "is_clear": obj.is_clear}

@router.patch("/{checklist_id}/clear")
def set_clear_state(
checklist_id: int,
req: ChecklistClearUpdate, # {"is_clear": 0 | 1}
db: Session = Depends(get_db),
user=Depends(get_current_user),
):
obj = (
db.query(Checklist)
.filter(Checklist.id == checklist_id, Checklist.u_id == user.u_id)
.first()
)
if not obj:
raise HTTPException(status_code=404, detail="Checklist not found")
obj.is_clear = int(req.is_clear) # 0/1 저장
db.commit()
db.refresh(obj)
return {"id": obj.id, "is_clear": obj.is_clear}
46 changes: 38 additions & 8 deletions routers/note.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from dotenv import load_dotenv
from fastapi import APIRouter, Depends, HTTPException, BackgroundTasks
from fastapi import APIRouter, Depends, HTTPException, BackgroundTasks, Query
from fastapi.responses import StreamingResponse
from sqlalchemy.orm import Session
from typing import List
Expand Down Expand Up @@ -145,20 +145,33 @@ def toggle_favorite(
return note

def save_summary(note_id: int, text: str):
"""Deprecated: kept for reference. No longer overwrites original note."""
db2 = SessionLocal()
try:
tgt = db2.query(Note).filter(Note.id == note_id).first()
if tgt:
tgt.content = text
tgt.updated_at = datetime.utcnow()
db2.commit()
if not tgt:
return
# Create a new note in the same folder with title '<original>요약'
title = (tgt.title or "").strip() + "요약"
if len(title) > 255:
title = title[:255]
new_note = Note(
user_id=tgt.user_id,
folder_id=tgt.folder_id,
title=title,
content=text,
)
db2.add(new_note)
db2.commit()
finally:
db2.close()

@router.post("/notes/{note_id}/summarize")
async def summarize_stream_langchain(
note_id: int,
background_tasks: BackgroundTasks,
domain: str | None = Query(default=None, description="meeting | code | paper | general | auto(None)"),
longdoc: bool = Query(default=True, description="Enable long-document map→reduce"),
db: Session = Depends(get_db),
user = Depends(get_current_user)
):
Expand All @@ -168,15 +181,32 @@ async def summarize_stream_langchain(

async def event_gen():
parts = []
async for sse in stream_summary_with_langchain(note.content):
async for sse in stream_summary_with_langchain(note.content, domain=domain, longdoc=longdoc):
parts.append(sse.removeprefix("data: ").strip())
yield sse.encode()
full = "".join(parts).strip()
if full:
background_tasks.add_task(save_summary, note.id, full)
# Create a new summary note in the same folder with title '<original>요약'
title = (note.title or "").strip() + "요약"
if len(title) > 255:
title = title[:255]
new_note = Note(
user_id=user.u_id,
folder_id=note.folder_id,
title=title,
content=full,
)
db.add(new_note)
db.commit()
db.refresh(new_note)
try:
# Optional: notify created note id
yield f"data: SUMMARY_NOTE_ID:{new_note.id}\n\n".encode()
except Exception:
pass

return StreamingResponse(
event_gen(),
media_type="text/event-stream",
headers={"Cache-Control": "no-cache"}
)
)
8 changes: 8 additions & 0 deletions schemas/checklist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from pydantic import BaseModel, conint

class ChecklistCreate(BaseModel):
checklist_title: str

class ChecklistClearUpdate(BaseModel):
is_clear: conint(ge=0, le=1) # 0 또는 1만 허용
Loading