Skip to content

egidiosalinaro/meditActive-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ§˜πŸΌβ€β™€οΈ MeditActive API πŸ§˜πŸ½β€β™‚οΈ

a JSON RESTful API created to manage the back-end features of a meditation app.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. License
  6. Contact

About The Project ❓

The goal of the project is to deliver the back-end structure aimed to manage an hypothetical application dedicated to meditation. I used Node.js (with Express framework) and MongoDB database for the purpose.

The API structure is made up of three data Schemas:

  • users: data about app subscribers
  • intervals: timeframes during which users try to achieve their meditation goals
  • goals: the main topic of the meditation app, challenges that users try to win

Using the correct relevant endpoints you can interact with users, intervals and goals and create, read, update and delete them. Furthermore, you can search through intervals using queries and join any goal to an interval.

(back to top)

Built With 🧱

javascript JavaScript ES6

Node.js Node.js

express Express

nodemon Nodemon

axios Dotenv

helmet Helmet

morgan Morgan

mongoose Mongoose

mongodb-memory-server Mongodb Memory Server

jest Jest

supertest Supertest

(back to top)

Getting Started 🎬

I used Node.js to bootstrap this project. You can install it here.
Once installed, you are ready to go:

Prerequisites πŸ“

  • verify you installed Node.js correctly by checking its version on your computer

    node -v
    npm -v
  • clone this repository

    git clone https://github.com/egidiosalinaro/meditActive-api

(back to top)

Installation βš™οΈ

Once downloaded this repo, in the project directory, you can:

  • connect your MongoDB database

    create a .env file (you won't find mine because it is in the .gitignore list) containing an enviroment variable named DB_URI calling your MongoDB connection string (see the DB_URI environment variable in action in the file databaseConnection.js)
    Example: DB_URI="mongodb+srv://...

  • install libraries and dependencies

    npm install
    
  • test the app

    npm test
  • run the app

    npm start

(back to top)

Usage πŸ•ΉοΈ

You can use this API on the port 5000 via platforms like Postman, Thunderclient or Insomnia. The first parameter of every path is the name of the app itself /meditactive

Users 🧍

  • GET a list of all users from the database
    /meditactive/users

  • add a new user to the database with a POST request
    /meditactive/users

    {
        "name": "insert an alphanumeric string, min 2 characters",
        "surname": "insert an alphanumeric string, min 2 characters",
        "email": "insert a valid email"
    }
  • GET a specific user's details*
    /meditactive/users/:id

  • update a user with a PUT request*
    /meditactive/users/:id

  • DELETE a user from the database*
    /meditactive/users/:id

*(:id must be a valid MongoDB id)

Goals 🎯 πŸ₯…

  • GET a list of all goals from the database
    /meditactive/goals

  • add a new goal to the database with a POST request
    /meditactive/goals

    {
        "title": "insert an alphanumeric string, min 2 characters",
        "description": "insert an alphanumeric string, min 2 characters",
        "days": "insert a number"
    }
  • GET a specific goal's details*
    /meditactive/goals/:id

  • update a goal with a PUT request*
    /meditactive/goals/:id

  • DELETE a goal from the database*
    /meditactive/goals/:id

*(:id must be a valid MongoDB id)

Intervals ⏲️

  • GET a list of all intervals from the database
    /meditactive/intervals

  • add a new interval to the database with a POST request
    /meditactive/intervals

    {
        "user": "insert a valid mongoID related to an existing user",
        "starting": "insert a valid ISO date",
        "ending": "insert a valid ISO date"
    }
  • join an interval with a goal using a PUT request*
    /meditactive/intervals/:id

    {
       "relatedGoal": "insert a valid mongoID related to an existing goal"
    }
  • GET a list of intervals filtered by queries
    /meditactive/intervals/filter

    Filter parameters:

    • user: insert a valid mongoID related to the user field
    • start: insert a valid ISO date for the starting field
    • end: insert a valid ISO date for the ending field
    • goal: insert a valid mongoID related to the relatedGoal field

    example: /meditactive/intervals/filter?goal=6335c098bb3ddb89f54cd3d6&start=2023-10-01

  • GET a specific interval's details*
    /meditactive/intervals/:id

  • update an interval with a PUT request*
    /meditactive/intervals/:id

  • DELETE an interval from the database*
    /meditactive/intervals/:id

*(:id must be a valid MongoDB id)

(back to top)

Roadmap πŸ—ΊοΈ

  • .env file containing mongoDB key
  • functions to connect/disconnect to database via mongoose
  • app configuration
    • logger
    • security middleware
    • initializing routes
    • error handling middlewares
  • server main file
  • creating Schemas and models
  • routes files
    • intervals routes
      • mongoose find method for filtering queries
    • users routes
    • goals routes
    • adding .next to catch error middlewares if needed
  • testing all routes and errors with jest and supertest
  • final code cleaning and code consistency

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

egidiosalinaro@gmail.com

(back to top)