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

Added behaviour endpoints #13

Merged
merged 7 commits into from
Jun 29, 2024
Merged

Conversation

MinIcecream
Copy link
Contributor

Created endpoints to modify/access the behaviour table.
Enabled getting all, getting one, creating, updating, and deleting entries.
Manually tested operations using Postman.

Copy link
Contributor

@aanxniee aanxniee left a comment

Choose a reason for hiding this comment

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

can you adding some ss to show your testing on postman

Copy link
Contributor

@aanxniee aanxniee left a comment

Choose a reason for hiding this comment

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

awesome work! seems right to me but let's add some ss so everyone reviewing can see it works. also did you make sure to test edge cases, i.e trying to delete something that doesn't exist, adding a behaviour name that's not valid

Copy link
Contributor

@jerry-cheng5 jerry-cheng5 left a comment

Choose a reason for hiding this comment

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

Looks really solid, just a couple small comments for design choices

}

export interface BehaviourResponseDTO {
id: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be a number? I know that for the UserDTO the id is a string, but I think that might be because it's a firebase user ID. Not 100% sure about that though.

But I think if there's no use case difference of the DTO, between having it as a string versus a number, then we should keep it consistent with the DB and have it as a number.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah me as well

try {
behaviour = await PgBehaviour.findByPk(id, { raw: true });
if (!behaviour) {
throw new Error(`Behaviour id ${id} not found`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this to be a 404 NOT FOUND response? We could do this by making custom error types and handling them seperately in the behaviourRoutes.ts file. (Something like NotFoundError would work)

LOL sorry ik I'm nitpicking, but you're the first one that made endpoints so I wanna make sure some things are clear for others as well.

backend/typescript/rest/behaviourRoutes.ts Show resolved Hide resolved
@MinIcecream
Copy link
Contributor Author

  1. Getting a specific behaviour, deleting a behaviour, and updating a behaviour now throws a 404 if the behaviour is not found.

  2. Changed id field in the BehaviourResponseDTO to be a number.

  3. Testing:

a. Getting all returns all behaviours in the database
image

b. Getting a specific behaviour returns it if it exists
image

c. Getting a specific behaviour returns 404 if it doesn't exist
image

d. Creating a new behaviour returns the created behaviour and updates database
image

e. Updating an existing behaviour returns the updated behaviour and updates database
image

f. Updating a nonexistent behaviour returns a 404 and doesn't affect database
image

g. Deleting an existing behaviour returns deleted behaviour's id and updates database
image

h. Deleting nonexistent behavour returns 404 and doesn't affect database
image

@MinIcecream
Copy link
Contributor Author

I also added the NotFoundError to the errorUtils file I found, but let me know if there's a better way to handle it.

if (e instanceof NotFoundError) {
res.status(404).send(getErrorMessage(e));
} else {
res.status(500).send(getErrorMessage(e));
Copy link
Contributor

Choose a reason for hiding this comment

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

for 500 i dont think we want to send the error message back. 500 is internal error so ideally we want to log the error internally, confirm @jerry-cheng5

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea I agree, I think that's the proper way to handle 500 errors.

(Normally its for security and shi and we don't reaaally have to worry about that, but its always good to practice the proper response conventions)

Copy link
Contributor

Choose a reason for hiding this comment

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

So maybe just send some generic message back like:

An unexpected internal server error occurred. Please try again later.

or

An unexpected error occurred on our end. Please try again later.

Copy link
Contributor

@aanxniee aanxniee left a comment

Choose a reason for hiding this comment

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

lgtm, wait for @laks0407 @jerry-cheng5 to take a final look

Copy link
Contributor

@jerry-cheng5 jerry-cheng5 left a comment

Choose a reason for hiding this comment

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

Great work! Really impressed by how fast you did all this :)

Everything looks good to me!

Copy link
Contributor

@laks0407 laks0407 left a comment

Choose a reason for hiding this comment

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

Looks great to me as well! Nice work :)

@MinIcecream MinIcecream merged commit f69d19c into main Jun 29, 2024
1 check passed
@MinIcecream MinIcecream deleted the S24/daniel/adding-behaviour-endpoints branch June 29, 2024 19:04
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.

5 participants