{"id":17651747,"url":"https://github.com/diegovictor/gocommerce","last_synced_at":"2025-05-07T08:31:39.581Z","repository":{"id":37240526,"uuid":"277415706","full_name":"DiegoVictor/gocommerce","owner":"DiegoVictor","description":"Project built during the Rocketseat Bootcamp #11","archived":false,"fork":false,"pushed_at":"2025-03-07T13:14:34.000Z","size":726,"stargazers_count":7,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T08:12:06.547Z","etag":null,"topics":["api","coverage-report","database","editorconfig","eslint","friendly-errors","gocommerce","gostack","javascript","js","node","nodejs","pg","postgres","prettier","rocketseat","ts","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DiegoVictor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-06T01:35:50.000Z","updated_at":"2025-03-07T13:14:37.000Z","dependencies_parsed_at":"2024-12-23T03:18:18.610Z","dependency_job_id":"89f66f20-d527-429c-9cc0-c629f562bda2","html_url":"https://github.com/DiegoVictor/gocommerce","commit_stats":{"total_commits":181,"total_committers":1,"mean_commits":181.0,"dds":0.0,"last_synced_commit":"c127810542e7c6f3ed3c2a9152be7c78c7ea5aec"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fgocommerce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fgocommerce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fgocommerce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fgocommerce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DiegoVictor","download_url":"https://codeload.github.com/DiegoVictor/gocommerce/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252842587,"owners_count":21812696,"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","coverage-report","database","editorconfig","eslint","friendly-errors","gocommerce","gostack","javascript","js","node","nodejs","pg","postgres","prettier","rocketseat","ts","typescript"],"created_at":"2024-10-23T11:43:29.257Z","updated_at":"2025-05-07T08:31:39.550Z","avatar_url":"https://github.com/DiegoVictor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoCommerce\n[![CircleCI](https://img.shields.io/circleci/build/github/DiegoVictor/gocommerce?style=flat-square\u0026logo=circleci)](https://app.circleci.com/pipelines/github/DiegoVictor/gocommerce?branch=main)\n[![postgres](https://img.shields.io/badge/postgres-8.7.1-326690?style=flat-square\u0026logo=postgresql\u0026logoColor=white)](https://www.postgresql.org/)\n[![typescript](https://img.shields.io/badge/typescript-4.4.3-3178c6?style=flat-square\u0026logo=typescript)](https://www.typescriptlang.org/)\n[![eslint](https://img.shields.io/badge/eslint-7.32.0-4b32c3?style=flat-square\u0026logo=eslint)](https://eslint.org/)\n[![airbnb-style](https://flat.badgen.net/badge/style-guide/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)\n[![jest](https://img.shields.io/badge/jest-27.2.2-brightgreen?style=flat-square\u0026logo=jest)](https://jestjs.io/)\n[![coverage](https://img.shields.io/codecov/c/gh/DiegoVictor/gocommerce?logo=codecov\u0026style=flat-square)](https://codecov.io/gh/DiegoVictor/gocommerce)\n[![MIT License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](https://raw.githubusercontent.com/DiegoVictor/gocommerce/main/LICENSE)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\u003cbr\u003e\n[![Run in Insomnia}](https://insomnia.rest/images/run.svg)](https://insomnia.rest/run/?label=GoCommerce\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2Fgocommerce%2Fmain%2FInsomnia_2024-11-30.json)\n\nPermit to register products and make orders. The app has rate limit, friendly errors, validation and also a simple versioning was made.\n\n## Table of Contents\n* [Installing](#installing)\n  * [Configuring](#configuring)\n    * [Postgres](#postgres)\n      * [Migrations](#migrations)\n    * [.env](#env)\n* [Usage](#usage)\n  * [Error Handling](#error-handling)\n    * [Errors Reference](#errors-reference)\n  * [Versioning](#versioning)\n  * [Routes](#routes)\n    * [Requests](#requests)\n* [Running the tests](#running-the-tests)\n  * [Coverage report](#coverage-report)\n\n# Installing\nEasy peasy lemon squeezy:\n```\n$ yarn\n```\nOr:\n```\n$ npm install\n```\n\u003e Was installed and configured the [`eslint`](https://eslint.org/) and [`prettier`](https://prettier.io/) to keep the code clean and patterned.\n\n## Configuring\nThe application use just one database: [Postgres](https://www.postgresql.org/). For the fastest setup is recommended to use [docker-compose](https://docs.docker.com/compose/), you just need to up all services:\n```\n$ docker-compose up -d\n```\n\n### Postgres\nResponsible to store all application data. If for any reason you would like to create a Postgres container instead of use `docker-compose`, you can do it by running the following command:\n```\n$ docker run --name gocommerce-postgres -e POSTGRES_PASSWORD=docker -p 5432:5432 -d postgres\n```\n\u003e Then create two databases: `gocommerce` and `tests` (in case you would like to run the tests).\n\n#### Migrations\nRemember to run the database migrations:\n```\n$ yarn ts-node-dev ./node_modules/typeorm/cli.js migration:run\n```\nOr:\n```\n$ yarn typeorm migration:run\n```\n\u003e See more information on [TypeORM Migrations](https://typeorm.io/#/migrations).\n\n### .env\nIn this file you may configure your Postgres database connection, JWT settings, the environment, app's port and a url to documentation (this will be returned with error responses, see [error section](#error-handling)). Rename the `.env.example` in the root directory to `.env` then just update with your settings.\n\n|key|description|default\n|---|---|---\n|APP_PORT|Port number where the app will run.|`3333`\n|NODE_ENV|App environment. The typeORM's database choice rely on this key value, so if the environment is `test` the database used will be `tests` otherwise the `POSTGRES_DATABASE` will set the database name.|`development`\n|POSTGRES_HOST|Postgres host.|`pg`\n|POSTGRES_PORT|Postgres port.|`5432`\n|POSTGRES_USER|Postgres user.| `postgres`\n|POSTGRES_PASSWORD|Postgres password.| -\n|POSTGRES_DATABASE|Application's database name.| gocommerce\n|DOCS_URL|An url to docs where users can find more information about the app's internal code errors.|`https://github.com/DiegoVictor/gocommerce#errors-reference`\n\n# Usage\nTo start up the app run:\n```\n$ yarn dev:server\n```\nOr:\n```\nnpm run dev:server\n```\n\n## Error Handling\nInstead of only throw a simple message and HTTP Status Code this API return friendly errors:\n```json\n{\n  \"status\": \"error\",\n  \"message\": \"Too Many Requests\",\n  \"code\": 429,\n  \"docs\": \"https://github.com/DiegoVictor/gocommerce#errors-reference\"\n}\n```\n\u003e As you can see a url to error docs are returned too. To configure this url update the `DOCS_URL` key from `.env` file.\n\u003e In the next sub section ([Errors Reference](#errors-reference)) you can see the errors `code` description.\n\n### Errors Reference\n|code|message|description\n|---|---|---\n|140|The email provided already in use|Already exists a customer with the same email.\n|144|Customer not found|The `id` sent not references an existing customer in the database.\n|240|There is not enough product quantity in stock|The requested quantity is not available in stock.\n|244|Order not found|The `id` sent not references an existing order in the database.\n|245|Customer not found|You are trying to create a new order with a customer that not exists.\n|246|Product not found|This happens when you try to create a new order with a non existing product.\n|247|Order not found|You are trying to retrieve products from a order that not exists.\n|344|Product not found|The `id` sent not references an existing order in the database.\n|349|A product with the same name already exists|Products must have unique names, but you provided one already in use.\n|429|Too Many Requests|You reached at the requests limit.\n\n## Versioning\nA simple versioning was made. Just remember to set after the `host` the `/v1/` string to your requests.\n```\nGET http://localhost:3333/v1/orders/f4968587-5950-4df3-92d8-c5aee0c647c2\n```\n\n## Routes\n|route|HTTP Method|params|description\n|:---|:---:|:---:|:---\n|`/customers`|POST|Body with customer `name` and `email`.|Create a new customer.\n|`/customers/:id`|GET|`:id` of the customer.|Return one customer.\n|`/products`|POST|Body with product `name`, `price` and `quantity`.|Create a new product.\n|`/products/:id`|GET|`:id` of the product.|Return one product.\n|`/orders`|POST|Body with order `customer_id` and `products` (with `id` and `quantity`).|Create a new order.\n|`/orders/:id`|GET|`:id` of the order|Show one order.\n|`/orders/:id/products`|GET|`:id` of the order|Return the products from an order.\n\n### Requests\n* `POST /customers`\n\nRequest body:\n```json\n{\n  \"name\": \"John Doe\",\n  \"email\": \"john@doe.com\"\n}\n```\n\n* `POST /products`\n\nRequest body:\n```json\n{\n  \"name\": \"Lemon\",\n  \"price\": 1.95,\n  \"quantity\": 100\n}\n```\n\n* `POST /orders`\n\nRequest body:\n```json\n{\n  \"customer_id\": \"d59d9a05-fba8-4e00-b3c4-11c0de51e410\",\n  \"products\": [\n    {\n      \"id\": \"732b09e3-bb0c-40e9-b9dc-49616c907726\",\n      \"quantity\": 1\n    },\n    {\n      \"id\": \"56d4b719-058c-4ddd-a89b-b09dcb70e5d9\",\n      \"quantity\": 3\n    }\n  ]\n}\n```\n\n# Running the tests\n[Jest](https://jestjs.io/) was the choice to test the app, to run:\n```\n$ yarn test\n```\nOr:\n```\n$ npm run test\n```\n\n## Coverage report\nYou can see the coverage report inside `tests/coverage`. They are automatically created after the tests run.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fgocommerce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegovictor%2Fgocommerce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fgocommerce/lists"}