Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paulo Henrique de Siqueira #83

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
144 changes: 144 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
######################
# Project Specific
######################
/target/www/**
/src/test/javascript/coverage/

######################
# Node
######################
/node/
node_tmp/
node_modules/
npm-debug.log.*
/.awcache/*
/.cache-loader/*

######################
# SASS
######################
.sass-cache/

######################
# Eclipse
######################
*.pydevproject
.project
.metadata
tmp/
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
.factorypath
/src/main/resources/rebel.xml

# External tool builders
.externalToolBuilders/**

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

######################
# Intellij
######################
.idea/
*.iml
*.iws
*.ipr
*.ids
*.orig
classes/
out/

######################
# Visual Studio Code
######################
.vscode/

######################
# Maven
######################
/log/
/target/

######################
# Gradle
######################
.gradle/
/build/

######################
# Package Files
######################
*.jar
*.war
*.ear
*.db

######################
# Windows
######################
# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini

######################
# Mac OSX
######################
.DS_Store
.svn

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

######################
# Directories
######################
/bin/
/deploy/

######################
# Logs
######################
*.log*

######################
# Others
######################
*.class
*.*~
*~
.merge_file*

######################
# Gradle Wrapper
######################
!gradle/wrapper/gradle-wrapper.jar

######################
# Maven Wrapper
######################
!.mvn/wrapper/maven-wrapper.jar

######################
# ESLint
######################
.eslintcache
75 changes: 53 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,66 @@
![PicPay](https://user-images.githubusercontent.com/1765696/26998603-711fcf30-4d5c-11e7-9281-0d9eb20337ad.png)

# Teste Backend
Paulo Henrique de Siqueira
[email protected]
https://www.linkedin.com/in/paulohenriquesiqueira/

### Stack utilizado

Esta solução foi desenvolvida utilizando as seguintes tecnologias:

* Spring Boot
* MongoDB
* Elasticsearch
* Angular
* Docker

O desafio é criar uma API REST que busca usuarios pelo nome e username a partir de uma palavra chave. Faça o download do arquivo [users.csv.gz](https://s3.amazonaws.com/careers-picpay/users.csv.gz) que contém o banco de dados que deve ser usado na busca. Ele contém os IDs, nomes e usernames dos usuários.
### Execução

###### Exemplo
| ID | Nome | Username |
|--------------------------------------|-------------------|----------------------|
| 065d8403-8a8f-484d-b602-9138ff7dedcf | Wadson marcia | wadson.marcia |
| 5761be9e-3e27-4be8-87bc-5455db08408 | Kylton Saura | kylton.saura |
| ef735189-105d-4784-8e2d-c8abb07e72d3 | Edmundo Cassemiro | edmundo.cassemiro |
| aaa40f4e-da26-42ee-b707-cb81e00610d5 | Raimundira M | raimundiram |
| 51ba0961-8d5b-47be-bcb4-54633a567a99 | Pricila Kilder | pricilakilderitaliani|
Os seguintes passos são necessários para rodar a solução:

1) Construir a aplicação Java com o Maven
```sh
$ cd server
$ mvn clean install -DskipTests
```
2) Na pasta raiz do projeto rodar o docker-compose
```sh
$ docker-compose up
```

3) O container do Spring Boot (pic-rest) aguarda 30s para que o mongo e o elasticsearch terminem de inicializar. Após isso o projeto Java começa a rodar e inicia o job para importar os registros. O primeiro step é o download do arquivo csv.
Após o download finalizado, enquanto os registros são importados, a api já está disponível. No entanto ainda sem a priorização pelas listas de relevância.

Também são fornecidas duas listas de usuários que devem ser utilizadas para priorizar os resultados da busca. A lista 1 tem mais prioridade que a lista 2. Ou seja, se dois usuarios casam com os criterios de busca, aquele que está na lista 1 deverá ser exibido primeiro em relação àquele que está na lista 2. Os que não estão em nenhuma das listas são exibidos em seguida.
A API é protegida usando JWT, para gerar o token é necessáio fazer uma requisição POST para o endpoint de autenticação com os dados do usuário padrão:
```
curl -X POST \
http://localhost:8080/api/authenticate \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: a33b0b31-3bd6-c0aa-cab6-f250a46c5d47' \
-d '{"username":"user", "password":"password"}'
```

As listas podem ser encontradas na raiz deste repositório ([lista_relevancia_1.txt](lista_relevancia_1.txt) e [lista_relevancia_2.txt](lista_relevancia_2.txt)).
Os resultados devem ser retornados paginados de 15 em 15 registros.
O token será retornado no header da resposta.

Escolha as tecnologias que você vai usar e tente montar uma solução completa para rodar a aplicação.
O endpoint que gerencia as buscas é o /api/usr-data
Os query parameters aceitos são:
* query - O termo a ser pesquisado no name ou username
* page - a página do resultado, começando em 0
* size - a quantidade de resultados retornados, o padrão é 15

Faça um ***Fork*** deste repositório e abra um ***Pull Request***, **com seu nome na descrição**, para participar. Assim que terminar, envie um e-mail para ***[email protected]*** com o seu usuário do Github nos avisando.
Exemplo de requisição:
```
curl -X GET \
'http://localhost:8080/api/usr-data?query=rafa' \
-H 'authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJzZWN1cmUtYXBpIiwiYXVkIjoic2VjdXJlLWFwcCIsInN1YiI6InVzZXIiLCJleHAiOjE1NTM5NjY5ODIsInJvbCI6WyJST0xFX1VTRVIiXX0._wpp_VXYk1QXLu5mAxYHxwezJAh0nBc8-_1eTma9FmvLs5fJlVgbXOJVFf8U3ZuYYerrh5kiFMmSqtmk0XIrvg' \
```

-----
A interface gráfica pode ser acessada na porta 80:
http://localhost:80

### Diferenciais
Usuário: user
Senha: password

- Criar um frontend para realizar a busca com uma UX elaborada
- Criar uma solução de autenticação entre o frontend e o backend
- Ter um desempenho elevado num conjunto de dados muito grande
- Utilizar o Docker
### Observações

O MongoDB foi utilizado apenas para simular uma situação onde existe uma base de dados primária e o elasticsearch utilizado para indexação para fins de buscas (e pelo desafio de utilizar um banco não relacional).
13 changes: 13 additions & 0 deletions client/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
28 changes: 28 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### STAGE 1: Build ###

FROM node:10-alpine as builder

COPY package.json package-lock.json ./


RUN npm ci && mkdir /ng-app && mv ./node_modules ./ng-app

WORKDIR /ng-app

COPY . .


RUN npm run ng build -- --output-path=dist


### STAGE 2: Setup ###

FROM nginx:1.14.1-alpine

COPY nginx/default.conf /etc/nginx/conf.d/

RUN rm -rf /usr/share/nginx/html/*

COPY --from=builder /ng-app/dist /usr/share/nginx/html

CMD ["nginx", "-g", "daemon off;"]
27 changes: 27 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Client

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.6.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

## Code scaffolding

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.

## Build

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
Loading