Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nleroy917 committed Feb 4, 2024
2 parents 509ac84 + 1d7c4cb commit 8923fbe
Showing 1 changed file with 66 additions and 24 deletions.
90 changes: 66 additions & 24 deletions pephub/routers/api/v1/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
ProjectUniqueNameError,
SampleAlreadyInView,
SampleNotFoundError,
ViewNotFoundError,
ProjectNotFoundError,
ViewAlreadyExistsError,
SampleAlreadyExistsError,
)
from pepdbagent.models import (
AnnotationModel,
Expand Down Expand Up @@ -504,8 +508,8 @@ async def update_sample(
"""
if namespace not in list_of_admins:
raise HTTPException(
detail="You do not have permission to update this project.",
status_code=401,
detail="Sample does not exist, or you do not have permission to update this sample.",
status_code=404,
)
try:
agent.sample.update(
Expand All @@ -522,10 +526,10 @@ async def update_sample(
},
status_code=202,
)
except Exception as e:
except SampleNotFoundError:
raise HTTPException(
status_code=400,
detail=f"Could not update sample. Server error: {e}",
status_code=404,
detail="Sample does not exist, or you do not have permission to update this sample.",
)


Expand Down Expand Up @@ -565,10 +569,17 @@ async def upload_sample(
},
status_code=202,
)
except Exception:

except SampleAlreadyExistsError:
raise HTTPException(
status_code=409,
detail="Sample already exists in project. Use 'overwrite' parameter to overwrite.",
)

except Exception as e:
raise HTTPException(
status_code=400,
detail="Could not upload sample. Server error!",
detail=f"Could not upload sample. Server error",
)


Expand Down Expand Up @@ -601,6 +612,11 @@ async def delete_sample(
},
status_code=202,
)
except SampleNotFoundError:
raise HTTPException(
status_code=404,
detail="Sample not found in project.",
)
except Exception:
raise HTTPException(
status_code=400,
Expand Down Expand Up @@ -805,24 +821,30 @@ async def get_view_of_the_project(
"""
Fetch a view of the project.
"""
if raw:
return ProjectRawModel(
**agent.view.get(
try:
if raw:
return ProjectRawModel(
**agent.view.get(
namespace=namespace,
name=project,
view_name=view,
tag=tag,
raw=raw,
)
)
else:
return agent.view.get(
namespace=namespace,
name=project,
view_name=view,
tag=tag,
raw=raw,
)
).to_dict()
except ViewNotFoundError:
raise HTTPException(
status_code=404,
detail=f"View '{view}' not found in project '{namespace}/{project}:{tag}'",
)
else:
return agent.view.get(
namespace=namespace,
name=project,
view_name=view,
tag=tag,
raw=raw,
).to_dict()


@project.post(
Expand Down Expand Up @@ -859,10 +881,20 @@ async def create_view_of_the_project(
sample_list=sample_names,
),
)
except Exception as e:
except SampleNotFoundError as e:
raise HTTPException(
status_code=404,
detail=f"Sample '{e}' not found in project '{namespace}/{project}:{tag}'",
)
except ProjectNotFoundError:
raise HTTPException(
status_code=404,
detail=f"Project '{namespace}/{project}:{tag}' not found",
)
except ViewAlreadyExistsError as e:
_LOGGER.error(f"Could not create view. Error: {e}")
raise HTTPException(
status_code=400,
status_code=409,
detail="Could not create view. Server error",
)
return JSONResponse(
Expand Down Expand Up @@ -929,12 +961,12 @@ async def add_sample_to_view(
)
except SampleAlreadyInView:
raise HTTPException(
status_code=400,
status_code=409,
detail=f"Sample '{sample_name}' already in view '{view}'",
)
except SampleNotFoundError:
raise HTTPException(
status_code=400,
status_code=404,
detail=f"Sample '{sample_name}' not found in project '{namespace}/{project}:{tag}'",
)
return JSONResponse(
Expand Down Expand Up @@ -975,9 +1007,14 @@ def delete_sample_from_view(
)
except SampleNotFoundError:
raise HTTPException(
status_code=400,
status_code=404,
detail=f"Sample '{sample_name}' not found in view '{view}'",
)
except ViewNotFoundError:
raise HTTPException(
status_code=404,
detail=f"View '{view}' not found in project '{namespace}/{project}:{tag}'",
)
return JSONResponse(
content={
"message": "Sample deleted from view successfully.",
Expand Down Expand Up @@ -1012,6 +1049,11 @@ def delete_view(
project_tag=tag,
view_name=view,
)
except ViewNotFoundError:
raise HTTPException(
status_code=404,
detail=f"View '{view}' not found in project '{namespace}/{project}:{tag}'",
)
except Exception:
raise HTTPException(
status_code=400,
Expand Down

0 comments on commit 8923fbe

Please sign in to comment.