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

Project Happy Thoughts API - Kathinka #487

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kathinka
Copy link

Netlify link

API
Site

Collaborators

solo

@kathinka kathinka changed the title Project Happy Thougts API Project Happy Thoughts API - Kathinka May 19, 2024
Copy link
Contributor

@HIPPIEKICK HIPPIEKICK left a comment

Choose a reason for hiding this comment

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

Nice job Kathinka, cool to see that you played around a little with the different methods and possibilities ⭐ 🥳

Copy link
Contributor

Choose a reason for hiding this comment

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

File names should be kebab-case (lowercase) if nothing else is specified 😇

Copy link
Contributor

Choose a reason for hiding this comment

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

But nice idea breaking this out 👍


const HappyThought = mongoose.model("HappyThought", happyThoughtSchema);

export default HappyThought;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good practice to always leave an empty line at the end of JS files

routes/Routes.js Outdated
@@ -0,0 +1,159 @@
import express, { response } from "express";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why import { response } here? 👀

.sort({ createdAt: "desc" })
.limit(20)
.exec();
res.json(happyThoughts);
Copy link
Contributor

Choose a reason for hiding this comment

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

A status code could be nice here

const newHappyThought = await new HappyThought({ message }).save();
res.status(201).json(newHappyThought);
} catch (error) {
console.error(error); // Log the error
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove console.logs in production

Comment on lines +43 to +47
const updatedThought = await HappyThought.findByIdAndUpdate(
thoughtId,
{ $inc: { hearts: 1 } },
{ new: true }
);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

{ new: true }
);
if (updatedThought) {
res.json(updatedThought);
Copy link
Contributor

Choose a reason for hiding this comment

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

Status code could be nice here too

});

//delete a happy thought
router.delete("/thoughts/:thoughtId", async (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Would be cool if it was reflected in your frontend as well, but since auth is not until this week, I understand you didn't want anyone to be able to delete anyone else's posts

});

//filter happy thoughts by limit or skip or both
router.get("/thoughts/q", async (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be its own endpoint, you can include the query in your /thoughts endpoint

});

// get updated documentation
router.get("/", (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Most generic endpoints should always come first, e.g.

  1. /
  2. /books
  3. /books/:id

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