807cde30be
A task is now a note with status/priority/due_date columns set (status IS NOT NULL). This eliminates the separate tasks table, companion note system, cascade deletes, bidirectional title sync, and _skip_cascade flags. Migration (0004): - Add status, priority, due_date columns to notes table - Migrate task data from companion notes and orphan tasks - Drop tasks table and old enum types Backend: - models/note.py: Add TaskStatus/TaskPriority enums, task columns, is_task property - models/task.py: Deleted (merged into note.py) - models/__init__.py: Re-export enums from note.py, remove Task import - services/notes.py: Remove companion/cascade logic, add is_task filter, convert_note_to_task, convert_task_to_note, simplified backlinks - services/tasks.py: Rewritten as thin wrappers around notes service - routes/notes.py: Add is_task filter (default false), task fields in CRUD, convert-to-note endpoint - routes/tasks.py: description→body (with fallback), remove note_id filter Frontend: - types/note.ts: Add TaskStatus, TaskPriority, task fields to Note interface - types/task.ts: Task is now a re-export alias for Note - stores/notes.ts: Simplify convertToTask, add convertToNote - stores/tasks.ts: description→body in createTask/updateTask - TaskEditorView: description→body, remove companion note UI - TaskViewerView: description→body, remove companion note link, add Convert to Note - NoteViewerView: Remove companion task UI, simplify convert-to-task - TaskCard: description→body, non-null assertions for status/priority Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
157 lines
4.6 KiB
Python
157 lines
4.6 KiB
Python
from datetime import date
|
|
|
|
from quart import Blueprint, jsonify, request
|
|
|
|
from fabledassistant.services.notes import (
|
|
convert_note_to_task,
|
|
convert_task_to_note,
|
|
create_note,
|
|
delete_note,
|
|
get_all_tags,
|
|
get_backlinks,
|
|
get_note,
|
|
get_note_by_title,
|
|
get_or_create_note_by_title,
|
|
list_notes,
|
|
update_note,
|
|
)
|
|
from fabledassistant.utils.tags import extract_tags
|
|
|
|
notes_bp = Blueprint("notes", __name__, url_prefix="/api/notes")
|
|
|
|
|
|
@notes_bp.route("", methods=["GET"])
|
|
async def list_notes_route():
|
|
q = request.args.get("q")
|
|
tag = request.args.getlist("tag")
|
|
sort = request.args.get("sort", "updated_at")
|
|
order = request.args.get("order", "desc")
|
|
limit = request.args.get("limit", 50, type=int)
|
|
offset = request.args.get("offset", 0, type=int)
|
|
|
|
# Default to non-task notes only; ?is_task=true for tasks, ?all=true for everything
|
|
is_task: bool | None = False
|
|
if request.args.get("all", "").lower() == "true":
|
|
is_task = None
|
|
elif request.args.get("is_task", "").lower() == "true":
|
|
is_task = True
|
|
|
|
notes, total = await list_notes(
|
|
q=q, tags=tag or None, is_task=is_task, sort=sort, order=order, limit=limit, offset=offset
|
|
)
|
|
return jsonify({"notes": [n.to_dict() for n in notes], "total": total})
|
|
|
|
|
|
@notes_bp.route("", methods=["POST"])
|
|
async def create_note_route():
|
|
data = await request.get_json()
|
|
body = data.get("body", "")
|
|
tags = extract_tags(body)
|
|
|
|
# Optional task fields
|
|
status = data.get("status")
|
|
priority = data.get("priority")
|
|
due_date = None
|
|
if data.get("due_date"):
|
|
due_date = date.fromisoformat(data["due_date"])
|
|
|
|
note = await create_note(
|
|
title=data.get("title", ""),
|
|
body=body,
|
|
tags=tags,
|
|
parent_id=data.get("parent_id"),
|
|
status=status,
|
|
priority=priority,
|
|
due_date=due_date,
|
|
)
|
|
return jsonify(note.to_dict()), 201
|
|
|
|
|
|
@notes_bp.route("/tags", methods=["GET"])
|
|
async def list_tags_route():
|
|
q = request.args.get("q")
|
|
tags = await get_all_tags(q=q)
|
|
return jsonify({"tags": tags})
|
|
|
|
|
|
@notes_bp.route("/by-title", methods=["GET"])
|
|
async def get_note_by_title_route():
|
|
title = request.args.get("title", "")
|
|
if not title:
|
|
return jsonify({"error": "title parameter is required"}), 400
|
|
note = await get_note_by_title(title)
|
|
if note is None:
|
|
return jsonify({"error": "Note not found"}), 404
|
|
return jsonify(note.to_dict())
|
|
|
|
|
|
@notes_bp.route("/resolve-title", methods=["POST"])
|
|
async def resolve_title_route():
|
|
data = await request.get_json()
|
|
title = data.get("title", "").strip()
|
|
if not title:
|
|
return jsonify({"error": "title is required"}), 400
|
|
note = await get_or_create_note_by_title(title)
|
|
return jsonify(note.to_dict())
|
|
|
|
|
|
@notes_bp.route("/<int:note_id>", methods=["GET"])
|
|
async def get_note_route(note_id: int):
|
|
note = await get_note(note_id)
|
|
if note is None:
|
|
return jsonify({"error": "Note not found"}), 404
|
|
return jsonify(note.to_dict())
|
|
|
|
|
|
@notes_bp.route("/<int:note_id>", methods=["PUT"])
|
|
async def update_note_route(note_id: int):
|
|
data = await request.get_json()
|
|
fields = {}
|
|
for key in ("title", "body", "parent_id", "status", "priority"):
|
|
if key in data:
|
|
fields[key] = data[key]
|
|
|
|
if "due_date" in data:
|
|
fields["due_date"] = (
|
|
date.fromisoformat(data["due_date"]) if data["due_date"] else None
|
|
)
|
|
|
|
if "body" in fields:
|
|
fields["tags"] = extract_tags(fields["body"])
|
|
note = await update_note(note_id, **fields)
|
|
if note is None:
|
|
return jsonify({"error": "Note not found"}), 404
|
|
return jsonify(note.to_dict())
|
|
|
|
|
|
@notes_bp.route("/<int:note_id>", methods=["DELETE"])
|
|
async def delete_note_route(note_id: int):
|
|
deleted = await delete_note(note_id)
|
|
if not deleted:
|
|
return jsonify({"error": "Note not found"}), 404
|
|
return "", 204
|
|
|
|
|
|
@notes_bp.route("/<int:note_id>/convert-to-task", methods=["POST"])
|
|
async def convert_note_to_task_route(note_id: int):
|
|
try:
|
|
note = await convert_note_to_task(note_id)
|
|
return jsonify(note.to_dict()), 200
|
|
except ValueError as e:
|
|
return jsonify({"error": str(e)}), 404
|
|
|
|
|
|
@notes_bp.route("/<int:note_id>/convert-to-note", methods=["POST"])
|
|
async def convert_task_to_note_route(note_id: int):
|
|
try:
|
|
note = await convert_task_to_note(note_id)
|
|
return jsonify(note.to_dict()), 200
|
|
except ValueError as e:
|
|
return jsonify({"error": str(e)}), 404
|
|
|
|
|
|
@notes_bp.route("/<int:note_id>/backlinks", methods=["GET"])
|
|
async def get_backlinks_route(note_id: int):
|
|
links = await get_backlinks(note_id)
|
|
return jsonify({"backlinks": links})
|