Skip to content

feat: create a new product

Paul Jarleton requested to merge feat/#7_product_create into main

Summary

It adds a POST /products route that creates a new product.

What's in the box

Error handling

This PR introduce a better error channel with a refinement at the end of the chain allowing each layer of the application to return their own shaped error that will be later on converted into an ApiError.

Sql statements

Even tho it is not yet within the application itself (for now) this PR changed the shape of the database as follow:

CREATE TABLE inventory (
    art_id        int CONSTRAINT inventory_unique_article_id PRIMARY KEY,
    name          varchar NOT NULL,
    stock         integer NOT NULL CHECK ( stock >= 0 )
);

CREATE TABLE products (
    id          SERIAL PRIMARY KEY,
    name        varchar NOT NULL
);

CREATE TABLE product_to_inventory (
    product_id   int,
    amount_of    int NOT NULL CHECK (amount_of > 0),
    art_id       int,
    CONSTRAINT pti_product_id_exist
        FOREIGN KEY(product_id)
              REFERENCES products(id),
    CONSTRAINT pti_art_id_exist
        FOREIGN KEY(art_id)
              REFERENCES inventory(art_id)
);

It name all the constraints so that the error handling can differentiate different situation.

Other changes

Fix on POST /inventory route

Inventory was failing due to content type not being right in the send part, this PR fix it.

codecs has been moved under codecs folder

Merge request reports