Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
879db5f
Update package.json with project details and structure
KidFromCalifornia May 26, 2025
dcbf71b
.get added and workiing with data.json
KidFromCalifornia May 28, 2025
87e3876
Add new endpoints for filtering, searching, pagination, and posting t…
KidFromCalifornia Jun 2, 2025
a772d40
Refactor server to use mongoose for database operations and update th…
KidFromCalifornia Jun 3, 2025
bc18d2a
d add like functionality to increment hearts
KidFromCalifornia Jun 3, 2025
7f552ec
Refactor server routes to return thoughts and improve error handling;…
KidFromCalifornia Jun 4, 2025
1608043
Add @babel/cli dependency to package.json
KidFromCalifornia Jun 4, 2025
725bcec
Fix start script in package.json to use npx for babel-node
KidFromCalifornia Jun 4, 2025
07afc42
Fix start script in package.json to remove npx for babel-node
KidFromCalifornia Jun 4, 2025
74a52af
Remove unused dependencies and clean up package.json scripts
KidFromCalifornia Jun 4, 2025
63c74e4
Remove empty devDependencies section from package.json
KidFromCalifornia Jun 4, 2025
9088efa
Implement user authentication and enhance thoughts management features
KidFromCalifornia Jun 12, 2025
3b58a19
Add user authentication and thoughts management routes, models, and m…
KidFromCalifornia Jun 12, 2025
cfe0327
Refactor thoughts and users routes for improved structure and clarity
KidFromCalifornia Jun 12, 2025
c60b78c
Refactor authentication middleware and update thoughts route for cons…
KidFromCalifornia Jun 13, 2025
140ad0f
Add user reference to Thought model and enforce ownership in delete r…
KidFromCalifornia Jun 13, 2025
c3d3204
Refactor post and delete routes in thoughts.js for improved organizat…
KidFromCalifornia Jun 14, 2025
98c5af0
Fix typo in user reference when creating a new thought
KidFromCalifornia Jun 14, 2025
1432255
Fix typo in user property assignment in post route
KidFromCalifornia Jun 14, 2025
85cb5d3
Fix typo in user property assignment in post route
KidFromCalifornia Jun 14, 2025
9431c53
Fix user property assignment in post route
KidFromCalifornia Jun 14, 2025
31110d1
fixed route for delete and patch
KidFromCalifornia Jun 14, 2025
c8ae688
Return success status with updated thought in patch route response
KidFromCalifornia Jun 14, 2025
b632444
Add express-list-endpoints dependency and update root endpoint response
KidFromCalifornia Jun 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 77 additions & 7 deletions data.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[
{
{
"_id": "682bab8c12155b00101732ce",
"message": "Berlin baby",
"hearts": 37,
"createdAt": "2025-05-19T22:07:08.999Z",
"__v": 0
},
{
"_id": "682e53cc4fddf50010bbe739",
"_id": "682e53cc4fddf50010bbe739",
"message": "My family!",
"hearts": 0,
"createdAt": "2025-05-22T22:29:32.232Z",
Expand All @@ -25,7 +25,7 @@
"message": "Newly washed bedlinen, kids that sleeps through the night.. FINGERS CROSSED 🤞🏼\n",
"hearts": 6,
"createdAt": "2025-05-21T21:42:23.862Z",
"__v": 0
"__v": 0
},
{
"_id": "682e45804fddf50010bbe736",
Expand Down Expand Up @@ -53,7 +53,7 @@
"message": "A god joke: \nWhy did the scarecrow win an award?\nBecause he was outstanding in his field!",
"hearts": 12,
"createdAt": "2025-05-20T20:54:51.082Z",
"__v": 0
"__v": 0
},
{
"_id": "682cebbe17487d0010a298b5",
Expand All @@ -74,7 +74,7 @@
"message": "Summer is coming...",
"hearts": 2,
"createdAt": "2025-05-20T15:03:22.379Z",
"__v": 0
"__v": 0
},
{
"_id": "682c706c951f7a0017130024",
Expand All @@ -100,7 +100,7 @@
{
"_id": "682c6e65951f7a0017130021",
"message": "The weather is nice!",
"hearts": 0,
"hearts": 2,
"createdAt": "2025-05-20T11:58:29.662Z",
"__v": 0
},
Expand All @@ -117,5 +117,75 @@
"hearts": 37,
"createdAt": "2025-05-19T22:07:08.999Z",
"__v": 0
},
{
"_id": "650b32c9e4bce17db221d8a7",
"message": "Long bike rides with no destination 🚴‍♀️",
"hearts": 19,
"createdAt": "2025-03-03T10:43:19.553Z",
"__v": 0
},
{
"_id": "64fcde98be72c80afc8d33ee",
"message": "When everything just clicks at work 💡",
"hearts": 25,
"createdAt": "2025-01-17T14:11:07.734Z",
"__v": 0
},
{
"_id": "63d1ecfc22cb0f173a6a8894",
"message": "A surprise sunny day in February ☀️",
"hearts": 30,
"createdAt": "2025-02-20T12:50:45.286Z",
"__v": 0
},
{
"_id": "64bb9b72a7a6b87ffce30d44",
"message": "Waking up before the alarm feeling refreshed 😴",
"hearts": 13,
"createdAt": "2025-04-10T06:39:58.914Z",
"__v": 0
},
{
"_id": "649a1dc0cced95dfad9a7e33",
"message": "Watching birds from the balcony 🐦",
"hearts": 6,
"createdAt": "2025-03-28T08:23:30.201Z",
"__v": 0
},
{
"_id": "652ee0db90de8445dfc29a2e",
"message": "Late-night deep talks with a friend 🌙",
"hearts": 31,
"createdAt": "2025-01-04T23:57:12.483Z",
"__v": 0
},
{
"_id": "63cf410d27b5f2cf6a97c028",
"message": "A clean desk and a clear mind 🧼🧠",
"hearts": 10,
"createdAt": "2025-05-06T11:45:01.006Z",
"__v": 0
},
{
"_id": "64aaf9ee8d8e2953df0cd987",
"message": "Hearing your favorite song on the radio 📻",
"hearts": 20,
"createdAt": "2025-04-25T15:20:38.527Z",
"__v": 0
},
{
"_id": "64b4b702df25e8e93f8a3e49",
"message": "The smell of fresh rain 🌧️",
"hearts": 12,
"createdAt": "2025-03-10T18:11:26.749Z",
"__v": 0
},
{
"_id": "6504d2b53a7bc742b7fbe114",
"message": "Seeing someone smile because of you 😊",
"hearts": 28,
"createdAt": "2025-02-12T20:02:14.318Z",
"__v": 0
}
]
]
25 changes: 25 additions & 0 deletions middlewares/authenticationUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import User from "../models/User.js";

