Skip to content
This repository was archived by the owner on Nov 7, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
a9e935d
chore(app): application setup
Leonardo-Figueiredo Jun 23, 2022
691b137
chore(app): add env for application PORT
Leonardo-Figueiredo Jun 23, 2022
16ac494
chore(app): add graphql dependencies
Leonardo-Figueiredo Jun 23, 2022
42761af
chore(app): add GraphQL dependencies
Leonardo-Figueiredo Jun 23, 2022
e630711
refactor(main): change server up message
Leonardo-Figueiredo Jun 23, 2022
b31b106
feat(repo.entity): add repo entity on project:
Leonardo-Figueiredo Jun 23, 2022
6b15a83
feat(owner.entity): add owner entity on project
Leonardo-Figueiredo Jun 23, 2022
3cf60c8
refactor(github-api-routes.enum): update github routes
Leonardo-Figueiredo Jun 23, 2022
6476bf6
refactor(shared.module): removed unused providers
Leonardo-Figueiredo Jun 23, 2022
827f68b
feat(app.module): add GraphQL configuration and repo module
Leonardo-Figueiredo Jun 23, 2022
7593075
feat(repo-find-all-input/output): add repo find all inputs and outputs
Leonardo-Figueiredo Jun 23, 2022
8f783d0
feat(github-api.repository): add findAll method
Leonardo-Figueiredo Jun 23, 2022
730fa48
feat(repo.service): add findAll service
Leonardo-Figueiredo Jun 23, 2022
d3d6d9e
feat(format-github-repositories.util): add util to format response pr…
Leonardo-Figueiredo Jun 23, 2022
e6ec801
feat(repo.resolver): add repoFindAll query implementing findAll service
Leonardo-Figueiredo Jun 23, 2022
143b06a
feat(repo.module): add GithubApiRepository provider
Leonardo-Figueiredo Jun 23, 2022
7bbc279
refactor(repo-find-response.input): change module name
Leonardo-Figueiredo Jun 23, 2022
68a2e7a
feat(github-api.repository): add findByName method
Leonardo-Figueiredo Jun 23, 2022
ba34f7e
feat(repo.service): add findOne service
Leonardo-Figueiredo Jun 23, 2022
207499b
feat(repo.resolver): add findOne resolver
Leonardo-Figueiredo Jun 23, 2022
726bdf3
chore(package): add typeorm and pg dependencies
Leonardo-Figueiredo Jun 23, 2022
b427405
chore(.prettierrc): add prettier printWidth rule
Leonardo-Figueiredo Jun 24, 2022
48161ac
chore(package): add typeorm ts command
Leonardo-Figueiredo Jun 24, 2022
0645951
feat(data-source): add data-source with database configuration
Leonardo-Figueiredo Jun 24, 2022
acd28d4
feat(create-repo-table): add migration to create repo table and add u…
Leonardo-Figueiredo Jun 24, 2022
e71cdd1
feat(create-owners-table): add table to create owners table
Leonardo-Figueiredo Jun 24, 2022
56e133b
feat(database.constant): add database constants
Leonardo-Figueiredo Jun 24, 2022
fb30600
feat(repo.entity): add TypeORM entity and column decorators
Leonardo-Figueiredo Jun 24, 2022
3955c16
feat(owner.entity): add TypeORM entity and column decorators
Leonardo-Figueiredo Jun 24, 2022
1b81db9
feat(database.provider): add database provider to initialize typeorm …
Leonardo-Figueiredo Jun 24, 2022
240e41e
feat(shared.module): register datapbaseProviders on sharedModule
Leonardo-Figueiredo Jun 24, 2022
9c1c756
feat(repo.provider): add repo repository provider
Leonardo-Figueiredo Jun 24, 2022
9bac9a1
refactor(data-source): choose entities and migrations path by executi…
Leonardo-Figueiredo Jun 24, 2022
6048824
refactor(owner.entity): removed unused ownser
Leonardo-Figueiredo Jun 24, 2022
183b46d
refactor(create-repo-table): add column on repo table migration
Leonardo-Figueiredo Jun 24, 2022
f7373c0
feat(create-repo.input): add input fields
Leonardo-Figueiredo Jun 24, 2022
5c0f617
feat(repo.entity): add is_storaged field
Leonardo-Figueiredo Jun 24, 2022
615b513
feat(repo.entity): add default on is_storaged
Leonardo-Figueiredo Jun 24, 2022
252913f
feat(repo.service): add create repo Service
Leonardo-Figueiredo Jun 24, 2022
345b505
feat(repo.module): add RepoRepository provider
Leonardo-Figueiredo Jun 24, 2022
214fde1
refactor(data-source/database.constant): moved to shared module
Leonardo-Figueiredo Jun 24, 2022
9556dfc
tests(app.e2e-spec): remove e2e tests
Leonardo-Figueiredo Jun 24, 2022
1e5a9e0
chore(package): add faker lib
Leonardo-Figueiredo Jun 24, 2022
3e1b1be
refactor(github-api.repository): add a better function syntax with ar…
Leonardo-Figueiredo Jun 24, 2022
5e98b6b
refactor(repo.resolver/service): implements new findOne arg syntax
Leonardo-Figueiredo Jun 24, 2022
afd639c
tests(fake-github-api.repository): add mocked github api repository'
Leonardo-Figueiredo Jun 24, 2022
6b9350a
tests(fake-repo.provider): add fake Repo Provider(Repository)
Leonardo-Figueiredo Jun 24, 2022
4c4673e
tests(repo.service.spec): add create, findOne and findAll tests
Leonardo-Figueiredo Jun 24, 2022
7832528
refactor(data-source): update migrations and entities path
Leonardo-Figueiredo Jun 25, 2022
1978373
chore(.env.sample): add env example
Leonardo-Figueiredo Jun 25, 2022
bc041e4
refactor(app): change some logic
Leonardo-Figueiredo Jun 25, 2022
3c2fb4a
refactor(repo.entity): change created_at, updated_at and deleted_at f…
Leonardo-Figueiredo Jun 25, 2022
2116433
feat(findone): add is_storaged logic
Leonardo-Figueiredo Jun 25, 2022
829c1e5
style(prettier): increase printWidth to 100
Leonardo-Figueiredo Jun 25, 2022
bdb6e93
chore(package): add node version
Leonardo-Figueiredo Jun 25, 2022
b5aba06
chore(package): add yarn version
Leonardo-Figueiredo Jun 25, 2022
1fb8c2a
chore(package): change yarn version
Leonardo-Figueiredo Jun 25, 2022
2f1ca2a
chore(package): remove dynamic dependencies
Leonardo-Figueiredo Jun 25, 2022
1f0ace6
feat(data-source): add ssl settings
Leonardo-Figueiredo Jun 25, 2022
365aaac
feat(main): add heroku port
Leonardo-Figueiredo Jun 25, 2022
bb07eb2
feat(app.module): add graphQL cache config
Leonardo-Figueiredo Jun 25, 2022
dbb59c1
chore(procfile): use yarn instead npm
Leonardo-Figueiredo Jun 25, 2022
5b2abad
chore(package): add author
Leonardo-Figueiredo Jun 25, 2022
d053d60
tests(repo.service.spec): fix create a new repo test
Leonardo-Figueiredo Jun 25, 2022
2187f32
docs(readme): add API setup documentation
Leonardo-Figueiredo Jun 25, 2022
dd4edae
docs(readme): add API on title
Leonardo-Figueiredo Jun 25, 2022
c864453
docs(readme): remove Client dependencies and add a contact
Leonardo-Figueiredo Jun 25, 2022
08bb6d7
docs(readme): add Jest as Technology and Yarn as a dependency
Leonardo-Figueiredo Jun 25, 2022
0c8ffbb
docs(readme): add Challenge original repository
Leonardo-Figueiredo Jun 25, 2022
251b23d
refactor(data-source): add DB_URL on SSL option
Leonardo-Figueiredo Jun 25, 2022
3b23e0e
refactor(data-source): disable SSL rejectUnauthorized option
Leonardo-Figueiredo Jun 25, 2022
909865e
chore(.env.sample): change DB_URL to DATABASE_URL
Leonardo-Figueiredo Jun 25, 2022
982ffcb
chore(docker): add dockerfile and docker-compose
Leonardo-Figueiredo Jun 26, 2022
975997f
docs(readme): add docker steps
Leonardo-Figueiredo Jun 26, 2022
d4f0862
docs(readme): add Live preview
Leonardo-Figueiredo Jun 26, 2022
162203e
docs(readme): change live preview location
Leonardo-Figueiredo Jun 26, 2022
70cd1b1
feat(github-api-error-decoder.util): add github error handling
Leonardo-Figueiredo Jun 26, 2022
2239f73
feat(destroy-repo.input): add DestroyRepoInput
Leonardo-Figueiredo Jun 26, 2022
82009de
feat(repo.service): add destroy repository service
Leonardo-Figueiredo Jun 26, 2022
dbe6483
feat(repo.resolver): add destroyResolver
Leonardo-Figueiredo Jun 26, 2022
a8b9e0e
refactor(rename-repos-stored-columns): add migration and update all a…
Leonardo-Figueiredo Jun 26, 2022
85a42e4
docs(readme): update API link
Leonardo-Figueiredo Jun 26, 2022
e363c60
docs(readme): add docker dependencies
Leonardo-Figueiredo Jun 26, 2022
186077e
docs(readme): add captal case on preview
Leonardo-Figueiredo Jun 26, 2022
ccbd25c
tests(repo.service.spec): add destroyOne tests
Leonardo-Figueiredo Jun 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
11 changes: 11 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APP_PORT=3450
GITHUB_BASE_URL="https://api.github.com/"
GITHUB_AUTH_TOKEN=""

