Skip to content

Add honourary member endpoints#150

Open
AmrajKoonar wants to merge 2 commits into
CSSS:mainfrom
AmrajKoonar:issue-130-honourary-members
Open

Add honourary member endpoints#150
AmrajKoonar wants to merge 2 commits into
CSSS:mainfrom
AmrajKoonar:issue-130-honourary-members

Conversation

@AmrajKoonar

Copy link
Copy Markdown

Closes #130

Summary:

  • Added an honorary_member table and Alembic migration
  • Added honourary member models, CRUD functions, and routes
  • Registered the /honourary router
  • Added admin-only endpoints for listing, creating, updating, and deleting honourary member terms

Testing:

  • Ran python -m pytest
  • 47 tests passed

@jbriones1 jbriones1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, looks really good!

One thing that will need to change in many places is that "honourary" is less common than "honorary", even in Canada. That's my bad since that's how I wrote it in the issue. Please go through and change everything that says "honourary" to "honorary"

Comment thread src/honourary/__init__.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file can be removed.

Comment thread src/honourary/crud.py
Comment on lines +33 to +37
if honorary_member is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"honorary member term with id={term_id} does not exist",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<module>/crud.py files shouldn't raise HTTP errors, this will be changed for the Officers and Nominees module in the future. Return None and have the error be raised in honorary/urls.py.

This is so unit tests for CRUD operation don't need to test HTTPExceptions that are meant for API endpoints.

Comment thread src/honourary/crud.py
Comment on lines +43 to +46
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="cannot update or delete a term that has already ended",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as above You can change this to a function that returns a boolean and rename it to has_term_ended(honorary_member: HonoraryMemberDB) and then raise the HTTPException where needed.

Also, this should return status code 409 Conflict instead of 403 Forbidden. We use 409 to indicate that the request is well-formed, but the state of the resource doesn't allow it, while 403 Forbidden is when someone is authenticated, but not authorized to carry out an action.

Comment thread src/honourary/models.py


class HonoraryMemberCreate(BaseModel):
name: str = Field(..., max_length=128)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use HONORARY_MEMBER_MAX_LENGTH = 128.

# ### commands auto generated by Alembic - please adjust! ###
op.create_table('honorary_member',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the max length, make a file in the honorary folder and call it constants.py. Define a constant HONORARY_MEMBER_MAX_LENGTH = 128 and then use it in the models file, table definition, and this file.

Comment thread src/honourary/tables.py
__tablename__ = "honorary_member"

id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
name: Mapped[str] = mapped_column(String(128), nullable=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use HONORARY_MEMBER_MAX_LENGTH = 128.

Comment thread src/honourary/crud.py
honorary_members: list[HonoraryMemberDB],
) -> list[HonoraryMemberDB]:
db_session.add_all(honorary_members)
await db_session.flush()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the flush here and add it wherever it needs to happen.

Comment thread src/honourary/urls.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a responses dict to each endpoint to indicate what status codes can be returned. See

async def provide_nominee_info(db_session: database.DBSession, body: NomineeUpdate, computing_id: str):
for an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create resources to support Honorary Members

2 participants