diff --git a/backend/src/api_types.py b/backend/src/api_types.py index 9032a573..1f5e1f40 100644 --- a/backend/src/api_types.py +++ b/backend/src/api_types.py @@ -57,3 +57,4 @@ class EditBody(CamelModel): old_name: str # so we can identify the exact row we need to change new_name: str new_content: str | None = None + new_refs: str | None = None diff --git a/backend/src/server.py b/backend/src/server.py index a1e0a488..bc23fbcb 100644 --- a/backend/src/server.py +++ b/backend/src/server.py @@ -137,21 +137,33 @@ def edit_protein_entry(body: EditBody): os.rename(pdb_file_name(body.old_name), pdb_file_name(body.new_name)) with Database() as db: - # if we have content/markdown, then update it, otherwise just update the name - if body.new_content is not None: + if body.new_name != body.old_name: db.execute( - """UPDATE proteins SET name = %s, content = %s WHERE name = %s""", + """UPDATE proteins SET name = %s WHERE name = %s""", [ body.new_name, + body.old_name, + ], + ) + + if body.new_content is not None: + db.execute( + """UPDATE proteins SET content = %s WHERE name = %s""", + [ str_to_bytea(body.new_content), body.old_name, ], ) - else: + + if body.new_refs is not None: db.execute( - """UPDATE proteins SET name = %s WHERE name = %s""", - [body.new_name, body.old_name], + """UPDATE proteins SET refs = %s WHERE name = %s""", + [ + str_to_bytea(body.new_refs), + body.old_name, + ], ) + except Exception: return UploadError.WRITE_ERROR diff --git a/frontend/src/routes/edit/[proteinName]/+page.svelte b/frontend/src/routes/edit/[proteinName]/+page.svelte index 988ecb54..a9aa8993 100644 --- a/frontend/src/routes/edit/[proteinName]/+page.svelte +++ b/frontend/src/routes/edit/[proteinName]/+page.svelte @@ -4,13 +4,20 @@ import { goto } from "$app/navigation"; import { onMount } from "svelte"; import { formatProteinName, humanReadableProteinName } from "$lib/format"; + import ArticleEditor from "$lib/ArticleEditor.svelte"; // key difference, here we get the information, then populate it in the upload form that can be edited // and reuploaded/edited export let data; let name: string; - let content: string | null; + + // store original too so we can see if the user changed/edited the content + let ogContent: string; + let content: string; + let ogRefs: string; + let refs: string; + let uploadError: UploadError | undefined; let entry: ProteinEntry | null = null; let error = false; @@ -26,7 +33,12 @@ error = true; } else { name = humanReadableProteinName(entry.name); - content = entry.content!; + + content = entry.content ?? ""; + ogContent = content; // log original content + + refs = entry.refs ?? ""; + ogRefs = refs; // log original refs } }); @@ -54,13 +66,7 @@ {/if}
- -