Giter VIP home page Giter VIP logo

basemax / restaurantgraphql Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 1.1 MB

This GraphQL-based designed to handle multiple restaurants in a shop store. It provides various features such as searching for restaurants in a city, finding the nearest restaurant, retrieving a list of foods offered by a restaurant, and more.

License: GNU General Public License v3.0

JavaScript 3.86% TypeScript 96.14%
graphql javascript js ts typescript restuarant restuful-api

restaurantgraphql's Introduction

Restaurant GraphQL API

The RestaurantGraphQL API is a GraphQL-based API designed to handle multiple restaurants in a shop store. It provides various features such as searching for restaurants in a city, finding the nearest restaurant, retrieving a list of foods offered by a restaurant, and more. This README file provides an overview of the API and instructions on how to use it.

Features

The RestaurantGraphQL API offers the following features:

  • Search in a city: Users can search for restaurants in a specific city by providing the city name as a parameter.
  • Distance calculation: The API can calculate the distance between a given location and all the restaurants, enabling users to find the nearest restaurant.
  • Retrieve restaurant details: Users can retrieve detailed information about a specific restaurant, including its name, address, contact details, opening hours, and more.
  • Get a list of foods: The API allows users to fetch a list of foods offered by a restaurant, including their names, descriptions, prices, and any other relevant details.
  • Filtering: Users can apply various filters while searching for restaurants, such as food , price range, ratings, and more.

Installation

To run the RestaurantGraphQL API locally, follow these steps:

Clone the repository:

git clone https://github.com/BaseMax/RestaurantGraphQL

Navigate to the project directory:

cd RestaurantGraphQL

Install the dependencies:

npm install

Set up the environment variables:

  • Create a .env file in the project root.
  • Define the necessary environment variables, such as the database connection details and API keys.

Start the server:

npm start

The API will be available at http://localhost:3000.

Usage

To interact with the RestaurantGraphQL API, you need a GraphQL client or an API testing tool. Here's an example using cURL:

