Skip to content

mhanki/Mood-Minder-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mood Minder API

Node.js Express MySQL

Node.js API server for Mood Minder.

Table of contents

Installation

  1. Clone the repository: git clone https://github.com/mhanki/Mood-Minder-API.git
  2. Install the dependencies: npm install
  3. Set up a MySQL database. You can find the schema in the schema.sql file.
  4. Optionally populate the database with the feelings and environments data found in seed.sql.
  5. Configure your connection details in db.js if needed.

Usage

To start the API server, run:

npm start

By default, the server will run on port 8000. You can access the API at http://localhost:8000.

Endpoints

Users & Auth

  • POST /users: Create a new user.
  • POST /auth: Generate a JWT token by providing valid credentials.

Feelings & Environments

  • GET /feelings: Retrieves all feeling entries.
  • GET /feelings/:id: Retrieves a specific feeling.
  • GET /environments: Retrieves all environments entries.
  • GET /environments/:id: Retrieves a specific environment.

Logs (Protected routes, require authentication)

  • GET /logs: Retrieves all user logs.
  • GET /logs/:id: Retrieves a specific log.
  • POST /logs: Creates a new log.
  • PUT /logs/:id: Updates a specific log.
  • DELETE /logs/:id: Deletes a specific log.

Posts (Protected routes, require authentication)

  • GET /posts: Retrieves all user posts.
  • GET /posts/:id: Retrieves a specific post.
  • POST /posts: Creates a new post.
  • PUT /posts/:id: Updates a specific post.
  • DELETE /posts/:id: Deletes a specific post.

Request Examples

Register a new user

POST /users
content-type: application/json

{
  "name": "Jane",
  "username": "Jane123",
  "email": "[email protected]",
  "password": "123"
}

Login and create a JWT token

Requeset

POST /auth
content-type: application/json

{
  "email": "[email protected]",
  "password": "123"
}

Response

Status: 200 OK
content-type: application/json

{ 
  "token": "<JWT_TOKEN>", 
  "email": "[email protected]",
  "password": "123"
}

Retrieve all feelings

Request

GET /feelings

Response

Status: 200 OK
content-type: application/json

[
  {
    "ID": 1,
    "name": "horrible",
    "rank": 1
  },
  {
    "ID": 2,
    "name": "terrible",
    "rank": 2
  },
]

Retrieve all environments

Request

GET /environments

Response

Status: 200 OK
content-type: application/json

[
  {
    "ID": 1,
    "name": "at work"
  },
  {
    "ID": 2,
    "name": "outdoors"
  },
]

Retrieve all user logs (protected route)

GET /logs
Authorization: Bearer <JWT_TOKEN>

Retrieve a specific log (protected route)

GET /logs/:id
Authorization: Bearer <JWT_TOKEN>

Add a log (protected route)

POST /logs
content-type: application/json
Authorization: Bearer <JWT_TOKEN>

{
  "feeling": "<FEELING_ID>", 
  "environment": "<ENVIRONMENT_ID>"
}

Get a specific post (protected route)

Request

GET /posts/1
Authorization: Bearer <JWT_TOKEN>

Response

Status: 200 OK
content-type: application/json

{
  "post": {
    "ID": 1,
    "content": "New Post",
    "is_private": 1,
    "created_at": "2023-03-01T06:17:25.000Z",
    "updated_at": null,
    "user_id": 17
  }
}

Add a post (protected route)

POST /posts
content-type: application/json
Authorization: Bearer <JWT_TOKEN>

{
  "content": "A new post",
  "isPrivate": 0
}

Contributing

Found a bug or have a concrete feature request? Open a corresponding issue through the Issues Tab.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published