Skip to content

K1 5 create user schema and endpoints#6

Closed
RishanBaweja wants to merge 2 commits intohack4impact-calpoly:developfrom
RishanBaweja:K1-5-Create-User-Schema-and-Endpoints
Closed

K1 5 create user schema and endpoints#6
RishanBaweja wants to merge 2 commits intohack4impact-calpoly:developfrom
RishanBaweja:K1-5-Create-User-Schema-and-Endpoints

Conversation

@RishanBaweja
Copy link
Copy Markdown
Collaborator

Developer: Rishan Baweja

Closes #5

Pull Request Summary

Added the requested endpoints (retrieve all users, add user, retrieve a specific user, and update a specific user).
I did the updating and retrieving a specific user by their UUID

Modifications

I changed the userSchema file and updated it to match the specification, and I did the same for the Atlas preview. Additionally I added and changed the route files so that they would work for the requested API endpoints.

Testing Considerations

I tested the four API endpoints using Postman, and they worked on my end. My screenshots are below for it

Pull Request Checklist

  • 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

Screenshot 2026-01-28 at 7 34 13 PM Screenshot 2026-01-28 at 7 32 54 PM Screenshot 2026-01-28 at 7 33 19 PM Screenshot 2026-01-28 at 7 35 02 PM

@kaseyliu kaseyliu self-requested a review January 29, 2026 06:47
Copy link
Copy Markdown
Collaborator

@kaseyliu kaseyliu 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 overall! Left a few nitpicky comments, lmk if you are confused about them

import mongoose from "mongoose";

// Get a specific user, finding the user by their userID
export async function GET(_req: Request, { params }: { params: { id: string } }) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Was there a reason for using the normal Request vs NextRequest? We don't really need NextRequest, but lowkey I'd say just use it in case we need the functionality from it later (you can change the other ones to use NextRequest too)


const { id } = params;

const user = await User.findById(id).lean();
Copy link
Copy Markdown
Collaborator

@kaseyliu kaseyliu Jan 29, 2026

Choose a reason for hiding this comment

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

const user = await User.findById(id).lean(); You should probably move this to under your check for if the id is valid, so that this doesn't error (same for PUT)

// Get a specific user, finding the user by their userID
export async function GET(_req: Request, { params }: { params: { id: string } }) {
try {
await connectDB();
Copy link
Copy Markdown
Collaborator

@kaseyliu kaseyliu Jan 29, 2026

Choose a reason for hiding this comment

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

await connectDB();You could move this under your check for if the id is valid too, to avoid connecting if there's no id (same for PUT)


const { id } = params;
const changes = await req.json();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be good to add an id is valid check here too, like you did in GET

const body = await req.json();
const user = await User.create(body);
return NextResponse.json(user, { status: 201 });
} catch (err: any) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: could add console.error messages for all of these!

@kaseyliu kaseyliu closed this Feb 1, 2026
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.

2 participants