Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add published date on protein entry #206

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ CREATE TABLE proteins (
refs text, -- bibtex references mentioned in the content/article
species_id integer NOT NULL,
thumbnail bytea, -- thumbnail image of the protein in base64 format
date_published timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (species_id) REFERENCES species(id) ON UPDATE CASCADE ON DELETE CASCADE
);

Expand Down
12 changes: 9 additions & 3 deletions backend/src/api/protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ def get_protein_entry(protein_name: str):
proteins.content,
proteins.refs,
species.name,
proteins.thumbnail
proteins.thumbnail,
proteins.date_published
FROM proteins
JOIN species ON species.id = proteins.species_id
WHERE proteins.name = %s;"""
entry_sql = db.execute_return(query, [protein_name])
log.warn(entry_sql)

# if we got a result back
if entry_sql is not None and len(entry_sql) != 0:
Expand All @@ -163,12 +163,17 @@ def get_protein_entry(protein_name: str):
refs,
species_name,
thumbnail,
date_published,
) = only_returned_entry

# if byte arrays are present, decode them into a string
if thumbnail is not None:
# if byte arrays are present, decode them into a string
thumbnail = bytea_to_str(thumbnail)

if date_published is not None:
# forces the datetime object into a linux utc string
date_published = str(date_published)

return ProteinEntry(
name=name,
description=description,
Expand All @@ -178,6 +183,7 @@ def get_protein_entry(protein_name: str):
refs=refs,
species_name=species_name,
thumbnail=thumbnail,
date_published=date_published,
)

except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions backend/src/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ProteinEntry(CamelModel):
refs: str | None = None
thumbnail: str | None = None
description: str | None = None
date_published: str | None = None


class AllEntries(CamelModel):
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ export function formatProteinName(name: string) {
export function undoFormatProteinName(name: string) {
return name.replaceAll("_", " ");
}

/**
* @param date for example: '2024-04-03 18:52:04.878603+00:00'
*/
export function dbDateToMonthDayYear(date: string) {
const d = new Date(date);
// weirdly enough, the month is 0-indexed, but not others
return `${d.getUTCMonth() + 1}/${d.getUTCDate()}/${d.getUTCFullYear()}`;
}
1 change: 1 addition & 0 deletions frontend/src/lib/openapi/models/ProteinEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export type ProteinEntry = {
refs?: (string | null);
thumbnail?: (string | null);
description?: (string | null);
datePublished?: (string | null);
};

14 changes: 12 additions & 2 deletions frontend/src/routes/Protein.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import ProteinVis from "../lib/ProteinVis.svelte";
import { Button, Dropdown, DropdownItem } from "flowbite-svelte";
import Markdown from "../lib/Markdown.svelte";
import { numberWithCommas, undoFormatProteinName } from "../lib/format";
import {
numberWithCommas,
undoFormatProteinName,
dbDateToMonthDayYear,
} from "../lib/format";
import { navigate } from "svelte-routing";
import References from "../lib/References.svelte";
import { ChevronDownSolid, PenOutline } from "flowbite-svelte-icons";
Expand Down Expand Up @@ -129,7 +133,13 @@
<b>Method</b>
<div>AlphaFold 2</div>
<b>Date Published</b>
<div><code>11/11/1111</code></div>
<div>
<code
>{entry.datePublished
? dbDateToMonthDayYear(entry.datePublished)
: "n/a"}</code
>
</div>
</div>
</EntryCard>
</div>
Expand Down
Loading