Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SeriousHorncat committed Nov 9, 2023
1 parent f6b1839 commit 4105bc4
Showing 1 changed file with 63 additions and 8 deletions.
71 changes: 63 additions & 8 deletions backend/src/routers/analysis_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,72 @@ def update_event(
raise HTTPException(status_code=409, detail=str(exception)) from exception

@router.post("/{analysis_name}/sections", response_model=Analysis)
def update_analysis_sections(
def add_analysis_section_content(
analysis_name: str,
type: SectionRowType,
updated_sections: List[Section],
upload_file: UploadFile = File(...),
repositories=Depends(database),
authorized=Security(get_authorization, scopes=["write"]) #pylint: disable=unused-argument
):
"""Updates the sections that have changes"""
print(type)
print("The section type that is being saved in the update sections endpoint")
for section in updated_sections:
for field in section.content:
field_name, field_value= field["fieldName"], field["value"]
if "Nominator" == field_name:
repositories["analysis"].update_analysis_nominator(analysis_name, '; '.join(field_value))
repositories["analysis"].update_analysis_section(analysis_name, section.header, field_name, {"value": field_value})
if(type == SectionRowType.TEXT):
update_analysis_sections_text_fields(analysis_name, updated_sections, repositories["analysis"])
elif( type == SectionRowType.IMAGE or type == SectionRowType.DOCUMENT):
try:
new_object_id = add_file_to_bucket_repository(upload_file, repositories["bucket"])
except Exception as exception:
raise HTTPException(status_code=500, detail=str(exception)) from exception

# adding supportin evidence file
# field_value_file = {
# "name": upload_file.filename, "attachment_id": str(new_file_object_id), "type": "file", "comments": comments
# }
#
# return repositories['analysis'].attach_section_supporting_evidence_file(
# analysis_name, section_name, field_name, field_value_file
# )

else:
print(type)
print("ADDING TYPE NOT SUPPORTED YET, IN PROGRESS")

return repositories["analysis"].find_by_name(analysis_name)

@router.put("/{analysis_name}/sections", response_model=Analysis)
def update_analysis_section_content(
analysis_name: str,
type: SectionRowType,
updated_sections: List[Section],
repositories=Depends(database),
authorized=Security(get_authorization, scopes=["write"]) #pylint: disable=unused-argument
):
"""Updates the sections that have changes"""
print(type)
if(type == SectionRowType.TEXT):
update_analysis_sections_text_fields(analysis_name, updated_sections, repositories["analysis"])
else:
print(type)
print("ADDING TYPE NOT SUPPORTED YET, IN PROGRESS")

return repositories["analysis"].find_by_name(analysis_name)

def update_analysis_sections_text_fields(analysis_name, updated_sections: List[Section], analysis_repository):
for section in updated_sections:
for field in section.content:
field_name, field_value= field["fieldName"], field["value"]
if "Nominator" == field_name:
analysis_repository.update_analysis_nominator(analysis_name, '; '.join(field_value))
analysis_repository.update_analysis_section(analysis_name, section.header, field_name, {"value": field_value})

def add_file_to_bucket_repository(file_to_save, bucket_repository):
return bucket_repository.save_file(
file_to_save.file, file_to_save.filename, file_to_save.content_type
)

def add_analysis_section_document_field(analysis_name, section_name, field_name, document_file, analysis_repository):

@router.put("/{analysis_name}/section/attach/file")
def attach_animal_model_system_report(
analysis_name: str,
Expand Down Expand Up @@ -234,6 +281,14 @@ def attach_section_image(
authorized=Security(get_authorization, scopes=["write"]) #pylint: disable=unused-argument
):
""" Saves the uploaded image it to the specified field_name in the analysis's section."""
try:
new_file_object_id = repositories["bucket"].save_file(
upload_file.file, upload_file.filename, upload_file.content_type
)
except Exception as exception:
raise HTTPException(status_code=500, detail=str(exception)) from exception


try:
new_file_object_id = repositories["bucket"].save_file(
upload_file.file, upload_file.filename, upload_file.content_type
Expand Down

0 comments on commit 4105bc4

Please sign in to comment.