Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
28ed28d
initial setup of dependencies.
casalm26 May 27, 2025
00983f5
structure of files
casalm26 May 29, 2025
e5b5aad
lint setup
casalm26 May 29, 2025
30c4e03
added server.js and made the project functional.
casalm26 May 29, 2025
1449e13
implemented pagination and category filtering
casalm26 May 29, 2025
92295a3
added categories to the thoughts list
casalm26 May 29, 2025
b312686
added sorting and filtering
casalm26 May 29, 2025
bf31916
installed mongoose
casalm26 May 29, 2025
70b40cb
refactoring, broke the server.js file up into pieces.
casalm26 May 30, 2025
601a5f4
fixed readme
casalm26 May 31, 2025
64d6902
updated dependencies.
casalm26 Jun 3, 2025
576f491
added data models for thoughts and login
casalm26 Jun 3, 2025
f00b42d
seed database
casalm26 Jun 3, 2025
9f7768a
setup routes for auth
casalm26 Jun 3, 2025
049212a
added middleware for auth
casalm26 Jun 3, 2025
8cbdec1
Added error handling globally
casalm26 Jun 3, 2025
02f1c33
added databse functionality and connection to the app
casalm26 Jun 5, 2025
aa3921c
added validation to posting thoughts
casalm26 Jun 5, 2025
f7a281a
added route functionality
casalm26 Jun 5, 2025
b2cc34e
tests, bug fixes and some refactoring.
casalm26 Jun 8, 2025
7676a31
small fix
casalm26 Jun 9, 2025
a084ed6
JWT parsing fixed
casalm26 Jun 9, 2025
3a3d13d
JWT parsing fixed
casalm26 Jun 9, 2025
48eb407
update for production
casalm26 Jun 9, 2025
02e021a
chore(refactor): initialize task list for refactor sweep
casalm26 Jun 9, 2025
9a3ff3a
chore(refactor): eslint.config.js — clean code, format, relocate logic
casalm26 Jun 9, 2025
56f1a55
chore(refactor): src/db.js — clean code, format, relocate logic
casalm26 Jun 9, 2025
ada9380
chore(refactor): src/server.js — clean code, format, relocate logic
casalm26 Jun 9, 2025
d6d9a70
chore(refactor): src/routes/index.js — clean code, format, relocate l…
casalm26 Jun 9, 2025
dadf5be
chore(refactor): src/services/dataService.js — clean code, format, re…
casalm26 Jun 9, 2025
b6971a5
refactoring of the whole codebase
casalm26 Jun 10, 2025
8997771
validation fix
casalm26 Jun 10, 2025
74ffec7
re-seeded the database
casalm26 Jun 12, 2025
86bc641
restructure of the project library
casalm26 Jun 12, 2025
0a3d5cf
fix for pagination
casalm26 Jun 12, 2025
4178fe6
removed option to post anonymously
casalm26 Jun 13, 2025
2beec62
added documentation for seeing only the logged in user's thoughts
casalm26 Jun 13, 2025
9269c9d
fix for seeing only the logged in user's thoughts
casalm26 Jun 13, 2025
977b26d
cleanup
casalm26 Jun 13, 2025
4be528c
Added link in readme
casalm26 Jun 13, 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ node_modules
.env.development.local
.env.test.local
.env.production.local
package-lock.json
package-lock.json
instructions.txt
instructions_full.txt
refactoring.txt
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 80
}
164 changes: 158 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,163 @@
# Project API
# Happy Thoughts API

This project includes the packages and babel setup for an express server, and is just meant to make things a little simpler to get up and running with.
A REST API for managing happy thoughts with user authentication, filtering, sorting, and pagination.

## Getting started
## Live API

Install dependencies with `npm install`, then start the server by running `npm run dev`
🌐 **Production URL**: https://friendlytwitter-api.onrender.com
Live full website: https://friendlytwitter.netlify.app/

## View it live
## Endpoints

Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about.
### Documentation

- `GET /` - List all available endpoints

### Thoughts

- `GET /thoughts` - Get all thoughts (with optional filters, sorting, pagination)
- `GET /thoughts/:id` - Get single thought by ID
- `POST /thoughts` - Create a new thought (authenticated)
- `PUT /thoughts/:id` - Update a thought (authenticated, owner only)
- `DELETE /thoughts/:id` - Delete a thought (authenticated, owner only)
- `POST /thoughts/:id/like` - Like/unlike a thought (authenticated)

### Authentication

- `POST /auth/signup` - Register a new user
- `POST /auth/login` - Login user
- `GET /auth/me` - Get current user profile (authenticated)

### Users

- `GET /users/:id/thoughts` - Get thoughts by specific user (authenticated)
- `GET /users/me/thoughts` - Get thoughts created by the current user (authenticated)
- `GET /users/me/likes` - Get thoughts liked by the current user (authenticated)

## Query Parameters

**GET /thoughts** supports:

- `page` - Page number for pagination (default: 1)
- `limit` - Results per page, max 100 (default: 20)
- `category` - Filter by category (case-insensitive)
- `sort` - Sort by: `hearts`, `createdAt`, `updatedAt`, `category` (use `-` prefix for descending)
- `minHearts` - Filter thoughts with minimum number of hearts
- `newerThan` - Filter thoughts created after specific date (ISO format)

**GET /users/me/thoughts** supports the same parameters as GET /thoughts

**GET /users/me/likes** supports:

- `page` - Page number for pagination (default: 1)
- `limit` - Results per page, max 100 (default: 20)
- `sort` - Sort by: `hearts`, `createdAt`, `updatedAt`, `category` (use `-` prefix for descending)

## Authentication

Include the JWT token in the Authorization header:

```
Authorization: Bearer YOUR_JWT_TOKEN
```

## Examples

### Get API Documentation

```bash
curl https://friendlytwitter-api.onrender.com/
```

### Get All Thoughts

```bash
curl https://friendlytwitter-api.onrender.com/thoughts
```

### Get Thoughts with Pagination

```bash
curl https://friendlytwitter-api.onrender.com/thoughts?page=1&limit=5
```

### Filter and Sort Thoughts

```bash
curl https://friendlytwitter-api.onrender.com/thoughts?category=Food&sort=-hearts&minHearts=5
```

### Register a New User

```bash
curl -X POST https://friendlytwitter-api.onrender.com/auth/signup \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"SecurePass123","name":"John Doe"}'
```

### Login

```bash
curl -X POST https://friendlytwitter-api.onrender.com/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"SecurePass123"}'
```

### Create a Thought (Authenticated)

```bash
curl -X POST https://friendlytwitter-api.onrender.com/thoughts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{"message":"This is my happy thought!","category":"General"}'
```

### Like a Thought

```bash
curl -X POST https://friendlytwitter-api.onrender.com/thoughts/THOUGHT_ID/like \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
```

### Get My Thoughts

```bash
curl https://friendlytwitter-api.onrender.com/users/me/thoughts \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
```

### Get My Thoughts with Filters

```bash
curl "https://friendlytwitter-api.onrender.com/users/me/thoughts?category=Food&sort=-hearts&page=1&limit=10" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
```

### Get Thoughts I've Liked

```bash
curl https://friendlytwitter-api.onrender.com/users/me/likes \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
```

## Response Format

### Thoughts List Response

```json
{
"thoughts": [...],
"total": 123,
"pagination": {
"currentPage": 1,
"totalPages": 7,
"totalCount": 123,
"hasNextPage": true,
"hasPrevPage": false
},
"filters": {
"category": "Food",
"sort": "-hearts"
}
}
```
121 changes: 0 additions & 121 deletions data.json

This file was deleted.

Loading