Skip to content
Snippets Groups Projects

Here's the documentation for the API endpoints based on the provided code:

API Documentation

Base URL

All endpoints are prefixed with /api. For example, to access the addArticle endpoint, use /api/article/addArticle.

Content-Type

All endpoints expect requests to have a Content-Type of application/json unless specified otherwise.

Endpoints

Article Management

1. Add an Article

  • URL: /api/article/addArticle
  • Method: POST
  • Description: Adds a new article to the system.
  • Request Body:
    {
      "preis": number,
      "beschreibung": "string",
      "name": "string"
    }
  • Response:
    • 200 OK if the article was added successfully.
    • 400 Bad Request if the request body is invalid.

2. Get Product by Criteria

  • URL: /api/article/getProductByCriteria
  • Method: GET
  • Description: Retrieves a product based on either its id or name.
  • Query Parameters:
    • id: Product ID (number)
    • name: Product name (string)
  • Response:
    • 200 OK with the product details if found.
    • 400 Bad Request if the criteria are invalid.
    • 404 Not Found if no product matches the criteria.

3. Get All Products

  • URL: /api/article/getAllProducts
  • Method: GET
  • Description: Retrieves all products in the system.
  • Response:
    • 200 OK with a list of all products.

Shopping Cart Management

1. Create a Shopping Cart

  • URL: /api/shoppingCart/createShoppingCart
  • Method: POST
  • Description: Creates a new shopping cart.
  • Request Body:
    {
      "name": "string",
      "beschreibung": "string"
    }
  • Response:
    • 200 OK if the shopping cart was created successfully.
    • 400 Bad Request if the request body is invalid.

2. Get All Shopping Carts

  • URL: /api/shoppingCart/getAllShoppingCart
  • Method: GET
  • Description: Retrieves all shopping carts in the system.
  • Response:
    • 200 OK with a list of all shopping carts.

3. Get Shopping Cart by Criteria

  • URL: /api/shoppingCart/getShoppingCartByCriteria
  • Method: GET
  • Description: Retrieves a shopping cart based on either its id or name.
  • Query Parameters:
    • id: Cart ID (number)
    • name: Cart name (string)
  • Response:
    • 200 OK with the shopping cart details if found.
    • 400 Bad Request if the criteria are invalid.
    • 404 Not Found if no cart matches the criteria.

Order Management

1. Add New Item to Order

  • URL: /api/order/addNewItemToOrder
  • Method: POST
  • Description: Adds a new item to an existing shopping cart order.
  • Request Body:
    {
      "itemId": number,
      "cartId": number,
      "quantity": number
    }
  • Response:
    • 200 OK if the item was added successfully.
    • 400 Bad Request if the request body is invalid.

2. Get Items in Cart

  • URL: /api/order/getItemsInCart
  • Method: GET
  • Description: Retrieves all items in a specified shopping cart.
  • Query Parameters:
    • cartId: Cart ID (number)
  • Response:
    • 200 OK with a list of items in the cart.
    • 400 Bad Request if the cartId is not provided or invalid.
    • 404 Not Found if the cart does not exist.

3. Update Product Quantity in Cart

  • URL: /api/order/updateProductMenge
  • Method: PUT
  • Description: Updates the quantity of a specific product in the cart.
  • Request Body:
    {
      "cartId": number,
      "articleId": number,
      "newQuantity": number
    }
  • Response:
    • 200 OK if the quantity was updated successfully.
    • 400 Bad Request if the request body is invalid.
    • 404 Not Found if the cart or article does not exist.

Middleware

All routes that modify data (POST, PUT) use a middleware function called check to validate request bodies. This middleware checks for the presence and type of required fields based on the endpoint specifications.

Error Codes

  • 400 Bad Request: The request was invalid or malformed.
  • 404 Not Found: The specified resource could not be found.
  • 200 OK: The request was successful.

Example Requests

Add an Article

POST /api/article/addArticle
Content-Type: application/json

{
  "preis": 15.99,
  "beschreibung": "A new gadget",
  "name": "Gadget Pro"
}

Get Shopping Cart by ID

GET /api/shoppingCart/getShoppingCartByCriteria?id=123

Update Product Quantity in Cart

PUT /api/order/updateProductMenge
Content-Type: application/json

{
  "cartId": 1,
  "articleId": 101,
  "newQuantity": 3
}

This documentation provides an overview of the available endpoints, their parameters, expected request formats, and possible responses.