Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pantry info endpoint (backend & frontend) #3

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

hellolol2016
Copy link

@hellolol2016 hellolol2016 commented Sep 29, 2024

Note: We may not want to merge this PR until the ESLint crash triggered by the changes to apiClient.ts is fixed. Otherwise, all future commits and pushes on branches that include the changes from this branch will fail the pre-commit/pre-push hooks. (The --no-verify option was used to bypass these hooks for the last 2 commits on this branch, as the new API client function should not cause a linter crash.)

ℹ️ Issue
Closes https://trello.com/c/U1mRqCo7

📝 Description

  • Added pantries API endpoint to retrieve information about a pantry from its ID
    • Response is 404 Not Found if the pantry ID does not exist in the database
    • Added utils functions to make it easier for controller endpoint functions to throw an exception/return an error response code when a service function returns null or undefined
  • Used this endpoint in the frontend to show pantry info on the pantry-overview page, based on the pantry ID in the URL

✔️ Verification
Confirmed that Swagger contains the api endpoint:
Swagger image

Verified the endpoint with an existing pantry ID:
Postman API response image
frontend pantry overview page image

Verified the endpoint with a non-existing pantry ID:
Postman API response image
frontend pantry overview page image

@hellolol2016 hellolol2016 marked this pull request as draft September 29, 2024 20:03
@Column()
approved: boolean;

@Column()

Choose a reason for hiding this comment

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

we can do @manytoone(() => User) @joincolumn({ name: 'ssf_representative_id' }) here instead of column

@Column()
ssf_representative_id: number;

@Column()

Choose a reason for hiding this comment

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

and @manytoone(() => User) @joincolumn({ name: 'pantry_representative_id' }) here instead

Copy link
Author

Choose a reason for hiding this comment

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

hey fanny, I implemented what you suggested in my latest commit, could you explain a little bit more what this does?

Choose a reason for hiding this comment

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

Hi Dennis, "@manytoone" helps indicate a many-to-one relationship between the Pantry and User tables (meaning that each pantry can only have one user as its SSF representative or pantry representative, but a user can be the representative for multiple pantries). The "(() => User)" explicitly states that the many-to-one relationship is with the User entity, which is better for type checking and indicates that pantry_representative_id / ssf_representative_id foreign key columns in pantry refer to the user table. The "@joincolumn" specifies the columns in the pantry table that store the foreign keys linking to the user table.

@fanzzz368 fanzzz368 marked this pull request as ready for review October 19, 2024 02:49
@hellolol2016 hellolol2016 force-pushed the pantries-api-endpoints branch from 2c5aad7 to 8771b38 Compare October 20, 2024 20:23
Copy link

@fanzzz368 fanzzz368 left a comment

Choose a reason for hiding this comment

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

looks good to me

@sam-schu sam-schu marked this pull request as draft October 20, 2024 22:26
@sam-schu sam-schu changed the title pantry api configuration in most recent main branch Pantry info endpoint (backend & frontend) Oct 28, 2024
@sam-schu sam-schu marked this pull request as ready for review October 28, 2024 02:00
@sam-schu sam-schu requested a review from fanzzz368 October 28, 2024 02:00
Copy link

@fanzzz368 fanzzz368 left a comment

Choose a reason for hiding this comment

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

lgtm

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.

3 participants