{"id":19326188,"url":"https://github.com/marlinsk/small-sales-system","last_synced_at":"2026-04-11T05:03:46.741Z","repository":{"id":211830902,"uuid":"722360266","full_name":"Marlinsk/small-sales-system","owner":"Marlinsk","description":"Small sales system developing for technical studies about communication between microsservices. For this project we used Java, Springboot, Node.js, Typescript, Babel, MongoDB, Postgresql, Docker, Rabbitmq.","archived":false,"fork":false,"pushed_at":"2023-12-11T03:39:34.000Z","size":740,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-06T06:44:00.238Z","etag":null,"topics":["api-rest","axios","babel","docker","docker-compose","expressjs","java-17","javascript","jwt-authentication","maven","microservices","mongodb","mongoose","nodejs","postrgresql","rabbitmq","sequelize-orm","spring-boot","typescript"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Marlinsk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-23T01:25:31.000Z","updated_at":"2023-12-11T03:50:36.000Z","dependencies_parsed_at":"2023-12-11T07:38:34.615Z","dependency_job_id":null,"html_url":"https://github.com/Marlinsk/small-sales-system","commit_stats":null,"previous_names":["marlinsk/small-sales-system"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marlinsk%2Fsmall-sales-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marlinsk%2Fsmall-sales-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marlinsk%2Fsmall-sales-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Marlinsk%2Fsmall-sales-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Marlinsk","download_url":"https://codeload.github.com/Marlinsk/small-sales-system/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240427313,"owners_count":19799471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-rest","axios","babel","docker","docker-compose","expressjs","java-17","javascript","jwt-authentication","maven","microservices","mongodb","mongoose","nodejs","postrgresql","rabbitmq","sequelize-orm","spring-boot","typescript"],"created_at":"2024-11-10T02:12:44.280Z","updated_at":"2025-11-17T05:02:46.432Z","avatar_url":"https://github.com/Marlinsk.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"assets/add-to-cart.png\" width=\"36px\" height=\"36px\"\u003e Microservices-based Small Sales System Application\nSales management system developed using the microservices architecture and technologies such as **Java, Spring Boot, Javascript + Typescript, Node.js, Rabbitmq, Docker.**\n\nThe project was developed for study purposes in terms of concept, functionality, applicability, and scenarios where this type of architecture fits, such as banks, customer service, and e-commerce.\n\n## Technologies\nThe applications of this project use:\n- Java 17\n- Spring Boot 3\n- Spring Cloud OpenFeign\n- Apache Maven\n- Javascript\n- Typescript\n- Node.js 19\n- Express.js\n- Babel (Build generator)\n- Sequelize (Object-Relational Mapping)\n- MongoDB\n- PostgreSQL\n- RabbitMQ \n- API REST\n- Docker\n- docker-compose\n- JWT\n- Axios\n\n## Architecture\nThe project was developed following the architecture below:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"architecture\" src=\"assets/Architecture.drawio.png\"/\u003e\n\u003c/p\u003e\n\n## In-depth description of the application\nThe applications communicate with each other to execute the authentication validation process and update the status of a product sales order in the database. Much of this communication takes place between the **Product API** and **Sales API,** which complement each other. \n\nThe **Product API** is responsible for product management, while the **Sales API** handles order placement.\n\n### Tech descripiton of applications\n- **Auth-API:** Authentication API with Node.js 19, Express.js, Typescript, Sequelize, PostgreSQL, JWT, Bcryptjs, Babel.\n- **Sales-API:** Sales API with Node.js 19, Express.js, Typescript, MongoDB, Mongoose, Babel, JWT validation, RabbitMQ, and Axios for HTTP clients.\n- **Product-API:** Product API with Java 17, Spring Boot, Spring Data JPA, PostgreSQL, JWT validation, RabbitMQ, and Spring Cloud OpenFeign for HTTP clients.\n\n### Order Execution Flow\nThe flow for placing an order will depend on both synchronous communications (HTTP calls via REST) and asynchronous messaging with **RabbitMQ.**\n\nThe flow is described below:\n\n* 01 - The flow begins by making a request to the order creation endpoint.\n* 02 - The input payload (JSON) will be a list of products indicating the ID and desired quantity.\n* 03 - Before creating the order, a REST call will be made to the Products API to validate if there is sufficient stock for the purchase of all products.\n* 04 - If any product is out of stock, the Products API will return an error, and the Sales API will throw an error message indicating insufficient stock.\n* 05 - If there is sufficient stock, an order will be created and saved in MongoDB with a pending status (PENDING).\n* 06 - Upon saving the order, a message will be published on RabbitMQ, indicating the ID of the created order, along with the products and their respective IDs and quantities.\n* 07 - The Products API will be listening to the queue and will receive the message.\n* 08 - Upon receiving the message, the API will revalidate the stock of the products, and if everything is okay, it will update the stock of each product.\n* 09 - If the stock is successfully updated, the Products API will publish a message on the sales confirmation queue with a status of APPROVED.\n* 10 - If there is an issue with the update, the Products API will publish a message on the sales confirmation queue with a status of REJECTED.\n* 11 - Finally, the Orders API will receive the confirmation message and update the order with the status returned in the message.\n\n## Cloning and running the project with docker \n**Note:** To run this project, it is necessary to have Docker installed on your machine.\n\n**1º step: clone the repository to your machine from GitHub.**\n```bash\ngit clone https://github.com/Marlinsk/small-sales-system.git\n```\n\n**2º step: Navigate to the project folder.**\n```bash\ncd small-sales-system\n```\n\n**3º step: Run this docker-compose command to build the images and start the containers.**\n```bash\ndocker-compose build\n```\n\n**Run this command to execute the tasks in the background.**\n```bash\ndocker-compose build -d\n```\n\nAfter everything is up and running, just open any request tool and play around.\n\n## Endpoints description\nThe Auth-API application features a single endpoint dedicated to authentication.\n\nThe Product-API application is composed of three modules, each hosting multiple endpoints catering to products, categories, and suppliers.\n\nConversely, the Sales-API application is streamlined with just four endpoints.\n\n**Notes:** \n - In some projects, data is generated during the initialization execution.\n - All endpoints in the Product-API and Sales-API services require the authorization and transactionid headers.\n\n### Auth-API\nBase URL: http://localhost:8080\n\n**POST** Performs user login:\n\nValidates user credentials and generates the user authentication token on the platform.\n\n\u003e /api/user/auth\n\nBody:\n\n```json\n{\n    \"email\": \"haroldstriker@outlook.com\",\n    \"password\": \"123456pipboy\"\n}\n```\n\nResponse example:\n\n```json\n{\n    \"status\": 200,\n    \"accessToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRoVXNlciI6eyJpZCI6MSwibmFtZSI6Ikhhcm9sZCBTdHJpa2VyIiwiZW1haWwiOiJoYXJvbGRzdHJpa2VyQG91dGxvb2suY29tIn0sImlhdCI6MTcwMjI1MjQxNywiZXhwIjoxNzAyMzM4ODE3LCJzdWIiOiIxIn0.rjwc7BEwXcIQqe7vQ-QUqiOT7kAp7CbLIjKwLE_-O_o\"\n}\n```\n\n**GET** Displays the email of the authenticated user:\n\nProvide the email of the authenticated user in the parameters, and then make the request.\n\n\u003e /api/user/email/:email\n\n### Product-API\nBase URL: http://localhost:8081\n\n#### Product Module\n\n**POST** Create a new product\n\nTo create a product, it is necessary to provide the category ID, supplier ID, product name, and quantity.\n\n\u003e /api/product\n\nBody:\n\n```json\n{\n    \"name\": \"Processor Intel Core i9-13900K, 13th Generation, 5.8GHz Max Turbo, 36MB Cache, 24 Cores, LGA 1700, Integrated Graphics - BX8071513900K\",\n    \"quantity_available\": 3,\n    \"supplierId\": 1001,\n    \"categoryId\": 1001\n}\n```\n\nResponse (params.id = 1004):\n\n```json\n{\n    \"id\": 1004,\n    \"name\": \"Processor Intel Core i9-13900K, 13th Generation, 5.8GHz Max Turbo, 36MB Cache, 24 Cores, LGA 1700, Integrated Graphics - BX8071513900K\",\n    \"supplier\": {\n        \"id\": 1001,\n        \"name\": \"Intel\"\n    },\n    \"category\": {\n        \"id\": 1001,\n        \"description\": \"Hardware\"\n    },\n    \"quantity_available\": 3,\n    \"created_at\": \"09/12/2023 16:05:43\"\n    \"updated_at\": \"09/12/2023 16:05:43\"\n}\n```\n\n**PUT** Update a product\n\nInclude the product ID in the URL parameters of the request, and change the body.\n\n\u003e /api/product/{id}\n\nBody:\n\n```json\n{\n    \"name\": \"Processor Intel Core i9-13900K, 13th Generation, 5.8GHz Max Turbo, 36MB Cache, 24 Cores, LGA 1700, Integrated Graphics - BX8071513900K\",\n    \"quantity_available\": 3,\n    \"supplierId\": 1001,\n    \"categoryId\": 1001\n}\n```\n\nResponse:\n\n```json\n{\n    \"id\": 1,\n    \"name\": \"Processor Intel Core i9-13900K, 13th Generation, 5.8GHz Max Turbo, 36MB Cache, 24 Cores, LGA 1700, Integrated Graphics - BX8071513900K\",\n    \"supplier\": {\n        \"id\": 1001,\n        \"name\": \"Intel\"\n    },\n    \"category\": {\n        \"id\": 1001,\n        \"description\": \"Hardware\"\n    },\n    \"quantity_available\": 7,\n    \"created_at\": \"09/12/2023 16:05:43\"\n    \"updated_at\": \"09/12/2023 16:08:48\"\n}\n```\n\n**DELETE** Remove a product by id\n\nInclude the product ID in the URL parameters of the request.\n\n\u003e /api/product/{id}\n\nResponse (params.id = 1002):\n\n```json\n{\n    \"status\": 200,\n    \"message\": \"The product was deleted.\"\n}\n```\n\n**GET** Get all products\n\nRetrieve all products that are stored in the database.\n\n\u003e /api/product\n\nResponse:\n\n```json\n[\n    {\n        \"id\": 1001,\n        \"name\": \"Processador Intel Core i7-10700KF, 10ª Geração, 3.8GHz (5.1GHz Max Turbo), Cache 16MB, LGA 1200 - BX8070110700KF\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 5,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    },\n    {\n        \"id\": 1002,\n        \"name\": \"Processador Intel Core i9-11900K, 11ª Geração, 3.5 GHz (5.1GHz Turbo), Cache 16MB, Octa Core, LGA1200, Vídeo Integrado - BX8070811900K\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 3,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    },\n    {\n        \"id\": 1003,\n        \"name\": \"Processador Intel Core i9-12900F, 12ª Geração, Cache 30MB, 2.4GHz (5.1GHz Max Turbo), LGA 1700 - BX8071512900F\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 4,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    }\n]\n```\n\n**GET** Get product by ID\n\nInclude the product ID in the URL parameters of the request.\n\n\u003e /api/product/{id}\n\nResponse (params.id = 1001):\n\n```json\n{\n    \"id\": 1001,\n    \"name\": \"Processador Intel Core i7-10700KF, 10ª Geração, 3.8GHz (5.1GHz Max Turbo), Cache 16MB, LGA 1200 - BX8070110700KF\",\n    \"category\": {\n        \"id\": 1001,\n        \"description\": \"Hardware\"\n    },\n    \"supplier\": {\n        \"id\": 1001,\n        \"name\": \"Intel\"\n    },\n    \"quantity_available\": 5,\n    \"created_at\": \"10/12/2023 19:24:23\",\n    \"updated_at\": \"10/12/2023 19:24:23\"\n}\n```\n\n**GET** Get products by name (without case sensitive)\n\nInclude the product name in the URL parameters of the request.\n\n\u003e /api/product/name/{name}\n\nResponse (params.name = \"Pro\"):\n\n```json\n[\n    {\n        \"id\": 1001,\n        \"name\": \"Processador Intel Core i7-10700KF, 10ª Geração, 3.8GHz (5.1GHz Max Turbo), Cache 16MB, LGA 1200 - BX8070110700KF\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 5,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    },\n    {\n        \"id\": 1002,\n        \"name\": \"Processador Intel Core i9-11900K, 11ª Geração, 3.5 GHz (5.1GHz Turbo), Cache 16MB, Octa Core, LGA1200, Vídeo Integrado - BX8070811900K\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 3,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    }\n]\n```\n\n**GET** Get products by category ID:\n\nInclude the category ID in the URL parameters of the request.\n\n\u003e /api/product/category/{categoryId}\n\nResponse (params.categoryId = 1001):\n\n```json\n[\n    {\n        \"id\": 1001,\n        \"name\": \"Processador Intel Core i7-10700KF, 10ª Geração, 3.8GHz (5.1GHz Max Turbo), Cache 16MB, LGA 1200 - BX8070110700KF\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 5,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    },\n    {\n        \"id\": 1002,\n        \"name\": \"Processador Intel Core i9-11900K, 11ª Geração, 3.5 GHz (5.1GHz Turbo), Cache 16MB, Octa Core, LGA1200, Vídeo Integrado - BX8070811900K\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 3,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    },\n    {\n        \"id\": 1003,\n        \"name\": \"Processador Intel Core i9-12900F, 12ª Geração, Cache 30MB, 2.4GHz (5.1GHz Max Turbo), LGA 1700 - BX8071512900F\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1001,\n            \"name\": \"Intel\"\n        },\n        \"quantity_available\": 4,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    }\n]\n```\n\n**GET** Get products by supplier ID:\n\nInclude the supplier ID in the URL parameters of the request.\n\n\u003e  /api/product/supplier/{supplierId}\n\nResponse (params.supplierId = 1006):\n\n```json\n[\n    {\n        \"id\": 1008,\n        \"name\": \"Placa de Vídeo RTX 4060 1-Click OC 1X Galax NVIDIA GeForce, 8GB GDDR6, DLSS, Ray Trancing, G-Sync\",\n        \"category\": {\n            \"id\": 1001,\n            \"description\": \"Hardware\"\n        },\n        \"supplier\": {\n            \"id\": 1006,\n            \"name\": \"Galax\"\n        },\n        \"quantity_available\": 6,\n        \"created_at\": \"10/12/2023 19:24:23\",\n        \"updated_at\": \"10/12/2023 19:24:23\"\n    }\n]\n```\n\n**POST** Check product quantity availabel:\n\nCheck if the provided quantity is compatible with the availability.\n\n\u003e /api/product/check-stock\n\nBody:\n\n```json\n{\n    \"products\": [\n        {\n            \"productId\": 1001,\n            \"quantity\": 1\n        },\n        {\n            \"productId\": 1002,\n            \"quantity\": 1\n        },\n        {\n            \"productId\": 1003,\n            \"quantity\": 1\n        }\n    ]\n}\n```\n\nResponse:\n\n```json\n{\n    \"status\": 200,\n    \"message\": \"The stock is ok!\"\n}\n```\n\n**GET** List product sales ID\n\nRetrieve the product along with all the IDs of the orders placed for it.\n\n\u003e /api/product/{productId}/sales\n\nResponse:\n\n```json\n{\n    \"id\": 1001,\n    \"name\": \"Graphics Card Gigabyte NVIDIA GeForce GTX 1650 D6 OC 4G, 4GB GDDR6, REV 4.0 - GV-N1656OC-4GD 4.0\",\n    \"supplier\": {\n        \"id\": 1005,\n        \"name\": \"GigaByte\"\n    },\n    \"category\": {\n        \"id\": 1000,\n        \"description\": \"Hardware\"\n    },\n    \"sales\": [\n        \"6161cd32560fbede60d48efc\",\n        \"6161cd32560fbede60d48efe\",\n        \"6161d007560fbede60d48f01\"\n    ],\n    \"quantity_available\": 3,\n    \"created_at\": \"09/12/2023 14:11:15\"\n    \"updated_at\": \"09/12/2023 14:11:15\"\n}\n```\n\n#### Supplier Module\n\n**POST** Create a new supplier\n\n\u003e /api/supplier\n\nBody:\n\n```json\n{\n    \"name\": \"Amazon\"\n}\n```\n\nResponse:\n\n```json\n{\n    \"id\": 1,\n    \"name\": \"Amazon\"\n}\n```\n\n**PUT** Update supplier by ID\n\nInclude the supplier ID in the URL parameters of the request.\n\n\u003e /api/supplier/{id}\n\nBody:\n\n```json\n{\n    \"name\": \"Amazon BR\"\n}\n```\n\nResponse:\n\n```json\n{\n    \"id\": 1,\n    \"name\": \"Amazon BR\"\n}\n```\n\n**DELETE** Delete supplier by ID\n\nInclude the supplier ID in the URL parameters of the request.\n\n\u003e /api/supplier/{id}\n\nResponse:\n\n```json\n{\n    \"status\": 200,\n    \"message\": \"The supplier was deleted.\"\n}\n```\n\n**GET** Get all supplier\n\nRetrieve all supplier that are stored in the database.\n\n\u003e /api/supplier\n\nResponse:\n\n```json\n[\n    {\n        \"id\": 1001,\n        \"name\": \"Intel\"\n    },\n    {\n        \"id\": 1002,\n        \"name\": \"AMD\"\n    },\n    {\n        \"id\": 1003,\n        \"name\": \"NVIDIA\"\n    },\n    {\n        \"id\": 1004,\n        \"name\": \"ASUS\"\n    },\n    {\n        \"id\": 1005,\n        \"name\": \"GigaByte\"\n    }\n]\n```\n\n**GET** Get supplier by ID\n\n\u003e /api/supplier/{id} \n\nResponse (params.id = 1004): \n\n```json\n{\n   \"id\": 1004,\n   \"name\": \"ASUS\"\n}\n```\n\n**GET** Get supplier by name\n\nInclude the suppliers name in the URL parameters of the request.\n\n\u003e /api/supplier/name/{name}\n\nResponse (params.name = ASUS): \n\n```json\n[\n  {\n     \"id\": 1004,\n     \"name\": \"ASUS\"\n  }\n]\n```\n\n#### Category Module\n\n**POST** Create a new category\n\n\u003e /api/category\n\nBody:\n\n```json\n{\n   \"description\": \"Games\"\n}\n```\n\nResponse:\n\n```json\n{\n   \"id\": 1,\n   \"description\": \"Games\"\n}\n```\n\n**PUT** Update category by ID\n\nInclude the category ID in the URL parameters of the request.\n\n\u003e /api/category/{id}\n\nBody:\n\n```json\n{\n   \"name\": \"Monitor\"\n}\n```\n\nResponse:\n\n```json\n{\n   \"id\": 1,\n   \"name\": \"Monitor\"\n}\n```\n\n**DELETE** Delete category by ID\n\nInclude the category ID in the URL parameters of the request.\n\n\u003e /api/category/{id}\n\nResponse:\n\n```json\n{\n   \"status\": 200,\n   \"message\": \"The category was deleted.\"\n}\n```\n\n**GET** Get all categories\n\nRetrieve all categories that are stored in the database.\n\n\u003e /api/category\n\nResponse:\n\n```json\n[\n  {\n    \"id\": 1001,\n    \"description\": \"Hardware\"\n  }\n]\n```\n\n**GET** Get category by ID\n\n\u003e /api/category/{id} \n\nResponse (params.id = 1001): \n\n```json\n{\n  \"id\": 1001,\n  \"description\": \"Hardware\"\n}\n```\n\n**GET** Get category by name\n\nInclude the category name in the URL parameters of the request.\n\n\u003e /api/category/name/{name}\n\nResponse (params.name = \"Hardware\"): \n\n```json\n[\n  {\n     \"id\": 1001,\n     \"name\": \"Hardware\"\n  }\n]\n```\n\n### Sales-API\nBase URL: http://localhost:8082\n\n**POST** Create a new order\n\n\u003e /api/order/create\n\nBody:\n\n```json\n{\n  \"products\": [\n    {\n      \"productId\": 1001,\n      \"quantity\": 1\n    },\n    {\n      \"productId\": 1018,\n      \"quantity\": 1\n    },\n    {\n      \"productId\": 1021,\n      \"quantity\": 1\n    }\n  ]\n}\n```\n\nResponse:\n\n```json\n{\n    \"status\": 200,\n    \"order\": {\n        \"_id\": \"6576650891f50cf8744b0fe2\",\n        \"products\": [\n            {\n                \"productId\": \"1001\",\n                \"quantity\": 1,\n                \"_id\": \"6576650891f50cf8744b0fe3\"\n            },\n            {\n                \"productId\": \"1018\",\n                \"quantity\": 1,\n                \"_id\": \"6576650891f50cf8744b0fe4\"\n            },\n            {\n                \"productId\": \"1021\",\n                \"quantity\": 1,\n                \"_id\": \"6576650891f50cf8744b0fe5\"\n            }\n        ],\n        \"user\": {\n            \"id\": \"1\"\n        },\n        \"status\": \"PENDING\",\n        \"createdAt\": \"2023-12-11T01:25:28.804Z\",\n        \"updatedAt\": \"2023-12-11T01:25:28.804Z\"\n    }\n}\n```\n\n**GET** Get all orders\n\nRetrieve all orders that are stored in the database.\n\n\u003e /api/order\n\nResponse:\n\n```json\n{\n    \"status\": 200,\n    \"orders\": [\n        {\n            \"_id\": \"6576650891f50cf8744b0fe2\",\n            \"products\": [\n                {\n                    \"productId\": \"1001\",\n                    \"quantity\": 1,\n                    \"_id\": \"6576650891f50cf8744b0fe3\"\n                },\n                {\n                    \"productId\": \"1018\",\n                    \"quantity\": 1,\n                    \"_id\": \"6576650891f50cf8744b0fe4\"\n                },\n                {\n                    \"productId\": \"1021\",\n                    \"quantity\": 1,\n                    \"_id\": \"6576650891f50cf8744b0fe5\"\n                }\n            ],\n            \"user\": {\n                \"id\": \"1\"\n            },\n            \"status\": \"APPROVED\",\n            \"createdAt\": \"2023-12-11T01:25:28.804Z\",\n            \"updatedAt\": \"2023-12-11T01:25:29.013Z\"\n        },\n        {\n            \"_id\": \"6576652991f50cf8744b0fef\",\n            \"products\": [\n                {\n                    \"productId\": \"1001\",\n                    \"quantity\": 1,\n                    \"_id\": \"6576652991f50cf8744b0ff0\"\n                },\n                {\n                    \"productId\": \"1018\",\n                    \"quantity\": 1,\n                    \"_id\": \"6576652991f50cf8744b0ff1\"\n                },\n                {\n                    \"productId\": \"1021\",\n                    \"quantity\": 1,\n                    \"_id\": \"6576652991f50cf8744b0ff2\"\n                }\n            ],\n            \"user\": {\n                \"id\": \"1\"\n            },\n            \"status\": \"APPROVED\",\n            \"createdAt\": \"2023-12-11T01:26:01.687Z\",\n            \"updatedAt\": \"2023-12-11T01:26:01.826Z\"\n        }\n    ]\n}\n```\n\n**GET** Get order by ID\n\nInclude the order ID in the URL parameters of the request.\n\n\u003e /api/order/{id}\n\nResponse (params.id = \"6576652991f50cf8744b0fef\"):\n\n```json\n{\n    \"status\": 200,\n    \"order\": {\n        \"_id\": \"6576652991f50cf8744b0fef\",\n        \"products\": [\n            {\n                \"productId\": \"1001\",\n                \"quantity\": 1,\n                \"_id\": \"6576652991f50cf8744b0ff0\"\n            },\n            {\n                \"productId\": \"1018\",\n                \"quantity\": 1,\n                \"_id\": \"6576652991f50cf8744b0ff1\"\n            },\n            {\n                \"productId\": \"1021\",\n                \"quantity\": 1,\n                \"_id\": \"6576652991f50cf8744b0ff2\"\n            }\n        ],\n        \"user\": {\n            \"id\": \"1\"\n        },\n        \"status\": \"APPROVED\",\n        \"createdAt\": \"2023-12-11T01:26:01.687Z\",\n        \"updatedAt\": \"2023-12-11T01:26:01.826Z\"\n    }\n}\n```\n\n**GET** Get orders by product ID\n\nRetrieve all orders ID for a product.\n\n\u003e /api/orders/products/{productId}\n\nResponse (params.id = 1018):\n\n```json\n{\n    \"status\": 200,\n    \"salesIds\": [\n        \"6576650891f50cf8744b0fe2\",\n        \"6576652991f50cf8744b0fef\"\n    ]\n}\n```\n\n## Logs and Tracing\nAll endpoints require a header named **transactionid** as it will represent the ID that will traverse the entire request within the service. In case this application calls other microservices, this **transactionid** will be forwarded. All input and output endpoints will log the input data (JSON or parameters) and the **transactionid**.\n\nFor each request to each microservice, we will have a **serviceid** attribute generated solely for the logs of that specific service. We will then have the **transactionid** circulating among all the microservices involved in the request, and each microservice will have its own **serviceid**.\n\nRequest tracing flow:\n\n**POST** - **/api/order** with **transactionid**: ef8347eb-2207-4610-86c0-657b4e5851a3\n\n```\nservice-1:\ntransactionid: ef8347eb-2207-4610-86c0-657b4e5851a3\nserviceid    : 6116a0f4-6c9f-491f-b180-ea31bea2d9de\n|\n| HTTP Request\n|----------------\u003e service-2:\n                   transactionid: ef8347eb-2207-4610-86c0-657b4e5851a3\n                   serviceid    : 4e1261c1-9a0c-4a5d-bfc2-49744fd159c6\n                   |\n                   | HTTP Request\n                   |----------------\u003e service-3: /api/check-stock\n                                      transactionid: ef8347eb-2207-4610-86c0-657b4e5851a3\n                                      serviceid    : b4fbc082-a49a-440d-b1d6-2bd0557fd189\n```\n\nAs we can see in the flow above, the **transactionid** (ef8347eb-2207-4610-86c0-657b4e5851a3) remained the same across all three services, and each service has its own **serviceid**.\n\nExample of logs in the developed APIs:\n\n**Auth-API:**\n\n```\nRequest to POST login with data {\"email\":\"testeuser1@gmail.com\",\"password\":\"123456\"} | [transactionID: e3762030-127a-4079-9dee-ba961d7e77ce | serviceID: 6b07b6c2-009e-4799-be96-3bf972338b17]\n\nResponse to POST login with data {\"status\":200,\"accessToken\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRoVXNlciI6eyJpZCI6MSwibmFtZSI6IlVzZXIgVGVzdCAxIiwiZW1haWwiOiJ0ZXN0ZXVzZXIxQGdtYWlsLmNvbSJ9LCJpYXQiOjE2MzQwNTE4ODQsImV4cCI6MTYzNDEzODI4NH0.NJ-h2i5XPT8NwZyZ_43bif1NIS00ROfCtRecBkxy5A8\"} | [transactionID: e3762030-127a-4079-9dee-ba961d7e77ce | serviceID: 6b07b6c2-009e-4799-be96-3bf972338b17]\n```\n\n**Product-API:**\n\n```\nRequest to POST product stock with data {\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}]} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: ea146e74-55cf-4a53-860e-9010d6e3f61b]\n\nResponse to POST product stock with data {\"status\":200,\"message\":\"The stock is ok!\"} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: ea146e74-55cf-4a53-860e-9010d6e3f61b]\n```\n\n**Sales-API:**\n\n```\nRequest to POST new order with data {\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}]} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: 5f553f02-e830-4bed-bc04-8f71fe16cf28]\n\nResponse to POST login with data {\"status\":200,\"createdOrder\":{\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}],\"user\":{\"id\":1,\"name\":\"User Test 1\",\"email\":\"testeuser1@gmail.com\"},\"status\":\"PENDING\",\"createdAt\":\"2021-10-12T16:34:49.778Z\",\"updatedAt\":\"2021-10-12T16:34:49.778Z\",\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\",\"serviceid\":\"5f553f02-e830-4bed-bc04-8f71fe16cf28\",\"_id\":\"6165b92addaf7fc9dd85dad0\",\"__v\":0}} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: 5f553f02-e830-4bed-bc04-8f71fe16cf28]\n```\n\n**RabbitMQ:**\n\n```\nSending message to product update stock: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}],\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"}\n\nRecieving message with data: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}],\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"} and TransactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9\n\nSending message: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"status\":\"APPROVED\",\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"}\n\nRecieving message from queue: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"status\":\"APPROVED\",\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarlinsk%2Fsmall-sales-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarlinsk%2Fsmall-sales-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarlinsk%2Fsmall-sales-system/lists"}