Home

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.

URLMethodParamsURL ParamsSuccess ResponseError 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.

URLMethodParamsURL ParamsSuccess ResponseError Response
/data/populatePOST--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/clearDELETE--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.

URLMethodParamsURL ParamsSuccess ResponseError Response
/homeGET--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.

URLMethodParamsURL ParamsSuccess ResponseError Response
/dishPOSTDish-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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/dish/batchPOST[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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/dishGET--Code: 200 - OK <br />Content: { dishes:[Dish]}Code: 500 - INTERNAL SERVER ERROR <br />Content: { error: "Error when trying to Read All Dishes." }
<br />
URLMethodParamsURL ParamsSuccess ResponseError Response
/dish/:idGET-Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/dish/:idPATCHRequired:<br /> Object with the Fields that will be updated<br /><br />Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/dish/:idDELETERequired<br />-Required:<br />id: StringCode: 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.

URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurantPOSTRestaurant-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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurant/batchPOST[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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurantGET--Code: 200 - OK <br />Content: { dishes:[Restaurant]}Code: 500 - INTERNAL SERVER ERROR <br />Content: { error: "Error when trying to Read All Restaurants." }
<br />
URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurant/:idGET-Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurant/:idPATCHRequired:<br /> Object with the Fields that will be updated<br /><br />Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurant/:idDELETE-Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurant/nearbyGETRequired:<br />header: UserLocationRequired:<br />query: dishesTypes=Dish.type<br /><br />Example: /restaurant/nearby?dishesType=PizzaCode: 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 .

URLMethodParamsURL ParamsSuccess ResponseError Response
/restaurant/filterGETRequired:<br />header: UserLocationRequired:<br />query: {<br />dishesTypes=Dish.type<br />maxDistance=[Number]<br />}<br /><br />Example: restaurant/filter?dishesTypes=Pizza&<br />dishesTypes=Dessert&<br />maxDistance=8.5Code: 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.

URLMethodParamsURL ParamsSuccess ResponseError Response
/eventPOSTEvent-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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/event/batchPOST[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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/eventGET--Code: 200 - OK<br />Content: { dishes:[Event]}Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Read All Events." }
<br />
URLMethodParamsURL ParamsSuccess ResponseError Response
/event/:idGET-Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/event/:idPATCHRequired:<br /> Object with the Fields that will be updated<br /><br />Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/event/:idDELETE-Required:<br />id: StringCode: 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.

URLMethodParamsURL ParamsSuccess ResponseError Response
/reviewPOSTReview-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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/review/batchPOST[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 />
URLMethodParamsURL ParamsSuccess ResponseError Response
/reviewGET--Code: 200 - OK<br />Content: { dishes:[Review]}Code: 500 - INTERNAL SERVER ERROR<br />Content: { error: "Error when trying to Read All Reviews." }
<br />
URLMethodParamsURL ParamsSuccess ResponseError Response
/review/:idGET-Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/review/:idPATCHRequired:<br /> Object with the Fields that will be updated<br /><br />Required:<br />id: StringCode: 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." }
URLMethodParamsURL ParamsSuccess ResponseError Response
/review/:idDELETE-Required:<br />id: StringCode: 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

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