Skip to content

Commit

Permalink
run missing pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobfilik committed Jun 14, 2024
1 parent 91ae406 commit d7b9ad3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
40 changes: 24 additions & 16 deletions xas-standards-api/src/xas_standards_api/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import os
from typing import Annotated, List, Optional, Union
from typing import Annotated, List, Optional

import requests
from fastapi import (
Expand Down Expand Up @@ -123,7 +123,9 @@ async def get_current_user(


@app.get("/api/user")
async def check( session: Session = Depends(get_session), user_id: str = Depends(get_current_user)):
async def check(
session: Session = Depends(get_session), user_id: str = Depends(get_current_user)
):

statement = select(Person).where(Person.identifier == user_id)
person = session.exec(statement).first()
Expand Down Expand Up @@ -168,38 +170,42 @@ def read_standards(
) -> CursorPage[XASStandardResponse]:

statement = select(XASStandard).where(
XASStandard.review_status == ReviewStatus.approved)
XASStandard.review_status == ReviewStatus.approved
)

if element:
statement = statement.join(Element, XASStandard.element_z == Element.z).where(
Element.symbol == element
)


return paginate(
session, statement.order_by(XASStandard.id),
session,
statement.order_by(XASStandard.id),
)


@app.get("/api/admin/standards")
def read_standards_admin(
session: Session = Depends(get_session),
user_id: str = Depends(get_current_user),
) -> CursorPage[AdminXASStandardResponse]:

statement = select(Person).where(Person.identifier == user_id)
person = session.exec(statement).first()

if person is None or not person.admin:
raise HTTPException(status_code=401, detail=f"No standard with id={user_id}")
raise HTTPException(status_code=401, detail=f"No standard with id={user_id}")

if not person.admin:
raise HTTPException(status_code=401, detail=f"User {user_id} not admin")


statement = select(XASStandard).where(XASStandard.review_status == ReviewStatus.pending)
statement = select(XASStandard).where(
XASStandard.review_status == ReviewStatus.pending
)

return paginate(session, statement.order_by(XASStandard.id))


@app.get("/api/standards/{id}")
async def read_standard(
id: int, session: Session = Depends(get_session)
Expand Down Expand Up @@ -251,16 +257,18 @@ def add_standard_file(


@app.patch("/api/standards")
def submit_review(review: XASStandardAdminReviewInput,
session: Session = Depends(get_session),
user_id: str = Depends(get_current_user)):

def submit_review(
review: XASStandardAdminReviewInput,
session: Session = Depends(get_session),
user_id: str = Depends(get_current_user),
):

statement = select(Person).where(Person.identifier == user_id)
person = session.exec(statement).first()

if person is None or not person.admin:
raise HTTPException(status_code=401, detail=f"No standard with id={user_id}")
raise HTTPException(status_code=401, detail=f"No standard with id={user_id}")

if not person.admin:
raise HTTPException(status_code=401, detail=f"User {user_id} not admin")
return update_review(session, review, person.id)
Expand Down
1 change: 0 additions & 1 deletion xas-standards-api/src/xas_standards_api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def get_standard(session, id) -> XASStandard:
return standard
else:
raise HTTPException(status_code=404, detail=f"No standard with id={id}")



def update_review(session, review, reviewer_id):
Expand Down
10 changes: 8 additions & 2 deletions xas-standards-api/src/xas_standards_api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ class XASStandard(XASStandardInput, table=True):
element: Element = Relationship(sa_relationship_kwargs={"lazy": "joined"})
edge: Edge = Relationship(sa_relationship_kwargs={"lazy": "joined"})
beamline: Beamline = Relationship(sa_relationship_kwargs={"lazy": "selectin"})
submitter: Person = Relationship(sa_relationship_kwargs={"lazy": "selectin", "foreign_keys": "[XASStandard.submitter_id]"})
submitter: Person = Relationship(
sa_relationship_kwargs={
"lazy": "selectin",
"foreign_keys": "[XASStandard.submitter_id]",
}
)


class XASStandardResponse(XASStandardInput):
Expand All @@ -168,6 +173,7 @@ class XASStandardResponse(XASStandardInput):
beamline: BeamlineResponse
submitter_id: int


class AdminXASStandardResponse(XASStandardResponse):
submitter: Person

Expand All @@ -176,4 +182,4 @@ class XASStandardAdminReviewInput(SQLModel):
reviewer_comments: Optional[str] = None
review_status: ReviewStatus
standard_id: int
#get fedid from person table
# get fedid from person table

0 comments on commit d7b9ad3

Please sign in to comment.