Skip to content

Comments

API#32

Open
daniellauding wants to merge 9 commits intoTechnigo:masterfrom
daniellauding:master
Open

API#32
daniellauding wants to merge 9 commits intoTechnigo:masterfrom
daniellauding:master

Conversation

@daniellauding
Copy link

daniellauding and others added 9 commits January 23, 2026 07:40
- Add PATCH /thoughts/:id for editing thoughts (owner only)
- Add GET /categories for dynamic category list
- Add username field to Thought schema
- Fix typo in POST /thoughts (user._ud -> user._id)
- Update API documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Users can now delete their own account
- Also deletes all their thoughts when account is deleted

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Lists all users without sensitive fields (password, accessToken)
- For debugging purposes only

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
});

const Thought = mongoose.model("Thought", thoughtSchema);

Choose a reason for hiding this comment

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

Nice touch with separating models for user and thought into different files, makes it easier to read through!

},
category: {
type: String,
default: "general"

Choose a reason for hiding this comment

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

Great ux with the default category

password: {
type: String,
required: true,
minlength: 8

Choose a reason for hiding this comment

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

Also thoughtful moment with giving the minlength to pasword, makes it more secure for users:)

if (!user) {
return res.status(401).json({
success: false,
error: "Invalid token"

Choose a reason for hiding this comment

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

Great that you made different messages for different errors, makes it easier to handle them

authentication: {
description: "Some endpoints require authentication",
howTo: "Include 'Authorization' header with your access token",
protectedEndpoints: ["POST /thoughts", "PATCH /thoughts/:id", "DELETE /thoughts/:id"]

Choose a reason for hiding this comment

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

I see you hardcoded the endpoints instead of using listEndpoints here, and I it's a great idea to practice this already both for safety and for better documentation! I would probably suggest to still add listEndpoints(app) but only for internal use, and maybe console.log it to always be able to fast-check if hardcoded routes are up to date.


app.get("/thoughts", async (req, res) => {
try {
const { category, sort, page = 1, limit = 20 } = req.query;

Choose a reason for hiding this comment

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

Nice touch with limiting amount of fetched thoughts

try {
const { message, category } = req.body;

// First find the thought to check ownership

Choose a reason for hiding this comment

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

Great to see comments, makes it very easy to go through the code:)

}
});

// DELETE /users/:id - Delete user by ID (for debugging - remove in production!)

Choose a reason for hiding this comment

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

Again, great comment, especially since thosse last 2 end endpoints can seriously affect production:)

})
.catch((error) => {
console.error("Could not connect to MongoDB:", error.message)
});

Choose a reason for hiding this comment

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

Overall very clean work all the way through, great user experience and nice error handling with clear messages. Keep it up!:)

Copy link
Author

Choose a reason for hiding this comment

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

Thx!

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