Grabtot / Pizza-Api

0 stars 0 forks source link

Tags and allergens #25

Closed Grabtot closed 2 months ago

Grabtot commented 2 months ago

Endpoints

Allergens

Tags

Tag

Class description

The Tag class represents a marker in pizza or ingredients which indicates a property or type, such as meat, fish, cheese, etc. The class has 2 main properties: Name and Color. Name represents the name of the Tag and also serves as the tag's unique identifier instead of Id. Tags are compared using the NormalizedName property, which represents a case-insensitive Name.

Endpoints

All Tag endpoints have the path domain.com/api/tags and differ only in the HTTP Methods. Closes #24

GET Method

Returns all existing Tags.

Response example Path - GET domain.com/api/tags

[
    {
        "name": "meat",
        "color": -16711936
    },
    {
        "name": "fish",
        "color": -2147483393
    },
    {
        "name": "vegetarian",
        "color": 0 // 0 if color is null
    }
]

POST Method

Creates a new Tag. Requires Name and Color in the body. Color must be in ARGB number format. Color is nullable.

Request examples Path - POST domain.com/api/tags

{
    "name": "meat",
    "color": -16711936
}
{
    "name": "vegetarian"
}

Responses

PUT Method

Updates an existing Tag. Requires CurrentName as an identifier, and nullable NewName and nullable Color. If Color in the request is null, the Color in the tag will be set to null. Color must be in ARGB number format. If NewName is not null, the tag's Name will change if a Tag with this name doesn't exist.

Request examples Path - PUT domain.com/api/tags

Vegetarian's tag Color will change:

{
    "currentName": "vegetarian",
    "color": -2147418368
}

Vegetarian's tag will be renamed to fruit:

{
    "currentName": "vegetarian",
    "newName": "fruit",
    "color": -2147418368
}

Responses

DELETE Method

Deletes the Tag with the Name provided in the query parameter.

Request example Path - DELETE domain.com/api/tags?name=meat

Responses

Allergen

Class description

The Allergen class represents a marker for allergens in pizza or ingredients, such as peanut, gluten, dairy, etc. The class has 2 main properties: Name and Description. Name represents the name of the Allergen and serves as the allergen's unique identifier. Description provides detailed information about the allergen and its presence in various foods. Allergens are compared using the NormalizedName property, which represents a case-insensitive Name.

Endpoints

All Allergen endpoints have the path domain.com/api/tags and differ only in the HTTP Methods. Closes #23

GET Method

Returns all existing Allergens.

Response example Path - GET domain.com/api/allergens

[
    {
        "name": "Peanut",
        "description": "Contains peanuts which are found in many processed foods such as peanut butter, candies, cookies, and some sauces"
    },
    {
        "name": "Gluten",
        "description": null
    }
]

POST Method

Creates a new Allergen. Requires Name and Description in the body. Description is nullable.

Request examples Path - POST domain.com/api/allergens

{
    "name": "Peanut",
    "description": "Contains peanuts which..."
}
{
    "name": "Gluten"
}

Responses

PUT Method

Updates an existing Allergen. Requires CurrentName as an identifier, and nullable NewName and nullable Description. If Description in the request is null, the Description in the allergen will be set to null. If NewName is not null, the allergen's Name will change if a Allergen with this name doesn't exist.

Request examples Path - PUT domain.com/api/tags

Peanut's allergen Description will change:

{
    "currentName": "Peanut",
    "description": null
}

Peanut's allergen will be renamed to fruit and Description will be null:

{
    "currentName": "vegetarian",
    "newName": "fruit"
}

Responses

DELETE Method

Deletes the Allergen with the Name provided in the query parameter.

Request example Path - DELETE domain.com/api/allergens?name=meat

Responses