Awesome
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: stenio.wagner1@gmail.com
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<br />Content: { message: "UHUL! The API is UP && RUNNING!" } | Code: 500 - INTERNAL SERVER ERROR <br />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 <br />Content: { message: "Database Filled and Ready to Use!" } | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Populate the Database." } |
/data/clear | DELETE | - | - | Code: 201 - CREATED <br />Content: { message: "Database Cleared!" } | Code: 500 - INTERNAL SERVER ERROR<br />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<br />Content: <br />{ <br />userLocation : UserLocation <br /> inYourCityEvents: [Event],<br />youMightLikeDishes : [Dish],<br />popularDishes : [Dish]<br />} | <br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: <A Message with a description of the Error> } |
Dishes
This routes are used to make CRUD operations with Dishes.
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/dish | POST | Dish | - | Code: 201 - CREATED <br />Content: { id: <ID of the Dish Created> } | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Dish." } |
<br />
- Create a set of Dishes in batch
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/dish/batch | POST | [Dish] | - | Code: 201 - CREATED<br />Content: { message: "Dishes Created with Success!"} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Dishes." } |
<br />
- Read all Dishes recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/dish | GET | - | - | Code: 200 - OK <br />Content: { dishes: [Dish]} | Code: 500 - INTERNAL SERVER ERROR <br />Content: { error: "Error when trying to Read All Dishes." } |
<br />
- Read a single Dish recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/dish/:id | GET | - | Required:<br />id: String | Code: 200 - OK<br />Content: { <br /> dish: Dish,<br />reviews: Review,<br />restaurant : Restaurant<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Dish Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Read Dish." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/dish/:id | PATCH | Required:<br /> Object with the Fields that will be updated <br /><br /> | Required:<br />id: String | Code: 200 - OK<br />Content: <br />{ <br /> dishUpdated: Dish<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Dish Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Update Dish." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/dish/:id | DELETE | Required<br />- | Required:<br />id: String | Code: 201 - CREATED<br />Content: <br />{ <br /> message: "Dish Deleted with Success!" <br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Dish Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />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 <br />Content: { id: <ID of the Restaurant Created> } | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Restaurant." } |
<br />
- Create a set of Restaurants in batch
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/restaurant/batch | POST | [Restaurant] | - | Code: 201 - CREATED<br />Content: { message: "Restaurants Created with Success!"} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Restaurants." } |
<br />
- Read all Restaurants recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/restaurant | GET | - | - | Code: 200 - OK <br />Content: { dishes: [Restaurant]} | Code: 500 - INTERNAL SERVER ERROR <br />Content: { error: "Error when trying to Read All Restaurants." } |
<br />
- Read a single Restaurant recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/restaurant/:id | GET | - | Required:<br />id: String | Code: 200 - OK<br /><br />Content: { <br /> review: Restaurant<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Restaurant Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Read Restaurant." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/restaurant/:id | PATCH | Required:<br /> Object with the Fields that will be updated <br /><br /> | Required:<br />id: String | Code: 200 - OK<br />Content: <br />{ <br /> restaurantUpdated: Restaurant<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Restaurant Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Update Restaurant." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/restaurant/:id | DELETE | - | Required:<br />id: String | Code: 201 - CREATED<br />Content: <br />{ <br /> message: "Restaurant deleted with Success!" <br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Restaurant Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />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:<br />header: UserLocation | Required:<br />query: dishesTypes=Dish.type<br /><br />Example: /restaurant/nearby?dishesType=Pizza | Code: 200 - OK<br />Content: <br />{ <br /> restaurants : [Restaurant]<br />} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Read by Dishe Type." } |
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:<br />header: UserLocation | Required:<br />query: { <br />dishesTypes= Dish.type<br />maxDistance= [Number]<br />} <br /><br />Example: restaurant/filter?dishesTypes=Pizza&<br />dishesTypes=Dessert&<br />maxDistance=8.5 | Code: 200 - OK<br />Content: <br />{ <br /> restaurants : [Restaurant]<br />} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Filter Restaurants." } |
Events
This routes are used to make CRUD operations with Events.
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/event | POST | Event | - | Code: 201 - CREATED<br />Content: { id: <ID of the Event Created> } | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Event." } |
<br />
- Create a set of Events in batch
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/event/batch | POST | [Event] | - | Code: 201 - CREATED<br />Content: { message: "Events Created with Success!"} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Events." } |
<br />
- Read all Events recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/event | GET | - | - | Code: 200 - OK<br />Content: { dishes: [Event]} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Read All Events." } |
<br />
- Read a single Event recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/event/:id | GET | - | Required:<br />id: String | Code: 200 - OK<br />Content: { <br /> restaurants: [Restaurant],<br />event: Event<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Event Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Read Event." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/event/:id | PATCH | Required:<br /> Object with the Fields that will be updated <br /><br /> | Required:<br />id: String | Code: 200 - OK<br />Content: <br />{ <br /> eventUpdated: Event<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Event Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Update Event." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/event/:id | DELETE | - | Required:<br />id: String | Code: 201 - CREATED<br />Content: <br />{ <br /> message: "Event deleted with Success!" <br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Event Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Delete Event." } |
Reviews
This routes are used to make CRUD operations with Reviews.
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/review | POST | Review | - | Code: 201 - CREATED<br />Content: { id: <ID of the Review Created> } | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Review." } |
<br />
- Create a set of Reviews in batch
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/review/batch | POST | [Review] | - | Code: 201 - CREATED<br />Content: { message: "Reviews Created with Success!"} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Create Reviews." } |
<br />
- Read all Reviews recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/review | GET | - | - | Code: 200 - OK<br />Content: { dishes: [Review]} | Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Read All Reviews." } |
<br />
- Read a single Review recorded from Database
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/review/:id | GET | - | Required:<br />id: String | Code: 200 - OK<br />Content: { <br /> review: Review<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Review Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Read Review." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/review/:id | PATCH | Required:<br /> Object with the Fields that will be updated <br /><br /> | Required:<br />id: String | Code: 200 - OK<br />Content: <br />{ <br /> reviewUpdated: Review<br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Review Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />Content: { message: "Error when trying to Update Review." } |
URL | Method | Params | URL Params | Success Response | Error Response |
---|
/review/:id | DELETE | - | Required:<br />id: String | Code: 201 - CREATED<br />Content: <br />{ <br /> message: "Review deleted with Success!" <br />} | Code: 400 - BAD REQUEST<br />Content: { message: "The field id is required." } <br /><br />or<br /><br />Code: 404 - NOT FOUND<br />Content: { message: "Review Not Found." } <br /><br />or<br /><br />Code: 500 - INTERNAL SERVER ERROR<br />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: stenio.wagner1@gmail.com
Connect with me at LinkedIn
Thank you!
License
This project is licensed under the MIT License - see the LICENSE.md file for details