-
Notifications
You must be signed in to change notification settings - Fork 52
API #32
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
base: master
Are you sure you want to change the base?
API #32
Changes from all commits
fc3d4d9
cd6642b
6320c48
7bd5c5d
f9d3367
942ecaf
8eebb8f
a0fc63b
d8cf278
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| [ | ||
| { | ||
| "id": 1, | ||
| "message": "Today I learned Express!", | ||
| "hearts": 5, | ||
| "category": "learning", | ||
| "createdAt": "2026-01-10T10:00:00.00Z" | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "message": "Coffee is the best", | ||
| "hearts": 12, | ||
| "category": "food", | ||
| "createdAt": "2026-01-11T08:30:00.00Z" | ||
| }, | ||
| { | ||
| "id": 3, | ||
| "message": "My cat is sleeping on my keyboard", | ||
| "hearts": 24, | ||
| "category": "home", | ||
| "createdAt": "2026-01-12T15:45:00.00Z" | ||
| }, | ||
| { | ||
| "id": 4, | ||
| "message": "Snow is finally falling outside the window", | ||
| "hearts": 7, | ||
| "category": "weather", | ||
| "createdAt": "2026-01-13T06:12:00.00Z" | ||
| }, | ||
| { | ||
| "id": 5, | ||
| "message": "Refactored old React code and everything feels cleaner", | ||
| "hearts": 18, | ||
| "category": "coding", | ||
| "createdAt": "2026-01-13T09:47:00.00Z" | ||
| }, | ||
| { | ||
| "id": 6, | ||
| "message": "Walk without podcasts felt surprisingly nice", | ||
| "hearts": 9, | ||
| "category": "mindfulness", | ||
| "createdAt": "2026-01-14T17:22:00.00Z" | ||
| }, | ||
| { | ||
| "id": 7, | ||
| "message": "Tried dark mode and never want to go back", | ||
| "hearts": 21, | ||
| "category": "tech", | ||
| "createdAt": "2026-01-14T20:05:00.00Z" | ||
| }, | ||
| { | ||
| "id": 8, | ||
| "message": "Pair programming saved me from a really stubborn bug", | ||
| "hearts": 14, | ||
| "category": "coding", | ||
| "createdAt": "2026-01-15T19:11:00.00Z" | ||
| }, | ||
| { | ||
| "id": 9, | ||
| "message": "Found the perfect playlist for focus mode", | ||
| "hearts": 16, | ||
| "category": "music", | ||
| "createdAt": "2026-01-16T21:30:00.00Z" | ||
| }, | ||
| { | ||
| "id": 10, | ||
| "message": "Pushed the first version of my new side project", | ||
| "hearts": 27, | ||
| "category": "projects", | ||
| "createdAt": "2026-01-17T09:03:00.00Z" | ||
| }, | ||
| { | ||
| "id": 11, | ||
| "message": "Closed all old browser tabs, feel like a new person", | ||
| "hearts": 19, | ||
| "category": "productivity", | ||
| "createdAt": "2026-01-17T11:58:00.00Z" | ||
| }, | ||
| { | ||
| "id": 12, | ||
| "message": "Finally wrote tests for that tricky function", | ||
| "hearts": 13, | ||
| "category": "coding", | ||
| "createdAt": "2026-01-18T14:40:00.00Z" | ||
| }, | ||
| { | ||
| "id": 13, | ||
| "message": "Inbox down to zero, almost unreal feeling", | ||
| "hearts": 22, | ||
| "category": "productivity", | ||
| "createdAt": "2026-01-18T19:26:00.00Z" | ||
| }, | ||
| { | ||
| "id": 14, | ||
| "message": "Tried standing desk all day, back thanks me", | ||
| "hearts": 11, | ||
| "category": "health", | ||
| "createdAt": "2026-01-19T08:55:00.00Z" | ||
| }, | ||
| { | ||
| "id": 15, | ||
| "message": "Skiing in calendar, winter feels okay again", | ||
| "hearts": 25, | ||
| "category": "skiing", | ||
| "createdAt": "2026-01-19T16:17:00.00Z" | ||
| }, | ||
| { | ||
| "id": 16, | ||
| "message": "Logged out of social media for a week", | ||
| "hearts": 30, | ||
| "category": "mindfulness", | ||
| "createdAt": "2026-01-20T12:34:00.00Z" | ||
| }, | ||
| { | ||
| "id": 17, | ||
| "message": "Finally got my VS Code setup perfect", | ||
| "hearts": 17, | ||
| "category": "tech", | ||
| "createdAt": "2026-01-20T19:02:00.00Z" | ||
| }, | ||
| { | ||
| "id": 18, | ||
| "message": "Discovered walks solve more bugs than expected", | ||
| "hearts": 28, | ||
| "category": "life", | ||
| "createdAt": "2026-01-21T07:48:00.00Z" | ||
| }, | ||
| { | ||
| "id": 19, | ||
| "message": "Perfect coffee mid-debug session", | ||
| "hearts": 20, | ||
| "category": "food", | ||
| "createdAt": "2026-01-21T10:19:00.00Z" | ||
| }, | ||
| { | ||
| "id": 20, | ||
| "message": "Added dark mode toggle to latest project", | ||
| "hearts": 23, | ||
| "category": "projects", | ||
| "createdAt": "2026-01-21T18:33:00.00Z" | ||
| }, | ||
| { | ||
| "id": 21, | ||
| "message": "Set up automatic backups, suddenly feel adult", | ||
| "hearts": 15, | ||
| "category": "tech", | ||
| "createdAt": "2026-01-22T09:10:00.00Z" | ||
| }, | ||
| { | ||
| "id": 22, | ||
| "message": "Found new favorite lunch spot around corner", | ||
| "hearts": 10, | ||
| "category": "food", | ||
| "createdAt": "2026-01-22T11:25:00.00Z" | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import mongoose from "mongoose"; | ||
|
|
||
| const thoughtSchema = new mongoose.Schema({ | ||
| message: { | ||
| type: String, | ||
| required: true, | ||
| minlength: 5, | ||
| maxlength: 140 | ||
| }, | ||
| hearts: { | ||
| type: Number, | ||
| default: 0 | ||
| }, | ||
| category: { | ||
| type: String, | ||
| default: "general" | ||
| }, | ||
| user: { | ||
| type: mongoose.Schema.Types.ObjectId, | ||
| ref: "User" | ||
| }, | ||
| username: { | ||
| type: String, | ||
| default: "Anonymous" | ||
| }, | ||
| createdAt: { | ||
| type: Date, | ||
| default: Date.now | ||
| } | ||
| }); | ||
|
|
||
| const Thought = mongoose.model("Thought", thoughtSchema); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
| export default Thought; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import mongoose from "mongoose"; | ||
| import bcrypt from "bcrypt"; | ||
| import crypto from "crypto"; | ||
|
|
||
| const userSchema = new mongoose.Schema({ | ||
| username: { | ||
| type: String, | ||
| required: true, | ||
| unique: true, | ||
| minlength: 3, | ||
| maxlength: 20 | ||
| }, | ||
| email: { | ||
| type: String, | ||
| required: true, | ||
| unique: true, | ||
| lowercase: true | ||
| }, | ||
| password: { | ||
| type: String, | ||
| required: true, | ||
| minlength: 8 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:) |
||
| }, | ||
| accessToken: { | ||
| type: String, | ||
| default: () => crypto.randomUUID() | ||
| }, | ||
| createdAt: { | ||
| type: Date, | ||
| default: Date.now | ||
| } | ||
| }); | ||
|
|
||
| userSchema.pre("save", async function() { | ||
| if (this.isModified("password")) { | ||
| this.password = await bcrypt.hash(this.password, 10); | ||
| } | ||
| }); | ||
|
|
||
| const User = mongoose.model("User", userSchema); | ||
| export default User; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,25 @@ | ||
| { | ||
| "name": "project-api", | ||
| "name": "myfirstapi", | ||
| "version": "1.0.0", | ||
| "description": "Project API", | ||
| "description": "", | ||
| "license": "ISC", | ||
| "author": "", | ||
| "type": "module", | ||
| "main": "server.js", | ||
| "scripts": { | ||
| "start": "babel-node server.js", | ||
| "dev": "nodemon server.js --exec babel-node" | ||
| "start": "node server.js", | ||
| "dev": "nodemon server.js --exec babel-node", | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "@babel/core": "^7.17.9", | ||
| "@babel/node": "^7.16.8", | ||
| "@babel/preset-env": "^7.16.11", | ||
| "cors": "^2.8.5", | ||
| "express": "^4.17.3", | ||
| "nodemon": "^3.0.1" | ||
| "@babel/core": "^7.28.6", | ||
| "@babel/node": "^7.28.6", | ||
| "@babel/preset-env": "^7.28.6", | ||
| "bcrypt": "^6.0.0", | ||
| "cors": "^2.8.6", | ||
| "dotenv": "^17.2.3", | ||
| "express": "^5.2.1", | ||
| "mongoose": "^9.1.5", | ||
| "nodemon": "^3.1.11" | ||
| } | ||
| } |
There was a problem hiding this comment.
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