# DATABASE_URL is only allowed on real productions services with ssl
DATABASE_URL="postgresql://postgres:<your admin password>@localhost:5432/<your db name"
DB_HOST=""
DB_PORT=""
DB_USERNAME=""
DB_PASSWORD=""
DB_DATABASE="ateliware_hiring_challenge"
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir : __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# compiled output
/dist
/node_modules

# Application
*.gql
.env

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"trailingComma": "none",
"semi": false,
"arrowParens": "avoid",
"printWidth": 100
}
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web yarn start:prod
103 changes: 87 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,93 @@
# Desafio técnico para desenvolvedores
# Ateliware - Dev Hiring Challenge - API

Construa uma nova aplicação, utilizando o framework de sua preferência (Ruby on Rails, Elixir Phoenix, Python Django ou Flask, NodeJS Sails, Java Spring, ASP.NET ou outro), a qual deverá conectar na API do GitHub e disponibilizar as seguintes funcionalidades:
> The challenge is to create a application to comunicate with GithubAPI and implement the features bellow.
>
> - Button to search and save most featured repositories of five languages.
> - List found repositories.
> - Create repository details view.

- Botão para buscar e armazenar os repositórios destaques de 5 linguagens à sua escolha;
- Listar os repositórios encontrados;
- Visualizar os detalhes de cada repositório.
## Live Preview