const authenticationUser = async (req, res, next) => {
try {
const authHeader = req.headers && req.headers.authorization;
const accessToken =
authHeader && authHeader.startsWith("Bearer ")
? authHeader.split(" ")[1]
: null;
if (!accessToken) {
return res.status(401).json({ error: "Access token required" });
}
const user = await User.findOne({ accessToken });
if (user) {
req.user = user;
return next();
} else {
return res.status(401).json({ loggedout: true, error: "Unauthorized" });
}
} catch (error) {
return res.status(500).json({ error: "Internal server error" });
}
};

export default authenticationUser;
28 changes: 28 additions & 0 deletions models/Thought.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import mongoose from "mongoose";

const thoughtSchema = new mongoose.Schema({
message: {
type: String,
trim: true,
required: true,
minlength: 5,
maxlength: 140,
},
hearts: {
type: Number,
default: 0,
},
createdAt: {
type: Date,
default: Date.now,
},
username: {
type: String,
required: true,
trim: true,
},
});

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

export default Thought;
29 changes: 29 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import mongoose from "mongoose";
import crypto from "crypto";

const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
index: true, // Add index for optimization

Choose a reason for hiding this comment

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

},
email: {
type: String,
required: true,
unique: true,
index: true, // Add index for optimization
},
password: {
type: String,
required: true,
},
accessToken: {
type: String,
default: () => crypto.randomBytes(37).toString("hex"),
},
});

const User = mongoose.models.User || mongoose.model("User", userSchema);

export default User;
28 changes: 22 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
{
"name": "project-api",
"name": "js-project-api",
"version": "1.0.0",
"description": "Project API",
"description": " JS Project API",
"homepage": "https://github.com/KidFromCalifornia/js-project-api#readme",
"bugs": {
"url": "https://github.com/KidFromCalifornia/js-project-api/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/KidFromCalifornia/js-project-api.git"
},
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "server.js",
"scripts": {
"start": "babel-node server.js",
"dev": "nodemon server.js --exec babel-node"
},
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.17.9",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.11",
"bcrypt-nodejs": "^0.0.3",
"bcryptjs": "^3.0.2",
"cors": "^2.8.5",
"express": "^4.17.3",
"nodemon": "^3.0.1"
"dotenv": "^16.5.0",
"express": "^4.21.2",
"express-list-endpoints": "^7.1.1",
"mongoose": "^8.15.1",
"nodemon": "^3.0.1",
"validator": "^13.15.15"
}
}
Loading