Skip to content

RESTful API built with NodeJS + Express + MongoDB that serves the Bon-Appetit App.

License

Notifications You must be signed in to change notification settings

steniowagner/bon-appetit-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bon-Appetit-Server

This is the back-end of the Bon-Appetit App. It's a RESTful API built with NodeJS, that serves all the static data that the App needs.

About this Project

This project is part of my personal portfolio, so, I'll be happy if you could provide me any feedback about the project, code, structure or anything that you can report that could make me a better developer!

Email-me: [email protected]

Connect with me at LinkedIn

Also, you can use this Project as you wish, be for study, be for make improvements or earn money with it!

It's free!

Getting Started

Prerequisites

To run this project in the development mode, you'll need to have a basic environment with NodeJS 8+ installed. To use the database, you'll need to have MongoDB installed and running on your machine at the default port (27017).

Installing

Cloning the Repository

$ https://github.com/steniowagner/bon-appetit-server

$ cd bon-appetit-server

Installing dependencies

$ yarn

or

$ npm install

Running

Now, you'll need to change to development branch:

$ git checkout development

With all dependencies installed, the Database running and the environment properly configured, you can now run the server:

$ yarn dev

or

$ npm run dev

After run the server, populate the Database.

Routes

The base URL is: http://localhost:3001/bon-appetit/api/v1

Test Route

This is the route that you can use to check if the API is running properly.

URL Method Params URL Params Success Response Error Response
/ GET - - Code: 200 - OK
Content: { message: "UHUL! The API is UP && RUNNING!" }
Code: 500 - INTERNAL SERVER ERROR
Content: { error: <A Message with a description of the Error> }

Data Management

This routes are used to populate and to clear the Database with a single request. All the static data are stored at src/json-models, but it doesn't prevent you from create new data with custom values.

URL Method Params URL Params Success Response Error Response
/data/populate POST - - Code: 201 - CREATED
Content: { message: "Database Filled and Ready to Use!" }
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Populate the Database." }
/data/clear DELETE - - Code: 201 - CREATED
Content: { message: "Database Cleared!" }
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Clear the Database." }

Home

Returns all the data needed to show the Gastronomic Events happening in the City, Dishes that User might like and Popular Dishes, and also returns a random user-location as a current user location.

URL Method Params URL Params Success Response Error Response
/home GET - - Code: 200 - OK
Content:
{
userLocation: UserLocation
inYourCityEvents: [Event],
youMightLikeDishes: [Dish],
popularDishes: [Dish]
}

Code: 500 - INTERNAL SERVER ERROR
Content: { error: <A Message with a description of the Error> }

Dishes

This routes are used to make CRUD operations with Dishes.

  • Create a single Dish
URL Method Params URL Params Success Response Error Response
/dish POST Dish - Code: 201 - CREATED
Content: { id: <ID of the Dish Created> }
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Dish." }

  • Create a set of Dishes in batch
URL Method Params URL Params Success Response Error Response
/dish/batch POST [Dish] - Code: 201 - CREATED
Content: { message: "Dishes Created with Success!"}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Dishes." }

  • Read all Dishes recorded from Database
URL Method Params URL Params Success Response Error Response
/dish GET - - Code: 200 - OK
Content: { dishes:[Dish]}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Read All Dishes." }

  • Read a single Dish recorded from Database