Alguns requisitos:
[https://ateliware-prod-frontend.herokuapp.com](https://ateliware-prod-frontend.herokuapp.com)

- Deve ser uma aplicação totalmente nova;
- A solução deve estar em um repositório público do GitHub;
- A aplicação deve armazenar as informações encontradas;
- Utilizar PostgreSQL, MySQL ou SQL Server;
- O deploy deve ser realizado, preferencialmente, no Heroku, AWS ou no Azure;
- A aplicação precisa ter testes automatizados;
- Preferenciamente dockerizar a aplicação;
- Por favor atualizar o readme da aplicação com passo a passo com instrução para subir o ambiente.
## Technologies

Quando terminar, faça um Pull Request neste repo e avise-nos por email.
- [GraphQL](https://graphql.org)
- [Jest](https://jestjs.io/pt-BR/)
- [NestJS](https://nestjs.com)
- [TypeORM](https://typeorm.io)

**IMPORTANTE:** se você não conseguir finalizar o teste, por favor nos diga o motivo e descreva quais foram as suas dificuldades. Você pode também sugerir uma outra abordagem para avaliarmos seus skills técnicos, vender seu peixe, mostrar-nos do que é capaz.
## Application Architecture

### API

- [Dev Hiring Challenge API](https://github.com/Leonardo-Figueiredo/dev-hiring-challenge) (this repository)

### Client

- [Dev Hiring Challenge Client](https://github.com/Leonardo-Figueiredo/dev-hiring-challenge-frontend)

---

## Dependencies

- [Node ^16.15.1](https://nodejs.org/dist/v16.15.1/docs/api/)
- [Postgres ^14.4](https://www.postgresql.org)
- [Yarn ^1.22.19](https://yarnpkg.com)

_The dependencies above are unnecessary if you use docker, the ones below are required._

- [Docker Engine ^20.10.12](https://docs.docker.com/engine/install/)
- [Docker Compose ^1.29.2](https://docs.docker.com/compose/install/)

---

## Base Setup

- Create a Postgres database.
- Run `$ cp .env.sample .env` (or just make a copy), populate .env file with valid keys.

## Local Setup (without Docker, with Docker [go to](#docker-setup-🐳))

- Follow the steps above on [Base Setup](#base-setup)
- Run `$ yarn` to install all dependencies.
- Run `$ yarn ts-typeorm -d ./src/modules/shared/data-source.ts migration:run` to create database tables.
- Run test with: `$ yarn test`.
- To start Ateliware Challenge API in development mode with `$ yarn start:dev`.
- Build production Ateliware Challenge API with `$ yarn build`.
- To start Ateliware Challenge API in production mode with `$ yarn start:prod`.

## Docker Setup 🐳

- Follow the steps above on [Base Setup](#base-setup).
- Run `$ docker-compose build development` to create development or production image.
- Run the migrations with `$ docker-compose exec development $ yarn ts-typeorm -d ./src/modules/shared/data-source.ts migration:run`.
- To execute **production** container use `$ docker-compose up production`.
- If you want to execute on background, use **-d** flag, example: `$ docker-compose up -d production`.
- To execute **development** container use `$ docker-compose up development`.
- Stop containers and dependencies, execute `$ docker-compose stop`.
- To stop a especific container execute `$ docker-compose stop development`.
- Now run `$ docker-compose up -d development` and Ateliware Challenge API should be working fine. 🚀
- To up a container with new build, you should run `$ docker-compose up --build -d production`.

Open [http://localhost:3450](http://localhost:3450) with your browser to see the result.

_If you change the default port on .env, you should enter on <http://localhost:APP_PORT>_

### Migration Commands

```bash
# create
$ yarn ts-typeorm migration:create ./src/modules/shared/migrations/MIGRATION_NAME

# run
$ yarn ts-typeorm -d ./src/modules/shared/data-source.ts migration:run

# revert
$ yarn ts-typeorm -d ./src/modules/shared/data-source.ts migration:revert

```

[Challenge Original Repository](https://github.com/ateliware/dev-hiring-challenge)

If you have any problems, send me a e-mail [[email protected]](mailto:[email protected])
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.8"

services:
development:
container_name: ateliware-challenge-api-development
image: ateliware-challenge-api-development:1.0.0
restart: unless-stopped
build:
context: .
target: development
dockerfile: ./dockerfile
volumes:
- .:/usr/app
network_mode: host

production:
container_name: ateliware-challenge-api-production
image: ateliware-challenge-api-production:1.0.0
restart: unless-stopped
build:
context: .
target: production
dockerfile: ./dockerfile
volumes:
- .:/usr/app
network_mode: host

37 changes: 37 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
############### Development ###############

FROM node:16.15.1-alpine AS development

ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/app

COPY package.json ./

RUN yarn global add rimraf
RUN yarn install

COPY . .

CMD ["yarn", "start:dev"]

############### Production ###############

FROM node:16.15.1-alpine AS production

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /usr/app

COPY package.json ./

RUN yarn global add rimraf
RUN yarn install

COPY . .

RUN yarn build

CMD ["yarn", "start:prod"]
5 changes: 5 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
83 changes: 83 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"name": "dev-hiring-challenge",
"version": "0.0.1",
"author": "Leonardo Figueiredo <[email protected]>",
"private": true,
"license": "UNLICENSED",
"engines": {
"node": "16.15.1",
"yarn": "1.x"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"ts-typeorm": "NODE_ENV=typeorm typeorm-ts-node-esm",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/apollo": "10.0.16",
"@nestjs/common": "8.4.7",
"@nestjs/core": "8.0.0",
"@nestjs/graphql": "10.0.16",
"@nestjs/platform-express": "8.0.0",
"apollo-server-express": "3.9.0",
"@nestjs/cli": "8.2.8",
"dotenv": "16.0.1",
"graphql": "16.5.0",
"pg": "8.7.3",
"reflect-metadata": "0.1.13",
"rimraf": "3.0.2",
"rxjs": "7.2.0",
"typeorm": "0.3.6"
},
"devDependencies": {
"@faker-js/faker": "7.3.0",
"@nestjs/schematics": "8.0.0",
"@nestjs/testing": "8.0.0",
"@types/express": "4.17.13",
"@types/jest": "27.5.0",
"@types/node": "16.0.0",
"@types/supertest": "2.0.11",
"@typescript-eslint/eslint-plugin": "5.0.0",
"@typescript-eslint/parser": "5.0.0",
"eslint": "8.0.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"jest": "28.0.3",
"prettier": "2.3.2",
"source-map-support": "0.5.20",
"supertest": "6.1.3",
"ts-jest": "28.0.1",
"ts-loader": "9.2.3",
"ts-node": "10.8.1",
"tsconfig-paths": "4.0.0",
"typescript": "4.3.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
19 changes: 19 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'
import { Module } from '@nestjs/common'
import { GraphQLModule } from '@nestjs/graphql'
import { RepoModule } from './modules/repo/repo.module'
import { SharedModule } from './modules/shared/shared.module'

@Module({
imports: [
SharedModule,
RepoModule,
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
playground: process.env.NODE_ENV !== 'production',
autoSchemaFile: true,
cache: 'bounded'
})
]
})
export class AppModule {}
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'dotenv/config'
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'

async function bootstrap() {
const PORT = process.env.PORT || process.env.APP_PORT || 3000

const app = await NestFactory.create(AppModule)
await app.listen(PORT)

console.log(`\n 🎊 Server is up on port ${PORT} 🚀 \n`)
}

bootstrap()
Loading