diff --git a/API - Python com flask.postman_collection.json b/API - Python com flask.postman_collection.json new file mode 100644 index 0000000..0bbcbca --- /dev/null +++ b/API - Python com flask.postman_collection.json @@ -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": [] + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c1e0d0b --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.MD b/README.MD index d405ebc..2a34ddd 100644 --- a/README.MD +++ b/README.MD @@ -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` diff --git a/app/controller/route.py b/app/controller/route.py index df4491f..e4208b1 100644 --- a/app/controller/route.py +++ b/app/controller/route.py @@ -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(): diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f0b5a18 --- /dev/null +++ b/docker-compose.yml @@ -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" \ No newline at end of file