Implement storage layer for MVP-1 Personal Tracker CLI
Add storage layer with FileStorage, MarkdownReader, and MarkdownWriter classes. Add data models (Project, Session, Note, Change).
This commit is contained in:
65
tracker/services/note_service.py
Normal file
65
tracker/services/note_service.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""Note service for note management."""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from ..models import Session, NoteType, Note
|
||||
|
||||
|
||||
def add_note(session: Session, note_type: str, text: str) -> dict:
|
||||
"""
|
||||
Add a note to the session and return the note dict.
|
||||
Valid note types: work, change, blocker, decision, idea, reference
|
||||
"""
|
||||
try:
|
||||
note_type_enum = NoteType(note_type)
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid note type: {note_type}. Valid types are: {[t.value for t in NoteType]}")
|
||||
|
||||
note = Note(type=note_type_enum, text=text)
|
||||
session.raw_notes.append(note.model_dump(mode="json"))
|
||||
|
||||
return {
|
||||
"type": note.type.value,
|
||||
"text": note.text,
|
||||
"created_at": note.created_at.isoformat(),
|
||||
}
|
||||
|
||||
|
||||
def consolidate_notes(raw_notes: list[dict]) -> dict:
|
||||
"""
|
||||
Consolidate raw notes into categorized sections.
|
||||
Returns dict with keys: work_done, changes, decisions, blockers, references
|
||||
"""
|
||||
result = {
|
||||
"work_done": [],
|
||||
"changes": [],
|
||||
"decisions": [],
|
||||
"blockers": [],
|
||||
"references": [],
|
||||
}
|
||||
|
||||
for note in raw_notes:
|
||||
if isinstance(note, dict):
|
||||
note_type = note.get("type", "")
|
||||
text = note.get("text", "")
|
||||
else:
|
||||
# Handle string format like "[type] text"
|
||||
parts = note.split("]", 1)
|
||||
if len(parts) == 2:
|
||||
note_type = parts[0][1:]
|
||||
text = parts[1].strip()
|
||||
else:
|
||||
continue
|
||||
|
||||
if note_type == NoteType.WORK.value:
|
||||
result["work_done"].append(text)
|
||||
elif note_type == NoteType.CHANGE.value:
|
||||
result["changes"].append(text)
|
||||
elif note_type == NoteType.DECISION.value:
|
||||
result["decisions"].append(text)
|
||||
elif note_type == NoteType.BLOCKER.value:
|
||||
result["blockers"].append(text)
|
||||
elif note_type == NoteType.REFERENCE.value:
|
||||
result["references"].append(text)
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user