Skip to content

Commit

Permalink
Creating temporary discussion API mock api endpoints to test integrat…
Browse files Browse the repository at this point in the history
…ing them into the frontend
  • Loading branch information
SeriousHorncat authored and JmScherer committed Nov 27, 2023
1 parent a3efb7b commit 28d41d3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
67 changes: 67 additions & 0 deletions backend/src/routers/analysis_discussion_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# pylint: disable=too-many-arguments
# Due to adding scope checks, it's adding too many arguments (7/6) to functions, so diabling this for now.
# Need to refactor later.
""" Analysis endpoint routes that provide an interface to interact with an Analysis' discussions """
from datetime import datetime, timezone
import logging
from uuid import uuid4

from fastapi import (APIRouter, Depends, Form, Security)

from ..dependencies import database
from ..models.user import VerifyUser
from ..security.security import get_current_user

logger = logging.getLogger(__name__)

router = APIRouter(tags=["analysis"], dependencies=[Depends(database)])


def mock_discussion_fixture():
"""Mock dicussion fixture to fake the discussions being returned"""
return [{
"post_id": "90jkflsd8d-6298-4afb-add5-6ef710eb5e98", "author_id": "3bghhsmnyqi6uxovazy07ryn9q1tqbnt",
"author_fullname": "Hello Person", "publish_timestamp": "2023-10-09T21:13:22.687000",
"content": "Nulla diam mi, semper vitae.", "attachments": [], "thread": []
}, {
"post_id": "a677fdsfsacf8-4ff9-a406-b113a7952f7e", "author_id": "kw0g790fdx715xsr1ead2jk0pqubtlyz",
"author_fullname": "Developer Person", "publish_timestamp": "2023-10-10T21:13:22.687000",
"content": "Morbi laoreet justo.", "attachments": [], "thread": []
}, {
"post_id": "e602ffdsfa-fdsfdsa-9f42-862c826255ef", "author_id": "exqkhvidr7uh2ndslsdymbzfbmqjlunk",
"author_fullname": "Variant Review Report Preparer Person", "publish_timestamp": "2023-10-13T21:13:22.687000",
"content": "Mauris pretium sem at nunc sollicitudin also.", "attachments": [], "thread": []
}]


@router.get("/{analysis_name}/discussions")
def get_analysis_discussions(analysis_name: str):
""" Returns a list of genomic units for a given analysis """
logger.info("Retrieving the analysis '%s' discussions ", analysis_name)
return mock_discussion_fixture()


@router.post("/{analysis_name}/discussions")
def add_analysis_discussions(
analysis_name: str,
discussion_content: str = Form(...),
repositories=Depends(database),
client_id: VerifyUser = Security(get_current_user)
):
""" Adds a new analysis topic """
logger.info("Adding the analysis '%s' from user '%s'", analysis_name, client_id)
logger.info("The message: %s", discussion_content)

current_user = repositories["user"].find_by_client_id(client_id)

current_discussions = mock_discussion_fixture()
current_discussions.append({
"post_id": str(uuid4()),
"author_id": client_id,
"author_fullname": current_user["full_name"],
"publish_timestamp": datetime.now(timezone.utc),
"content": discussion_content,
"attachments": [],
"thread": [],
})
return current_discussions
3 changes: 3 additions & 0 deletions backend/src/routers/analysis_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
from ..models.phenotips_json import BasePhenotips
from ..models.user import VerifyUser
from ..security.security import get_authorization, get_current_user
from . import analysis_discussion_router

logger = logging.getLogger(__name__)

router = APIRouter(prefix="/analysis", tags=["analysis"], dependencies=[Depends(database)])
logger.info('including the api roter for discussions')
router.include_router(analysis_discussion_router.router)


@router.get("/", response_model=List[Analysis])
Expand Down

0 comments on commit 28d41d3

Please sign in to comment.