Make a POST request to the API endpoint (http://localhost:3000/graphql) with the following headers:

Content-Type: application/json

Send a GraphQL query as the request payload. Here's an example query to search for restaurants in a city:

query RestaurantByCity($city: String!) {
  restaurantByCity(city: $city) {
    name
    _id
    location {
      latitude
      longitude
    }
    foods {
      price
      name
      description
    }
  }
}

Replace "New York" with the desired city name.

Receive the response from the server, containing the list of restaurants in the specified city.

For detailed documentation on the available queries, mutations, and types, refer to the API documentation or the GraphQL schema.

Examples

Here are some additional examples of GraphQL queries and mutations for various features of the RestaurantGraphQL API:

Search in a City

Request:

query RestaurantByCity($city: String!) {
  restaurantByCity(city: $city) {
    name
    _id
    location {
      latitude
      longitude
    }
    foods {
      price
      name
      description
    }
  }
}

Body :

{
  "city": "london"
}

Response:

{
  "data": {
    "restaurantByCity": [
      {
        "name": "kababi",
        "_id": "649a14c72763b1002ad672c5",
        "location": {
          "latitude": -0.1379,
          "longitude": 51.5874
        },
        "foods": [
          {
            "price": 2000,
            "name": "kabab",
            "description": null
          },
          {
            "price": 200,
            "name": "mast",
            "description": null
          },
          {
            "price": 1000,
            "name": "gosht",
            "description": null
          },
          {
            "price": 3000,
            "name": "ghorme",
            "description": null
          }
        ]
      }
    ]
  }
}

Calculate Distance

Request:

query GetRestaurantWithDistance($locationInput: LocationInput!) {
  getRestaurantWithDistance(locationInput: $locationInput) {
    _id
    name
    location {
      longitude
      latitude
    }
  }
}

Body :

{
  "locationInput": {
    "latitude": -0.1379,
    "longitude": 51.5874
  }
}

Response:

{
  "data": {
    "getRestaurantWithDistance": [
      {
        "_id": "649a14c72763b1002ad672c5",
        "name": "kababi",
        "location": {
          "longitude": 51.5874,
          "latitude": -0.1379
        }
      }
    ]
  }
}

Retrieve Restaurant Details

Request:

query RestaurantById($restaurantByIdId: String!) {
  restaurantById(id: $restaurantByIdId) {
    name
    address
    city
    foods {
      price
      description
      name
    }
  }
}

Body :

{
  "restaurantByIdId": "649a14c72763b1002ad672c5"
}

Response:

{
  "data": {
    "restaurantById": {
      "name": "kababi",
      "address": "1 London Bridge St, London SE1 9BG",
      "city": "london",
      "foods": [
        {
          "price": 2000,
          "description": null,
          "name": "kabab"
        },
        {
          "price": 200,
          "description": null,
          "name": "mast"
        },
        {
          "price": 1000,
          "description": null,
          "name": "gosht"
        },
        {
          "price": 3000,
          "description": null,
          "name": "ghorme"
        }
      ]
    }
  }
}

Get List of Foods

Request:

query RestaurantById($restaurantByIdId: String!) {
  restaurantById(id: $restaurantByIdId) {
    foods {
      price
      name
      description
    }
  }
}

Body :

{
  "restaurantByIdId": "649a14c72763b1002ad672c5"
}

Response:

{
  "data": {
    "restaurantById": {
      "foods": [
        {
          "price": 2000,
          "name": "kabab",
          "description": null
        },
        {
          "price": 200,
          "name": "mast",
          "description": null
        },
        {
          "price": 1000,
          "name": "gosht",
          "description": null
        },
        {
          "price": 3000,
          "name": "ghorme",
          "description": null
        }
      ]
    }
  }
}

Filtering Restaurants

Request:

query SearchQuery($querySearch: QuerySearchInput!) {
  searchQuery(querySearch: $querySearch) {
    name
    address
    rating
    foods {
      price
      description
      name
    }
  }
}

Body :

{
  "querySearch": {
    "rating": 3,
    "food": "kabab",
    "name": "kakabi"
  }
}

Response:

{
  "data": {
    "searchQuery": []
  }
}

Create a Restaurant

Request:

mutation CreateRestaurant($createRestaurantInput: CreateRestaurantInput!) {
  createRestaurant(createRestaurantInput: $createRestaurantInput) {
    address
    contact {
      email
      phone
    }
    location {
      latitude
      longitude
    }
    name
    openingHours {
      day
      hours
    }
    rating
    city
    foods {
      name
    }
    _id
  }
}

Body :

{
  "createRestaurantInput": {
    "name": "kababi",
    "city": "london",
    "foods": [
      { "name": "kabab", "price": 2000 },
      { "name": "mast", "price": 200 },
      { "name": "gosht", "price": 1000 },
      { "name": "ghorme", "price": 3000 }
    ],
    "contact": {
      "email": "kababigmail.com",
      "phone": "989211828382"
    },
    "location": {
      "latitude": -0.1379,
      "longitude": 51.5874
    },
    "address": "1 London Bridge St, London SE1 9BG",
    "rating": 4,

    "openingHours": [
      { "day": "Monday", "hours": "10:00-22:00" },
      { "day": "Tuesday", "hours": "10:00-22:00" },
      { "day": "Wednesday", "hours": "10:00-22:00" },
      { "day": "Thursday", "hours": "10:00-22:00" },
      { "day": "Friday", "hours": "10:00-23:00" },
      { "day": "Saturday", "hours": "11:00-23:00" },
      { "day": "Sunday", "hours": "11:00-22:00" }
    ]
  }
}

Response:

{
  "data": {
    "createRestaurant": {
      "address": "1 London Bridge St, London SE1 9BG",
      "contact": {
        "email": "kababigmail.com",
        "phone": "989211828382"
      },
      "location": {
        "latitude": -0.1379,
        "longitude": 51.5874
      },
      "name": "kababi",
      "openingHours": [
        {
          "day": "Monday",
          "hours": "10:00-22:00"
        },
        {
          "day": "Tuesday",
          "hours": "10:00-22:00"
        },
        {
          "day": "Wednesday",
          "hours": "10:00-22:00"
        },
        {
          "day": "Thursday",
          "hours": "10:00-22:00"
        },
        {
          "day": "Friday",
          "hours": "10:00-23:00"
        },
        {
          "day": "Saturday",
          "hours": "11:00-23:00"
        },
        {
          "day": "Sunday",
          "hours": "11:00-22:00"
        }
      ],
      "rating": 4,
      "city": "london",
      "foods": [
        {
          "name": "kabab"
        },
        {
          "name": "mast"
        },
        {
          "name": "gosht"
        },
        {
          "name": "ghorme"
        }
      ],
      "_id": "649a18652763b1002ad672f7"
    }
  }
}

Get Restaurants rates greater than specified rate

Request:

query SearchQuery($querySearch: QuerySearchInput!) {
  searchQuery(querySearch: $querySearch) {
    name
    address
    rating
    foods {
      price
      description
      name
    }
  }
}

Body :

{
  "querySearch": {
    "rating": 3
  }
}

Response:

{
  "data": {
    "searchQuery": [
      {
        "name": "kababi",
        "address": "1 London Bridge St, London SE1 9BG",
        "rating": 4,
        "foods": [
          {
            "price": 2000,
            "description": null,
            "name": "kabab"
          },
          {
            "price": 200,
            "description": null,
            "name": "mast"
          },
          {
            "price": 1000,
            "description": null,
            "name": "gosht"
          },
          {
            "price": 3000,
            "description": null,
            "name": "ghorme"
          }
        ]
      }
    ]
  }
}

Get Restaurants by Price Range

Request:

query {
  restaurantsByPriceRange(minPrice: 10, maxPrice: 20) {
    id
    name
    address
    cuisine
    rating
  }
}

Response:

{
  "data": {
    "restaurantsByPriceRange": [
      {
        "id": "1",
        "name": "The Best Pizza",
        "address": "123 Main St",
        "cuisine": "Italian",
        "rating": 4.5
      },
      {
        "id": "3",
        "name": "Sushi Express",
        "address": "456 Cherry Blossom Ave",
        "cuisine": "Japanese",
        "rating": 4.8
      },
      ...
    ]
  }
}

Get Restaurants by food

Request:

query SearchQuery($querySearch: QuerySearchInput!) {
  searchQuery(querySearch: $querySearch) {
    name
    address
    rating
    foods {
      price
      description
      name
    }
  }
}

Body :

{
  "querySearch": {
    "food": "kabab"
  }
}

Response:

{
  "data": {
    "searchQuery": [
      {
        "name": "kababi",
        "address": "1 London Bridge St, London SE1 9BG",
        "rating": 4,
        "foods": [
          {
            "price": 2000,
            "description": null,
            "name": "kabab"
          },
          {
            "price": 200,
            "description": null,
            "name": "mast"
          },
          {
            "price": 1000,
            "description": null,
            "name": "gosht"
          },
          {
            "price": 3000,
            "description": null,
            "name": "ghorme"
          }
        ]
      }
    ]
  }
}

Search Restaurants by Name

Request:

query SearchQuery($querySearch: QuerySearchInput!) {
  searchQuery(querySearch: $querySearch) {
    name
    address
    rating
    foods {
      price
      name
    }
  }
}

Body :

{
  "querySearch": {
    "name": "kababi"
  }
}

Response:

{
  "data": {
    "searchQuery": [
      {
        "name": "kababi",
        "address": "1 London Bridge St, London SE1 9BG",
        "rating": 4,
        "foods": [
          {
            "price": 2000,
            "name": "kabab"
          },
          {
            "price": 200,
            "name": "mast"
          },
          {
            "price": 1000,
            "name": "gosht"
          },
          {
            "price": 3000,
            "name": "ghorme"
          }
        ]
      }
    ]
  }
}

These examples showcase a range of additional features and demonstrate how you can use GraphQL queries and mutations to interact with the RestaurantGraphQL API. Feel free to customize and extend them based on your specific requirements.

Contributing

If you encounter any issues or have suggestions for improvements, please submit an issue or a pull request to the GitHub repository.

License

The RestaurantGraphQL API is open-source and released under the GPL-V3.0 License. Feel free to use, modify, and distribute the code as per the terms of the license.

Copyright 2023, Max Base

restaurantgraphql's People

Contributors

dependabot[bot] avatar khalvai avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.