Skip to content

Commit

Permalink
Backend REST API Consistency Restructure (#162)
Browse files Browse the repository at this point in the history
* Manually rebased/merged discussions feature with the REST API consolidation effort to streamline the backend API service endpoints to be consistent

* Re-ordered the frontend methods to be together and consistent; fixed the frontend to include the anlaysis discussion tag

* Analysis Supporting Evidence endpoints refactored

* Refactor the annotation attachments endpoint to allow attachments to a dataset
  • Loading branch information
SeriousHorncat authored Feb 27, 2024
1 parent 82cda52 commit e0acc4a
Show file tree
Hide file tree
Showing 51 changed files with 2,976 additions and 2,773 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ backend/example_file_to_upload.txt
# Pandoc JOSS artifacts
media/
*.jats
*.pdf
/*.pdf
*.crossref

# SSL/TLS Certificates
Expand Down
3 changes: 1 addition & 2 deletions backend/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ disable=useless-return,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
duplicate-code
use-symbolic-message-instead

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
9 changes: 9 additions & 0 deletions backend/src/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
from enum import Enum


class SectionRowType(str, Enum):
"""The types of data stored within a field in an Analysis' sections."""

TEXT = 'text'
IMAGE = 'image'
DOCUMENT = 'document'
LINK = 'link'


class GenomicUnitType(str, Enum):
"""Enumeration of the different types of genomic units that can be analyzed"""

Expand Down
12 changes: 12 additions & 0 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
"name": "analysis",
"description": "Analyses of cases with information such as target gene, variation, phenotyping, and more.",
},
{
"name": "analysis sections",
"description": "Adds, updates, and removes content from an Analysis Section's fields within an analysis.",
},
{
"name": "analysis discussions",
"description": "Adds, updates, and removes discussion messages from an Analysis.",
},
{
"name": "analysis attachments",
"description": "Adds, updates, and removes attachments from an Analysis.",
},
{
"name": "annotation",
"description":
Expand Down
28 changes: 26 additions & 2 deletions backend/src/models/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""
# pylint: disable=too-few-public-methods
from datetime import date
from multiprocessing import Event
import json
import re
from typing import List, Optional
from pydantic import BaseModel, computed_field
from pydantic import BaseModel, computed_field, model_validator

from .event import Event

Expand All @@ -29,6 +29,14 @@ class Section(BaseModel, frozen=True):
attachment_field: Optional[str] = None
content: List = []

@model_validator(mode='before')
@classmethod
def validate_to_json(cls, value):
"""Allows FastAPI to valid and unpack the JSON of data into the model"""
if isinstance(value, str):
return cls(**json.loads(value))
return value


class BaseAnalysis(BaseModel):
"""The share parts of an analysis and it's summary"""
Expand Down Expand Up @@ -107,6 +115,22 @@ def units_to_annotate(self):

return units

def find_section_field_by_attachment_id(self, attachment_id):
"""
Returns a tuple of the Section and field of section that the attachment is in, otherwise returns (None, None)
"""

def attribute_type_in_field(attribute_key, field_value):
return attribute_key if attribute_key in field_value else ''

for section in self.sections:
for field in section.content:
for value in field['value']:
for key in ['file_id', 'attachment_id']:
if attribute_type_in_field(key, value) and value[key] == attachment_id:
return (section, field)
return (None, None)

def find_discussion_post(self, discussion_post_id):
"""
Finds a specific discussion post in an analysis by the discussion post id otherwise returns none
Expand Down
Loading

0 comments on commit e0acc4a

Please sign in to comment.