An open API service indexing awesome lists of open source software.

https://github.com/adrielcodeco/customer-demo

Customers API demo
https://github.com/adrielcodeco/customer-demo

Last synced: over 1 year ago
JSON representation

Customers API demo

Awesome Lists containing this project

README

          

# Customers API

[![codecov](https://codecov.io/gh/adrielcodeco/customer-demo/branch/develop/graph/badge.svg?token=rdlj9hy3im)](https://codecov.io/gh/adrielcodeco/customer-demo)

Demo API

The demo is available at [https://customers-api-demo.co2lab.info/api](https://customers-api-demo.co2lab.info/api)

## Installation

```bash
$ pnpm i
```

## Building

```bash
$ pnpm run build
```

## Running the app locally

To run the app locally you will need a redis running on localhost:6379.

You can run redis on docker with the below command:

```bash
$ docker compose run -p 6379:6379 -d cache
```

If your redis is not running on this host or port you can change the redis host and port
within the .env file setting the keys REDIS_HOST and REDIS_PORT.

```bash
# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod
```

## Running the app on docker

```bash
$ docker compose run -p 8000:80 --build demo
```

## Running the tests locally

```bash
# all tests without coverage
$ pnpm run test

# tests with coverage
$ pnpm run test:cov
```

## Running the tests on docker

```bash
$ docker compose run --build demo-test
```

## Using the apis

After running the application you can open in browser E.g.:

```txt
http://localhost:8000/api
```

On /api the application will show a OpenAPI page.

For test purpose you will need a access token.
To get a access token use the below curl E.g.:

```bash
$ curl --location 'https://accounts.seguros.vitta.com.br/auth/realms/careers/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=customers' \
--data-urlencode 'client_secret=453000f7-47a0-4489-bc47-891c742650e2' \
--data-urlencode 'username=adrielcodeco@hotmail.com' \
--data-urlencode 'password=YWRyaWVsY29kZWNvQGhvdG1haWwuY29t' \
--data-urlencode 'scope=openid'
```

after obtained the access token you can call the customers API to save a customer with the below curl E.g.:

```bash
$ curl --location 'http://localhost:8000/customers' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIg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"
}'
```

## Deploy to production

This project follow the [gitflow concept](https://danielkummer.github.io/git-flow-cheatsheet/) by
the convenience of being well known.

Follow the gitflow to send your changes to production.

The pipelines are automated, the application will be deployed to production if the code are merged to
the main branch.

The automation run a terraform that deploy a AWS App Runner service.

## Teste coverage

[![codecov](https://codecov.io/gh/adrielcodeco/customer-demo/branch/develop/graph/badge.svg?token=rdlj9hy3im)](https://codecov.io/gh/adrielcodeco/customer-demo)

[![codecov](https://codecov.io/gh/adrielcodeco/customer-demo/branch/develop/graphs/sunburst.svg?token=rdlj9hy3im)](https://codecov.io/gh/adrielcodeco/customer-demo)