Skip to content

Commit

Permalink
feat: protein name with underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
xnought committed Apr 18, 2024
1 parent f3668d1 commit 752c010
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backend/src/api/articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from fastapi.exceptions import HTTPException
from ..auth import requires_authentication
from fastapi.requests import Request
from .protein import format_protein_name

router = APIRouter()

Expand Down Expand Up @@ -310,6 +311,12 @@ class UploadArticleProteinComponent(CamelModel):
@router.post("/article/component/protein")
def upload_article_protein_component(body: UploadArticleProteinComponent, req: Request):
requires_authentication(req)

# replaces spaces with underscore, which is how proteins are stored in the DB
body.name = format_protein_name(body.name)
if body.aligned_with_name is not None:
body.aligned_with_name = format_protein_name(body.aligned_with_name)

with Database() as db:
try:
component_id = insert_component(db, body.article_id)
Expand All @@ -329,6 +336,13 @@ class EditArticleProteinComponent(CamelModel):
@router.put("/article/component/protein")
def edit_article_protein_component(body: EditArticleProteinComponent, req: Request):
requires_authentication(req)

# replaces spaces with underscore, which is how proteins are stored in the DB
if body.new_name is not None:
body.new_name = format_protein_name(body.new_name)
if body.new_aligned_with_name is not None:
body.new_aligned_with_name = format_protein_name(body.new_aligned_with_name)

with Database() as db:
try:
query = """UPDATE protein_components SET name=%s, aligned_with_name=%s WHERE component_id=%s;"""
Expand Down

0 comments on commit 752c010

Please sign in to comment.