Skip to content

Commit

Permalink
Api with docker (#4)
Browse files Browse the repository at this point in the history
* docker

* docker

* instalando dependências

* docker bugs

* docker bugs

* collections postman

* doc melhoria
  • Loading branch information
victor-hugo-sofist authored Jan 25, 2024
1 parent ec72d80 commit 4fa8fa9
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 1 deletion.
172 changes: 172 additions & 0 deletions API - Python com flask.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"info": {
"_postman_id": "184a292a-c4ff-4540-bc8a-a472609261c1",
"name": "API - Python com flask",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "29845617"
},
"item": [
{
"name": "Home API",
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [],
"url": {
"raw": "http://192.168.0.40:5000/",
"protocol": "http",
"host": [
"192",
"168",
"0",
"40"
],
"port": "5000",
"path": [
""
]
}
},
"response": []
},
{
"name": "Produtos cadastrados",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://192.168.0.40:5000/stocks/",
"protocol": "http",
"host": [
"192",
"168",
"0",
"40"
],
"port": "5000",
"path": [
"stocks",
""
]
}
},
"response": []
},
{
"name": "Procurar um produto",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://192.168.0.40:5000/stock/ITIU4/",
"protocol": "http",
"host": [
"192",
"168",
"0",
"40"
],
"port": "5000",
"path": [
"stock",
"ITIU4",
""
]
}
},
"response": []
},
{
"name": "Novo produto",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"Name\": \"ITI BANCO DIGITAL\",\r\n \"Symbol\": \"ITIU4\",\r\n \"Price\": 6\r\n}"
},
"url": {
"raw": "http://192.168.0.40:5000/new/stock/",
"protocol": "http",
"host": [
"192",
"168",
"0",
"40"
],
"port": "5000",
"path": [
"new",
"stock",
""
]
}
},
"response": []
},
{
"name": "Update product price",
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"Price\": 2\r\n}"
},
"url": {
"raw": "http://192.168.0.40:5000/stock/ITIU4/change/price/",
"protocol": "http",
"host": [
"192",
"168",
"0",
"40"
],
"port": "5000",
"path": [
"stock",
"ITIU4",
"change",
"price",
""
]
}
},
"response": []
},
{
"name": "Deletar produto",
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "http://192.168.0.40:5000/stock/delete/ITIU4/",
"protocol": "http",
"host": [
"192",
"168",
"0",
"40"
],
"port": "5000",
"path": [
"stock",
"delete",
"ITIU4",
""
]
}
},
"response": []
}
]
}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use uma imagem base do Python
FROM python:3.8

# Define o diretório de trabalho no contêiner
WORKDIR /app

# Copia o conteúdo do diretório atual para o diretório de trabalho
COPY . /app

# Instala as dependências do projeto
RUN pip install -r requirements.txt

# Expõe a porta que a aplicação Flask utiliza
EXPOSE 5000

# Comando para executar a aplicação quando o contêiner iniciar
CMD ["python", "main.py"]
6 changes: 6 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

Este projeto se trata de uma API capaz de armazenar produtos, exibir produtos cadastrados, realizar pesquisa por um produto, atualizar preços e deletar produtos.

## Instalando dependências
> `pip install -r requirements.txt`
## Executando a API
> `python main.py`
## Executando a as requests no Postman
Após instalar o Postman, procure pela opção `import`, arraste o arquivo `API - Python com flask.postman_collection.json` contido na pasta principal e finalize a ação.

## Testes unitários
### Para executar todos os testes:
> `python -m unittest`
Expand Down
5 changes: 4 additions & 1 deletion app/controller/route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from flask import Flask
from app.business.stock_business import *
import os

app = Flask(__name__, template_folder='C:\\projeto\\new-mentoria-api\\app\controller\\views')
file_path = os.path.dirname(os.path.abspath(__file__))
template_views = file_path + '/views'
app = Flask(__name__, template_folder = template_views)

@app.route('/', methods = ['GET'])
def home():
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"

services:
client:
image: python:3.8
working_dir: /app
volumes:
- ./:/app
ports:
- "5000:5000"
command: sh -c "pip install -r requirements.txt && python main.py"

0 comments on commit 4fa8fa9

Please sign in to comment.