The Skina Lanches Management API is designed to facilitate the management of products, categories, clients, and orders for a sandwich shop. The API provides endpoints to create, read, update, and delete entities within the system. This project follows a hexagonal architecture and is based on a DDD (Domain driven design) generated from event storming in which the steps can be analyzed in: https://miro.com/app/board/uXjVKTBf0pw=/?share_link_id=516597082495 The image for this project is also available on docker hub: https://hub.docker.com/r/mrcsfritsch/skinaapis
To set up the application using Docker and building the image from this repository, follow these steps:
- Ensure you have Docker installed on your machine and be logged into a registry (optional).
- Ensure you have a mongodb installation.
- Clone the repository to your local machine.
- Navigate to the project directory.
- Build the Docker image using the provided Dockerfile:
docker build -t yourRepository/skina-lanches-api:version .
- Run the Docker container:
docker run -p 9090:9090 -e MONGO_USER=user -e MONGO_PASSWORD=password -e MONGO_PORT=port -e MONGO_HOST=localhost -e MONGO_DATABASE=database yourRepository/skina-lanches-api:version
- Uploading the image to a registry:
docker push yourRepository/skina-lanches-api:version
To set up the application using Docker using the official image available on docker hub, follow these steps:
- Ensure you have Docker installed on your machine.
- Download the image:
docker pull mrcsfritsch/skinaapis
- Ensure you have a mongodb installation.
- Run the Docker container:
docker run -p 9090:9090 -e MONGO_USER=user -e MONGO_PASSWORD=password -e MONGO_PORT=port -e MONGO_HOST=localhost -e MONGO_DATABASE=database mrcsfritsch/skinaapis
To set up the application using Docker compose, follow these steps:
- Ensure you have Docker engine and docker compose installed on your machine.
- Navigate to the compose directory.
- Edit the .env file, setting the environment variables as desired
- Start service from docker compose file, must be in the compose directory:
docker compose up -d
- Access the skinaapis service address with the port defined in the .env file: http://127.0.0.1:9090/docs/index.html#/
- Add a client via the "post" method using the endpoint Clients.
- Get the category id that you will use when inserting a product, using the endpoint get method Categories
- Add a product via the "post" method using the endpoint Products
- Get the ids of the products that you will insert in your order, using the endpoint's get method Products, it is possible via query param to search by category.
- Add a request via the "post" method using the endpoint Orders
- Simulate a fake checkout through the endpoint using method post FakeCheckout, this will change the order status to finished.
Obs.: Through swagger for more details about the APIs
-
GET /categories
- Retrieves a paginated list of categories.
- Parameters:
page
(integer, default: 1): Page number for pagination.pageSize
(integer, default: 10): Number of categories per page.
- Responses:
200
: Successfully retrieved list of categories.500
: Internal server error if there is a problem on the server side.
-
POST /categories
- Adds a new category to the database.
- Body:
dto.CreateCategoryRequest
- Responses:
201
: Successfully created category.400
: Bad request if the category data is invalid.500
: Internal server error if there is a problem on the server side.
-
GET /categories/{id}
- Retrieves details of a category by its ID.
- Parameters:
id
(string): Category ID.
- Responses:
200
: Successfully retrieved the category details.400
: Bad request if the ID is not provided or invalid.404
: Category not found if the ID does not match any category.500
: Internal server error if there is a problem on the server side.
-
PUT /categories/{id}
- Replaced category by its ID.
- Parameters:
id
(string): Category ID.
- Body:
dto.CreateCategoryRequest
- Responses:
200
: Successfully updated category.400
: Invalid input, object is invalid.404
: Category not found.500
: Internal server error.
-
DELETE /categories/{id}
- Deletes a category by its ID.
- Parameters:
id
(string): Category ID.
- Responses:
200
: Message indicating successful deletion.400
: Bad request if the ID is not provided or is invalid.404
: Category not found if the ID does not match any category.500
: Internal server error if there is a problem deleting the category.
-
Patch /categories/{id}
- Update a category by its ID.
- Parameters:
id
(string): Category ID.
- Responses:
200
: Message indicating successful deletion.400
: Bad request if the ID is not provided or is invalid.404
: Category not found if the ID does not match any category.500
: Internal server error if there is a problem deleting the category.
-
POST /clients
- Adds a new client to the database.
- Body:
dto.CreateClientRequest
- Responses:
201
: Client successfully created.400
: Bad request if the client data is invalid.500
: Internal server error if there is a problem on the server side.
-
GET /clients/{cpf}
- Retrieves details of a client by its CPF.
- Parameters:
cpf
(string): Client CPF.
- Responses:
200
: Successfully retrieved the client details.400
: Bad request if the CPF is not provided or invalid.404
: Client not found if the CPF does not match any client.500
: Internal server error if there is a problem on the server side.
-
GET /orders
- Retrieves a paginated list of orders.
- Parameters:
page
(integer, default: 1): Page number for pagination.pageSize
(integer, default: 10): Number of orders per page.
- Responses:
200
: Successfully retrieved list of orders.500
: Internal server error if there is a problem on the server side.
-
POST /orders
- Adds a new order to the database.
- Body:
dto.CreateOrderRequest
- Responses:
201
: Successfully created order.400
: Bad request if the order data is invalid.500
: Internal server error if there is a problem on the server side.
-
GET /orders/{id}
- Retrieves details of an order by its ID.
- Parameters:
id
(string): Order ID.
- Responses:
200
: Successfully retrieved the order details.400
: Bad request if the ID is not provided or invalid.404
: Order not found if the ID does not match any order.500
: Internal server error if there is a problem on the server side.
-
PATCH /orders/{id}/{status}
- Update the status of an order
- Parameters:
id
(string): Order ID.status
(string): status.
- Responses:
200
: Successfully status updated.400
: Bad request if the Status is not provided or invalid500
: Internal server error if there is a problem on the server side.
-
GET /products
- Retrieves a paginated list of products, optionally filtered by category.
- Parameters:
category
(string, optional): Filter by category ID.page
(integer, default: 1): Page number for pagination.pageSize
(integer, default: 10): Number of products per page.
- Responses:
200
: Successfully retrieved list of products.500
: Internal server error if there is a problem on the server side.
-
POST /products
- Adds a new product to the database.
- Body:
dto.CreateProductRequest
- Responses:
201
: Product successfully created.400
: Bad request if the product data is invalid.500
: Internal server error if there is a problem on the server side.
-
GET /products/{id}
- Retrieves details of a product by its ID.
- Parameters:
id
(string): Product ID.
- Responses:
200
: Successfully retrieved the product details.400
: Bad request if the ID is not provided or invalid.404
: Product not found if the ID does not match any product.500
: Internal server error if there is a problem on the server side.
-
PUT /products/{id}
- Replaced product by its ID.
- Parameters:
id
(string): Product ID.
- Body:
dto.CreateProductRequest
- Responses:
200
: Product successfully updated.400
: Invalid input, object is invalid.404
: Product not found.500
: Internal server error.
-
PATCH /products/{id}
- Updates product details by its ID.
- Parameters:
id
(string): Product ID.
- Body:
dto.CreateProductRequest
- Responses:
200
: Product successfully updated.400
: Invalid input, object is invalid.404
: Product not found.500
: Internal server error.
-
DELETE /products/{id}
- Deletes a product by its ID.
- Parameters:
id
(string): Product ID.
- Responses:
200
: Message indicating successful deletion.400
: Bad request if the ID is not provided or is invalid.404
: Product not found if the ID does not match any product.500
: Internal server error if there is a problem deleting the product.# techchallenge
- POST /fakeCheckout/{id}
- Adds a new client to the database.
- Parameters:
id
(string): Product ID.
- Body:
dto.CreateClientRequest
- Responses:
200
: Successfully fake checkout.400
: Bad request if the ID is not provided or invalid.500
: Internal server error if there is a problem on the server side.