Git Product home page Git Product logo

credere_backend_test's Introduction

Hiring Test - Credere

This is a backend aplication to the backend developer job in the company Credere. To see this applicantion running with a frontend app, click here.

To see the frontend repository of this application, click here.

- Specifications and technologies used here

This project was built using Nodejs with Typescript.

Here, node version is 12.16.3 and the package manager used is yarn in version 1.22.5.

The database used is Postgres with Typeorm as ORM (object-relational mapping). Besides that, the database is running in a docker image of postgres.

In tests, it's used Jest and Coverage reports to help.

To test the APIs it was used Insomnia and DBeaver - v:7.2.1 as a database administration tool.

The archtecture of the project is based in DDD (Domain Driven Design).

- How to run the project

Docker

First of all, it's needed to install docker and download the postgres image. To install docker I suggest following instructions in this link.

After the instalation of docker, we need to create the database container with the correct image. Here you can see the docs of how to download the latest image from Postgres, but here's my suggestion to create the container and downloading image. It's important to follow the password and ports configuration as they are here. It's better to follow the command in terminal:

docker run --name conta_simples -e POSTGRES_PASSWORD=docker -p 5438:5432 -d postgres

After creating the container and downloading image, run to check if everything is ok:

docker ps

DBeaver

To visualize the database with Dbeaver, open it and click:

  • New database connection
  • Postgres

A window will open with tab Main. There you should set:

  • Host: localhost
  • Port: 5438
  • Database: credere-test
  • Username: postgres
  • Password: docker

In tab PostgresQL:

  • Show all database: check the box

Project

After downloading the code from the repository (and letting the docker running), run yarn to install all the dependencies.

After that, we need to create the tables in database, so run:

yarn typeorm migration:run

After that, to finish, run:

yarn dev:server

A message like this should appear in terminal:

๐Ÿš—๏ธ Server started on port 3333!

If so, enjoy the application!

Code tests

To run tests and see coverage report:

yarn test

- Testing the API

Here I will not teach how to use Insomia, because there are a lot of tutorials out there, but I liked this one. It's in portuguese.

- Available Endpoints

The endpoints here are shown in development environment.

Create Movements and Car Coordinates

  • Method: POST

  • Endpoint:

http://localhost:3333/movements
  • Body: JSON:
{
  TYPES:
  name: string,
  movement: string[]

  EXAMPLE
	"name": "John Doe",
	"movement": ["M", "GE", "M", "M"]
}

And then status 200 should come with the new coordinates, pilot_name and car direction:

RESPONSE:
{
  "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "pilot_name": "John Doe",
  "xCoordinate": 1,
  "yCoordinate": 2,
  "carDirection": "up"
}

List Movements by pilot name

  • Method: GET

  • Endpoint:

http://localhost:3333/movements/:pilot_name
  • Body: none:

And then status 200 should come with all the movements made by the specified pilot:

RESPONSE:
[
   {
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "pilot_name": "John Doe",
    "movement": "GE,M,M,M,GD,M,M"
  },
  {
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "pilot_name": "John Doe",
    "movement": "GE,GE,M"
  },
]

List Car Coordinate by pilot name

  • Method: GET

  • Endpoint:

http://localhost:3333/coordinates/:pilot_name
  • Body: none:

And then status 200 should come with all the information about coordinates by the specified pilot:

RESPONSE:
{
  "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "pilot_name": "John Doe",
  "xCoordinate": 1,
  "yCoordinate": 2,
  "carDirection": "down"
}

Reset Car Coordinate by pilot name

  • Method: GET

  • Endpoint:

http://localhost:3333/coordinates/reset/:pilot_name
  • Body: none:

And then status 200 should come with an empty object:

RESPONSE:
{}

To confirm if the coordinate is (x, y) = (0, 0), use the list coordinates endpoint to be sure.

- This backend system in production

This application is online, hosted in Digital Ocean, with a domain and SSL certificate. You can access it by this address:

PROD

https://credere.backend.felipedeamonteiro.com/

DEV

http://localhost:3333

Besides, it uses github actions for continuous deploy. The frontend application already uses this app in production.

Enjoy!

credere_backend_test's People

Contributors

felipedeamonteiro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.