Skip to content

refactor and standardize route files#39

Open
mohinichahal wants to merge 2 commits intodevelopfrom
standardize-crud-routes
Open

refactor and standardize route files#39
mohinichahal wants to merge 2 commits intodevelopfrom
standardize-crud-routes

Conversation

@mohinichahal
Copy link
Collaborator

Developer: Mohini Chahal

Closes #33

Pull Request Summary

Standardized the PUT route for trees/[id] to follow consistent CRUD patterns:

  • Destructured Supabase responses (data, error)
  • NextResponse formatting standardized
  • Internal server errors return { message: "Internal Server Error" } with status 500

Modifications

refer to summary for details of changes:
src/app/api/admin/volunteers/[id]/route.ts
src/app/api/admin/trees/[id]/route.ts
src/app/api/admin/trees/route.ts

Testing Considerations

PUT routes for volunteers and trees tested locally:
GET and POST routes for all trees tested locally:
POST inserts new tree

  • Code is neat, readable, and works
  • Comments are appropriate
  • The commit messages follows our guidelines
  • The developer name is specified
  • The summary is completed
  • Assign reviewers

Screenshots/Screencast

{put screenshots of your change, or even better a screencast displaying the functionality}


if (error) {
const status = postgrestErrorToHttpStatus(error);
return NextResponse.json({ error }, { status });
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't forget to include the attribute names here!

return NextResponse.json({ message: message.data }, { status: 200 });
} catch (error) {
return NextResponse.json({ message: "Unexpected Server Error" }, { status: 500 });
return NextResponse.json({ data }, { status: 200 });
Copy link
Collaborator

Choose a reason for hiding this comment

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

attribute name here too

Comment on lines 14 to 16
return NextResponse.json({ message: error.message }, { status: postgrestErrorToHttpStatus(error) });
}
return NextResponse.json({ message: data }, { status: 200 });
Copy link
Collaborator

Choose a reason for hiding this comment

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

dont forget standard attribute names here too. we want to keep them consistent across all files

Comment on lines 36 to 43
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets remove all of this test auth logic to clean up the function

Comment on lines 48 to 54
@@ -53,10 +52,7 @@ export async function POST(request: NextRequest) {
);
}
return NextResponse.json({ message: response.data }, { status: 200 });
Copy link
Collaborator

Choose a reason for hiding this comment

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

use standard attribute names here again


if (error) {
const status = postgrestErrorToHttpStatus(error);
return NextResponse.json({ error }, { status });
Copy link
Collaborator

Choose a reason for hiding this comment

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

attribute names

Copy link
Collaborator

@MatthewBlam MatthewBlam 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 so far!

i left some comments, but overall, please go trough each file and make sure to standardize all of the response formats using the specified format in the issue #33 description. here's some notes:

  • remove any unrelated or unused code or logic that was used for testing purposes
  • make sure all variable naming conventions are consistent across files
  • make sure docstring comments are all formatted similarly (up to you on how to do so)
  • dont forget about volunteers/route.ts!

@mohinichahal
Copy link
Collaborator Author

really sorry about all the mistakes! didn't rely on the instructions as clearly as i should have.

i've committed the changes, please take another look when you have the chance!

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.

CRUD Methods - Standardize and Refactor

2 participants