Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fa48a58
install packages
MalLunBar May 28, 2025
b11e599
creating endpoint to find specific thought
MalLunBar May 28, 2025
094078a
create an endpoint to serch for different amounts of likes
MalLunBar May 28, 2025
a09e7b8
cleanup
MalLunBar May 28, 2025
ba24a8e
install mongoose and start using
MalLunBar Jun 2, 2025
0e33a1a
new import
MalLunBar Jun 4, 2025
53f890d
add a delete thought endpoint
MalLunBar Jun 5, 2025
03dc5a7
add a post
MalLunBar Jun 5, 2025
b1b437f
add default number to hearts
MalLunBar Jun 9, 2025
aa05d01
Add func to patch
MalLunBar Jun 9, 2025
4ba6d9a
text
MalLunBar Jun 10, 2025
0358632
test
MalLunBar Jun 10, 2025
92a04bc
functinality for edit
MalLunBar Jun 11, 2025
22a4b94
fix bug in edit
MalLunBar Jun 11, 2025
f3b7814
Add correct endpoint
MalLunBar Jun 11, 2025
89ebfd3
correcting error
MalLunBar Jun 11, 2025
dcfdfa8
trying to text bug
MalLunBar Jun 11, 2025
b1fa723
add authentication for user
MalLunBar Jun 12, 2025
41db274
break out and structure the code
MalLunBar Jun 12, 2025
dfa7571
modify login. Delete name as required
MalLunBar Jun 13, 2025
438de94
connect specific message to specific user + find and fix bug
MalLunBar Jun 15, 2025
6e11864
up the security
MalLunBar Jun 16, 2025
68aafd1
Fix bug
MalLunBar Jun 16, 2025
fd99adf
make get function to get liked messages
MalLunBar Jun 17, 2025
00c0807
fix the count of likes
MalLunBar Jun 18, 2025
cab7ae0
fix show liked messages bug
MalLunBar Jun 23, 2025
68bcbd2
delete console.logs
MalLunBar Jun 23, 2025
8d8e1ce
clean
MalLunBar Jun 23, 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
25 changes: 4 additions & 21 deletions data.json
Original file line number Diff line number Diff line change
@@ -1,118 +1,101 @@
[
{
"_id": "682bab8c12155b00101732ce",
{
"message": "Berlin baby",
"hearts": 37,
"createdAt": "2025-05-19T22:07:08.999Z",
"__v": 0
},
{
"_id": "682e53cc4fddf50010bbe739",
"message": "My family!",
"hearts": 0,
"createdAt": "2025-05-22T22:29:32.232Z",
"__v": 0
},
{
"_id": "682e4f844fddf50010bbe738",
"message": "The smell of coffee in the morning....",
"hearts": 23,
"createdAt": "2025-05-22T22:11:16.075Z",
"__v": 0
},
{
"_id": "682e48bf4fddf50010bbe737",
"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",
"message": "I am happy that I feel healthy and have energy again",
"hearts": 13,
"createdAt": "2025-05-21T21:28:32.196Z",
"__v": 0
},
{
"_id": "682e23fecf615800105107aa",
"message": "cold beer",
"hearts": 2,
"createdAt": "2025-05-21T19:05:34.113Z",
"__v": 0
},
{
"_id": "682e22aecf615800105107a9",
"message": "My friend is visiting this weekend! <3",
"hearts": 6,
"createdAt": "2025-05-21T18:59:58.121Z",
"__v": 0
},
{
"_id": "682cec1b17487d0010a298b6",
"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",
"message": "Tacos and tequila🌮🍹",
"hearts": 2,
"createdAt": "2025-05-19T20:53:18.899Z",
"__v": 0
},
{
"_id": "682ceb5617487d0010a298b4",
"message": "Netflix and late night ice-cream🍦",
"hearts": 1,
"createdAt": "2025-05-18T20:51:34.494Z",
"__v": 0
},
{
"_id": "682c99ba3bff2d0010f5d44e",
"message": "Summer is coming...",
"hearts": 2,
"createdAt": "2025-05-20T15:03:22.379Z",
"__v": 0
"__v": 0
},
{
"_id": "682c706c951f7a0017130024",
"message": "Exercise? I thought you said extra fries! 🍟😂",
"hearts": 14,
"createdAt": "2025-05-20T12:07:08.185Z",
"__v": 0
},
{
"_id": "682c6fe1951f7a0017130023",
"message": "I’m on a seafood diet. I see food, and I eat it.",
"hearts": 4,
"createdAt": "2025-05-20T12:04:49.978Z",
"__v": 0
},
{
"_id": "682c6f0e951f7a0017130022",
"message": "Cute monkeys🐒",
"hearts": 2,
"createdAt": "2025-05-20T12:01:18.308Z",
"__v": 0
},
{
"_id": "682c6e65951f7a0017130021",
"message": "The weather is nice!",
"hearts": 0,
"createdAt": "2025-05-20T11:58:29.662Z",
"__v": 0
},
{
"_id": "682bfdb4270ca300105af221",
"message": "good vibes and good things",
"hearts": 3,
"createdAt": "2025-05-20T03:57:40.322Z",
"__v": 0
},
{
"_id": "682bab8c12155b00101732ce",
"message": "Berlin baby",
"hearts": 37,
"createdAt": "2025-05-19T22:07:08.999Z",
Expand Down
46 changes: 46 additions & 0 deletions middleware/authMiddleware.js

Choose a reason for hiding this comment

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

clear code! This is a speculation, im not really sure how one could do that, but the two authentications functions seems similar i wonder if there is a way to write one function, but maybe would make the code more complicated idk just thinking

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { User } from '../models/User.js'


export const authenticateUser = async (req, res, next) => {
try {
const accessToken = req.header("Authorization")
const user = await User.findOne({ accessToken: accessToken })
if (user) {
req.user = user
next()
} else {
res.status(401).json({
message: "Authentication missing or invalid.",
loggedOut: true
})
}
} catch (error) {
res.status(500).json({
message: "Internal server error",
error: error.message
});
}
}

export const authenticateUserLike = async (req, res, next) => {
try {
const accessToken = req.header("Authorization")
if (accessToken) {
const user = await User.findOne({ accessToken: accessToken })
if (user) {
req.user = user
} else {
return res.status(401).json({
message: "Authentication missing or invalid.",
loggedOut: true
})
}
}
next()
} catch (error) {
res.status(500).json({
message: "Internal server error",
error: error.message
})
}
}
24 changes: 24 additions & 0 deletions models/Like.js

Choose a reason for hiding this comment

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

🤟👾✅

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mongoose from "mongoose"

const likeSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true
},
thought: {
type: mongoose.Schema.Types.ObjectId,
ref: "Thought",
required: true
},
createdAt: {
type: Date,
default: Date.now
}
})

