diff --git a/app/api/v1/endpoints/group.py b/app/api/v1/endpoints/group.py index 59f2e90..ad93b33 100644 --- a/app/api/v1/endpoints/group.py +++ b/app/api/v1/endpoints/group.py @@ -240,7 +240,7 @@ async def change_article_name(article_id: int = Body(...), article_name: str = B @router.post("/changeNote", response_model=dict) async def change_note(note_id: int = Body(...), note_title: Optional[str] = Body(default=None), note_content: Optional[str] = Body(default=None), db: AsyncSession = Depends(get_db), user: dict = Depends(get_current_user)): - if len(note_title) > 100: + if note_title and len(note_title) > 100: raise HTTPException(status_code=405, detail="Invalid note title, longer than 100") user_id = user.get("id") await crud_change_note(user_id, note_id, note_title, note_content, db) diff --git a/app/api/v1/endpoints/note.py b/app/api/v1/endpoints/note.py index 8693925..8fc2def 100644 --- a/app/api/v1/endpoints/note.py +++ b/app/api/v1/endpoints/note.py @@ -1,4 +1,4 @@ -from fastapi import APIRouter, HTTPException, Depends +from fastapi import APIRouter, HTTPException, Depends, Body from sqlalchemy.ext.asyncio import AsyncSession from app.schemas.note import NoteCreate, NoteUpdate, NoteFind from app.utils.get_db import get_db @@ -21,8 +21,8 @@ async def delete_note(note_id: int, db: AsyncSession = Depends(get_db), current_ raise HTTPException(status_code=404, detail="Note not found") return {"msg": "Note deleted successfully"} -@router.put("/{note_id}", response_model=dict) -async def update_note(note_id: int, content: Optional[str] = None, title: Optional[str] = None,db: AsyncSession = Depends(get_db)): +@router.post("/{note_id}", response_model=dict) +async def update_note(note_id: int, content: Optional[str] = Body(default=None), title: Optional[str] = Body(default=None), db: AsyncSession = Depends(get_db)): if content is None and title is None: raise HTTPException(status_code=400, detail="At least one field must be provided for update") note = NoteUpdate(id=note_id, content=content, title=title)