Code Monkey home page Code Monkey logo

pizza-shop's Introduction

PizzaShop

This is a pizzashop API built with Ruby on Rails. It features three models: Restaurant, Pizza, and RestaurantPizza. The Restaurant model has a name and an address, while the Pizza model has a name and an ingredient. The RestaurantPizza model serves as a join table between Restaurant and Pizza, and has a price attribute.

live link

Topics

  • Models
  • Associations
  • Validations
  • Routes, Controllers, and REST

Instructions

Installation

To get started, clone the repository and navigate to the project directory:

git clone https://github.com/abdishukri-105/pizza-shop

cd pizza-shop

Then, install the required dependencies using Bundler:

bundle install

run the migrations:

rails db:migrate

Usage

Start the server with:

rails server

Table

Restaurant Table

Column Type
name String

Pizzas Table

Column Type
name String
ingredient String

restaurant_pizzas Table

Column Type
pizza_id integer
price Integer
restaurant_id integer

Validations

Add validations to the RestaurantPizza model:

  • must have a price between 1 and 30

Routes

GET /restaurants

Response

[
  {
    "id": 1,
    "name": "Sottocasa NYC",
    "address": "298 Atlantic Ave, Brooklyn, NY 11201"
  },
  {
    "id": 2,
    "name": "PizzArte",
    "address": "69 W 55th St, New York, NY 10019"
  }
]

GET /restaurants/:id

If the Restaurant exists, returns

{
  "id": 1,
  "name": "Sottocasa NYC",
  "address": "298 Atlantic Ave, Brooklyn, NY 11201",
  "pizzas": [
    {
      "id": 1,
      "name": "Cheese",
      "ingredients": "Dough, Tomato Sauce, Cheese"
    },
    {
      "id": 2,
      "name": "Pepperoni",
      "ingredients": "Dough, Tomato Sauce, Cheese, Pepperoni"
    }
  ]
}

If the Restaurant does not exist, returns the following JSON data

{
  "error": "Restaurant not found"
}

DELETE /restaurants/:id

If the Restaurant exists, it should be removed from the database, along with any RestaurantPizzas that are associated with it (a RestaurantPizza belongs to a Restaurant, so you need to delete the RestaurantPizzas before the Restaurant can be deleted). After deleting the Restaurant, return an empty response body, along with the appropriate HTTP status code. If the Restaurant does not exist, returns the following JSON data, along with the appropriate HTTP status code:

{
  "error": "Restaurant not found"
}

GET /pizzas Returns

[
  {
    "id": 1,
    "name": "Cheese",
    "ingredients": "Dough, Tomato Sauce, Cheese"
  },
  {
    "id": 2,
    "name": "Pepperoni",
    "ingredients": "Dough, Tomato Sauce, Cheese, Pepperoni"
  }
]

POST /restaurant_pizzas

This route creates a new RestaurantPizza that is associated with an existing Pizza and Restaurant. It accepts an object with the following properties in the body of the request:

{
  "price": 5,
  "pizza_id": 1,
  "restaurant_id": 3
}

If the RestaurantPizza is created successfully, it sends back a response with the data related to the Pizza:

{
  "id": 1,
  "name": "Cheese",
  "ingredients": "Dough, Tomato Sauce, Cheese"
}

If the RestaurantPizza is not created successfully, returns the following JSON data, along with the appropriate HTTP status code:

{
  "errors": ["validation errors"]
}

LICENSE

This repository is distributed under the ISC License

Author

This repository is maintained by:

  • Abdishukri Mohamed

pizza-shop's People

Contributors

abdishukri-105 avatar

Watchers

 avatar  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.