// will make sure a user can only like a thought one time
//
likeSchema.index({ user: 1, thought: 1 }, { unique: true })

export const Like = mongoose.model("Like", likeSchema)
27 changes: 27 additions & 0 deletions models/Thought.js

Choose a reason for hiding this comment

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

🤟👾✅

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import mongoose from "mongoose"

const thoughtSchema = new mongoose.Schema({

message: {
type: String,
required: true,
minLength: 5,
maxLength: 140
},
hearts: {
type: Number,
default: 0
},
createdAt: {
type: Date,
default: Date.now
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true
},

})

export const Thought = mongoose.model("Thought", thoughtSchema)
28 changes: 28 additions & 0 deletions models/User.js

Choose a reason for hiding this comment

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

🤟👾✅

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import mongoose from "mongoose"
import crypto from "crypto"


// Create a schema for the users
const userSchema = new mongoose.Schema({
name: {
type: String,
required: true,

},
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
}, // Passwords should be hashed in a real application
accessToken: {
type: String,
default: crypto.randomBytes(128).toString("hex")
} // Generate a random access token

})

export const User = mongoose.model("User", userSchema)
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
"@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",
"dotenv": "^16.5.0",
"express": "^4.17.3",
"nodemon": "^3.0.1"
"express-list-endpoints": "^7.1.1",
"mongoose": "^8.15.1",
"nodemon": "^3.1.10"
}
}
Loading