Skip to content

mfritschdotgo/techchallenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Skina Lanches Management API

Overview

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

Table of Contents

Setup

Docker Setup

To set up the application using Docker and building the image from this repository, follow these steps:

  1. Ensure you have Docker installed on your machine and be logged into a registry (optional).
  2. Ensure you have a mongodb installation.
  3. Clone the repository to your local machine.
  4. Navigate to the project directory.
  5. Build the Docker image using the provided Dockerfile:
    docker build -t yourRepository/skina-lanches-api:version .
  6. 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
  7. 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:

  1. Ensure you have Docker installed on your machine.
  2. Download the image:
    docker pull mrcsfritsch/skinaapis
  3. Ensure you have a mongodb installation.
  4. 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
    

Compose Setup

To set up the application using Docker compose, follow these steps:

  1. Ensure you have Docker engine and docker compose installed on your machine.
  2. Navigate to the compose directory.
  3. Edit the .env file, setting the environment variables as desired
  4. Start service from docker compose file, must be in the compose directory:
    docker compose up -d
    

Integrated testing via Swagger

  1. Access the skinaapis service address with the port defined in the .env file: http://127.0.0.1:9090/docs/index.html#/
  2. Add a client via the "post" method using the endpoint Clients.
  3. Get the category id that you will use when inserting a product, using the endpoint get method Categories
  4. Add a product via the "post" method using the endpoint Products
  5. 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.
  6. Add a request via the "post" method using the endpoint Orders
  7. 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

API Endpoints

Categories

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

Clients

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

Orders

  • 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 invalid
      • 500: Internal server error if there is a problem on the server side.

Products

  • 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

fakeCheckout

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published