MVP 0.92
This commit is contained in:
1 parent
60f0d2830d
commit
53b1eff833
62 files changed
+6578
-355
No files matched your search
@@ -10,6 +10,7 @@ from dialogue_turn import run_turn, visible_for_role
|
||||
from privacy_gateway import GatewayRequest, inspect
|
||||
from engine import EngineError
|
||||
from journal_generate import generate_draft
|
||||
from journal_opening import maybe_open_journal_conversation
|
||||
from journal_policy import PolicyError
|
||||
from journal_store import (
|
||||
create_day_conversation,
|
||||
@@ -20,13 +21,18 @@ from journal_store import (
|
||||
get_or_create_day,
|
||||
get_user_space,
|
||||
list_days,
|
||||
list_deleted_entries,
|
||||
list_space_entries,
|
||||
list_user_spaces,
|
||||
list_versions,
|
||||
purge_entry,
|
||||
rename_user_space,
|
||||
restore_entry,
|
||||
save_day_scratch,
|
||||
save_entry,
|
||||
soft_delete_entry,
|
||||
start_payload,
|
||||
undelete_entry,
|
||||
)
|
||||
from media_store import delete_media, get_media, list_media, save_media
|
||||
from writing_profile_store import (
|
||||
@@ -69,7 +75,11 @@ router = APIRouter(prefix="/api/journal", tags=["journal"])
|
||||
|
||||
|
||||
def _http(exc: StoreError | PolicyError | EngineError):
|
||||
raise HTTPException(status_code=exc.status_code, detail={"code": exc.code, "message": exc.message}) from exc
|
||||
detail = {"code": exc.code, "message": exc.message}
|
||||
extra = getattr(exc, "diagnostics", None)
|
||||
if extra:
|
||||
detail["diagnostics"] = extra
|
||||
raise HTTPException(status_code=exc.status_code, detail=detail) from exc
|
||||
|
||||
|
||||
class SpaceWrite(BaseModel):
|
||||
@@ -108,6 +118,10 @@ class RestoreWrite(BaseModel):
|
||||
version_id: str
|
||||
|
||||
|
||||
class PurgeWrite(BaseModel):
|
||||
confirm: bool = False
|
||||
|
||||
|
||||
class ScratchItem(BaseModel):
|
||||
id: str | None = None
|
||||
text: str = ""
|
||||
@@ -163,6 +177,11 @@ class ReviewAcceptWrite(BaseModel):
|
||||
baseline: bool = False
|
||||
|
||||
|
||||
@router.get("/continuity")
|
||||
def continuity(session: dict = Depends(require_auth)):
|
||||
return start_payload(session["profile_id"])
|
||||
|
||||
|
||||
@router.get("/spaces")
|
||||
def spaces(session: dict = Depends(require_auth)):
|
||||
return list_user_spaces(session["profile_id"])
|
||||
@@ -180,7 +199,27 @@ def create_space(body: SpaceWrite, session: dict = Depends(require_auth)):
|
||||
def space_detail(space_id: str, session: dict = Depends(require_auth)):
|
||||
try:
|
||||
space = get_user_space(session["profile_id"], space_id)
|
||||
return {"space": space, "days": list_days(session["profile_id"], space_id)}
|
||||
return {
|
||||
"space": space,
|
||||
"days": list_days(session["profile_id"], space_id),
|
||||
"entries": list_space_entries(session["profile_id"], space_id),
|
||||
}
|
||||
except StoreError as exc:
|
||||
_http(exc)
|
||||
|
||||
|
||||
@router.get("/spaces/{space_id}/entries")
|
||||
def space_entries(space_id: str, session: dict = Depends(require_auth)):
|
||||
try:
|
||||
return list_space_entries(session["profile_id"], space_id)
|
||||
except StoreError as exc:
|
||||
_http(exc)
|
||||
|
||||
|
||||
@router.get("/spaces/{space_id}/trash")
|
||||
def space_trash(space_id: str, session: dict = Depends(require_auth)):
|
||||
try:
|
||||
return list_deleted_entries(session["profile_id"], space_id)
|
||||
except StoreError as exc:
|
||||
_http(exc)
|
||||
|
||||
@@ -227,7 +266,9 @@ def write_scratch(journal_day_id: str, body: ScratchWrite, session: dict = Depen
|
||||
@router.post("/days/{journal_day_id}/conversations")
|
||||
def start_conversation(journal_day_id: str, body: ConversationWrite, session: dict = Depends(require_auth)):
|
||||
try:
|
||||
return create_day_conversation(session["profile_id"], journal_day_id, body.title)
|
||||
conversation = create_day_conversation(session["profile_id"], journal_day_id, body.title)
|
||||
opened = maybe_open_journal_conversation(session["profile_id"], conversation)
|
||||
return visible_for_role(opened, session.get("role"))
|
||||
except StoreError as exc:
|
||||
_http(exc)
|
||||
|
||||
@@ -356,6 +397,22 @@ def entry_restore(entry_id: str, body: RestoreWrite, session: dict = Depends(req
|
||||
_http(exc)
|
||||
|
||||
|
||||
@router.post("/entries/{entry_id}/undelete")
|
||||
def entry_undelete(entry_id: str, session: dict = Depends(require_auth)):
|
||||
try:
|
||||
return undelete_entry(session["profile_id"], entry_id)
|
||||
except StoreError as exc:
|
||||
_http(exc)
|
||||
|
||||
|
||||
@router.post("/entries/{entry_id}/purge")
|
||||
def entry_purge(entry_id: str, body: PurgeWrite, session: dict = Depends(require_auth)):
|
||||
try:
|
||||
return purge_entry(session["profile_id"], entry_id, confirm=body.confirm)
|
||||
except StoreError as exc:
|
||||
_http(exc)
|
||||
|
||||
|
||||
@router.delete("/entries/{entry_id}")
|
||||
def entry_delete(entry_id: str, session: dict = Depends(require_auth)):
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user