Automated Action 355d2a84d5 Implement notes management platform with FastAPI and SQLite
- Set up project structure with FastAPI
- Create database models for notes
- Implement Alembic migrations
- Create API endpoints for note CRUD operations
- Implement note export functionality (markdown, txt, pdf)
- Add health endpoint
- Set up linting with Ruff
2025-06-04 08:13:43 +00:00

53 lines
1.5 KiB
Python

from typing import List, Optional
from sqlalchemy.orm import Session
from app.models.note import Note
from app.schemas.note import NoteCreate, NoteUpdate
def get_note(db: Session, note_id: int) -> Optional[Note]:
return db.query(Note).filter(Note.id == note_id).first()
def get_notes(db: Session, skip: int = 0, limit: int = 100) -> List[Note]:
return db.query(Note).order_by(Note.updated_at.desc()).offset(skip).limit(limit).all()
def search_notes(db: Session, query: str, skip: int = 0, limit: int = 100) -> List[Note]:
return db.query(Note).filter(
(Note.title.contains(query)) | (Note.content.contains(query))
).order_by(Note.updated_at.desc()).offset(skip).limit(limit).all()
def create_note(db: Session, note: NoteCreate) -> Note:
db_note = Note(title=note.title, content=note.content)
db.add(db_note)
db.commit()
db.refresh(db_note)
return db_note
def update_note(db: Session, note_id: int, note: NoteUpdate) -> Optional[Note]:
db_note = db.query(Note).filter(Note.id == note_id).first()
if not db_note:
return None
update_data = note.model_dump(exclude_unset=True)
for key, value in update_data.items():
setattr(db_note, key, value)
db.commit()
db.refresh(db_note)
return db_note
def delete_note(db: Session, note_id: int) -> bool:
db_note = db.query(Note).filter(Note.id == note_id).first()
if not db_note:
return False
db.delete(db_note)
db.commit()
return True