URL Method Params URL Params Success Response Error Response
/dish/:id GET - Required:
id: String
Code: 200 - OK
Content: {
dish: Dish,
reviews: Review,
restaurant: Restaurant
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Dish Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Read Dish." }
  • Update a Dish
URL Method Params URL Params Success Response Error Response
/dish/:id PATCH Required:
Object with the Fields that will be updated

Required:
id: String
Code: 200 - OK
Content:
{
dishUpdated: Dish
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Dish Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Update Dish." }
  • Delete a Dish
URL Method Params URL Params Success Response Error Response
/dish/:id DELETE Required
-
Required:
id: String
Code: 201 - CREATED
Content:
{
message: "Dish Deleted with Success!"
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Dish Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Delete Dish." }

Restaurants

This routes are used to make CRUD operations with Restaurants.

  • Create a single Restaurant
URL Method Params URL Params Success Response Error Response
/restaurant POST Restaurant - Code: 201 - CREATED
Content: { id: <ID of the Restaurant Created> }
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Restaurant." }

  • Create a set of Restaurants in batch
URL Method Params URL Params Success Response Error Response
/restaurant/batch POST [Restaurant] - Code: 201 - CREATED
Content: { message: "Restaurants Created with Success!"}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Restaurants." }

  • Read all Restaurants recorded from Database
URL Method Params URL Params Success Response Error Response
/restaurant GET - - Code: 200 - OK
Content: { dishes:[Restaurant]}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Read All Restaurants." }

  • Read a single Restaurant recorded from Database
URL Method Params URL Params Success Response Error Response
/restaurant/:id GET - Required:
id: String
Code: 200 - OK

Content: {
review: Restaurant
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Restaurant Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Read Restaurant." }
  • Update a Restaurant
URL Method Params URL Params Success Response Error Response
/restaurant/:id PATCH Required:
Object with the Fields that will be updated

Required:
id: String
Code: 200 - OK
Content:
{
restaurantUpdated: Restaurant
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Restaurant Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Update Restaurant." }
  • Delete an Restaurant
URL Method Params URL Params Success Response Error Response
/restaurant/:id DELETE - Required:
id: String
Code: 201 - CREATED
Content:
{
message: "Restaurant deleted with Success!"
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Restaurant Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Delete Restaurant." }
  • Get the nearest Restaurants from User
URL Method Params URL Params Success Response Error Response
/restaurant/nearby GET Required:
header: UserLocation
Required:
query: dishesTypes=Dish.type

Example: /restaurant/nearby?dishesType=Pizza
Code: 200 - OK
Content:
{
restaurants: [Restaurant]
}
Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Read by Dishe Type." }
  • Filter Restaurants

Filter Restaurants based on the type of Dishes selected and the distance from the User to Restaurant .

URL Method Params URL Params Success Response Error Response
/restaurant/filter GET Required:
header: UserLocation
Required:
query: {
dishesTypes=Dish.type
maxDistance=[Number]
}

Example: restaurant/filter?dishesTypes=Pizza&
dishesTypes=Dessert&
maxDistance=8.5
Code: 200 - OK
Content:
{
restaurants: [Restaurant]
}
Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Filter Restaurants." }

Events

This routes are used to make CRUD operations with Events.

  • Create a single Event
URL Method Params URL Params Success Response Error Response
/event POST Event - Code: 201 - CREATED
Content: { id: <ID of the Event Created> }
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Event." }

  • Create a set of Events in batch
URL Method Params URL Params Success Response Error Response
/event/batch POST [Event] - Code: 201 - CREATED
Content: { message: "Events Created with Success!"}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Events." }

  • Read all Events recorded from Database
URL Method Params URL Params Success Response Error Response
/event GET - - Code: 200 - OK
Content: { dishes:[Event]}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Read All Events." }

  • Read a single Event recorded from Database
URL Method Params URL Params Success Response Error Response
/event/:id GET - Required:
id: String
Code: 200 - OK
Content: {
restaurants: [Restaurant],
event: Event
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Event Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Read Event." }
  • Update an Event
URL Method Params URL Params Success Response Error Response
/event/:id PATCH Required:
Object with the Fields that will be updated

Required:
id: String
Code: 200 - OK
Content:
{
eventUpdated: Event
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Event Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Update Event." }
  • Delete an Event
URL Method Params URL Params Success Response Error Response
/event/:id DELETE - Required:
id: String
Code: 201 - CREATED
Content:
{
message: "Event deleted with Success!"
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Event Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Delete Event." }

Reviews

This routes are used to make CRUD operations with Reviews.

  • Create a single Review
URL Method Params URL Params Success Response Error Response
/review POST Review - Code: 201 - CREATED
Content: { id: <ID of the Review Created> }
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Review." }

  • Create a set of Reviews in batch
URL Method Params URL Params Success Response Error Response
/review/batch POST [Review] - Code: 201 - CREATED
Content: { message: "Reviews Created with Success!"}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Create Reviews." }

  • Read all Reviews recorded from Database
URL Method Params URL Params Success Response Error Response
/review GET - - Code: 200 - OK
Content: { dishes:[Review]}
Code: 500 - INTERNAL SERVER ERROR
Content: { error: "Error when trying to Read All Reviews." }

  • Read a single Review recorded from Database
URL Method Params URL Params Success Response Error Response
/review/:id GET - Required:
id: String
Code: 200 - OK
Content: {
review: Review
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Review Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Read Review." }
  • Update a Review
URL Method Params URL Params Success Response Error Response
/review/:id PATCH Required:
Object with the Fields that will be updated

Required:
id: String
Code: 200 - OK
Content:
{
reviewUpdated: Review
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Review Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Update Review." }
  • Delete a Review
URL Method Params URL Params Success Response Error Response
/review/:id DELETE - Required:
id: String
Code: 201 - CREATED
Content:
{
message: "Review deleted with Success!"
}
Code: 400 - BAD REQUEST
Content: { message: "The field id is required." }

or

Code: 404 - NOT FOUND
Content: { message: "Review Not Found." }

or

Code: 500 - INTERNAL SERVER ERROR
Content: { message: "Error when trying to Delete Review." }

Models

Dish

{
   "imageURL":  {
      "type":  "String",
      "required":  true
   },
   "thumbnailImageURL":  {
      "type":  "String",
      "required":  true
   },
   "mediumImageURL":  {
      "type":  "String",
      "required":  true
   },
   "title":  {
      "type":  "String",
      "required":  true
   },
   "description":  {
      "type":  "String",
      "required":  true
   },
   "type":  {
      "type":  "String",
      "enum": [
	      "Barbecue",
	      "Dessert",
	      "Fast-Food",
	      "Homemade",
	      "Japanese",
	      "Pasta",
	      "Pizza",
	      "Salad",
	      "Seafood"
	   ],
      "required":  true
},
   "stars":  {
      "type":  "String",
      "required":  true
},
   "reviews":  {
      "type":  "String",
      "required":  true
   },
   "price":  {
      "type":  "String",
      "required":  true
   },
   "ingredients":  {
      "type":  "[String]",
      "required":  true
   }
}

Restaurant

{
   "imageURL": {
      "type": "String",
      "required": true
   },
   "thumbnailImageURL": {
      "type": "String",
      "required": true
   },
   "mediumImageURL": {
      "type": "String",
      "required": true
   },
   "name": {
      "type": "String",
      "required": true
   },
   "description": {
      "type": "String",
      "required": true
   },
   "stars": {
      "type": "Number",
      "required": true
   },
   "location": {
      "coordinates": {
         "type": "[Number]",
         "default": [0, 0]
      },
      "address": {
         "type": "String",
         "required": true
      }
   },
   "operatingHours": {
      "open": {
         "type": "String",
         "required": true
      },
      "close": {
         "type": "String",
         "required": true
      }
   },
   "dishesTypes": [
      {
         "type": "String",
         "enum": [
            "Barbecue",
            "Dessert",
            "Fast-Food",
            "Homemade",
            "Japanese",
            "Pasta",
            "Pizza",
            "Salad",
            "Seafood"
         ],
         "required": true
     }
   ]
}

Event

{
   "imageURL": {
      "type": "String",
      "required": true
   },
   "thumbnailImageURL": {
      "type": "String",
      "required": true
   },
   "mediumImageURL": {
      "type": "String",
      "required": true
   },
   "smallImageURL": {
      "type": "String",
      "required": true
   },
   "title": {
      "type": "String",
      "required": true
   },
   "description": {
      "type": "String",
      "required": true
   },
   "dishesTypes": [
      {
         "type": "String",
         "enum": [
            "Barbecue",
            "Dessert",
            "Fast-Food",
            "Homemade",
            "Japanese",
            "Pasta",
            "Pizza",
            "Salad",
            "Seafood"
         ],
         "required": true
     }
],
   "restaurantsParticipating": {
      "type": "Number",
      "required": true
   }
}

Review

{
   "profileImageURL": {
      "type": "String",
      "required": true
   },
   "name": {
      "type": "String",
      "required": true
   },
   "review": {
      "type": "String",
      "required": true
   },
   "stars": {
      "type": "Number",
      "required": false,
      "default":  0
   }
}

User Location

{
   "latitude": "Number",
   "longitude: "Number",
}

Built With

  • NodeJS - Build the server
  • Heroku - PaaS used in the production
  • Body-Parser - Node.js body parsing middleware
  • Express - Router of the Application
  • MongoDB - Database
  • Mongoose - Object Modeling
  • PM2 - Process Manager used in the production
  • Nodemon - Process Manager used in the development
  • Debug - Debug in development
  • Dotenv - Environment loader

Support tools

Contributing

You can send how many PR's do you want, I'll be glad to analyse and accept them! And if you have any question about the project...

Email-me: [email protected]

Connect with me at LinkedIn

Thank you!

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

RESTful API built with NodeJS + Express + MongoDB that serves the Bon-Appetit App.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published