-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update configurations and code formatting
- Loading branch information
Showing
24 changed files
with
259 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ POSTGRES_HOST= | |
POSTGRES_PORT= | ||
POSTGRES_DB= | ||
POSTGRES_SCHEMA= | ||
DATABASE_URL= | ||
|
||
# RabbitMQ | ||
CLOUDAMQP_URL= | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
## Linked ticket in Jira | ||
- https://hanagotchi.atlassian.net/jira/software/projects/HAN/boards/1/backlog | ||
|
||
## Describe your changes, marking the new features and possible risks | ||
- | ||
|
||
## Media: upload photos or videos (if needed) | ||
- | ||
## Linked ticket in Jira | ||
- https://hanagotchi.atlassian.net/jira/software/projects/HAN/boards/1/backlog | ||
|
||
## Describe your changes, marking the new features and possible risks | ||
- | ||
|
||
## Media: upload photos or videos (if needed) | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
|
||
name: Linters | ||
|
||
on: 'push' | ||
|
||
jobs: | ||
run-linters: | ||
name: Run linters | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install Python dependencies | ||
run: pip install black flake8 | ||
|
||
- name: Run linters | ||
uses: wearerequired/lint-action@v1 | ||
with: | ||
black: true | ||
|
||
- name: flake8 Lint | ||
uses: py-actions/flake8@v1.2.0 | ||
with: | ||
|
||
name: Linters | ||
|
||
on: 'push' | ||
|
||
jobs: | ||
run-linters: | ||
name: Run linters | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install Python dependencies | ||
run: pip install black flake8 | ||
|
||
- name: Run linters | ||
uses: wearerequired/lint-action@v1 | ||
with: | ||
black: true | ||
|
||
- name: flake8 Lint | ||
uses: py-actions/flake8@v1.2.0 | ||
with: | ||
max-line-length: "88" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
default: docker-compose-up | ||
|
||
all: | ||
|
||
create-network: | ||
@if ! docker network inspect common_network >/dev/null 2>&1; then \ | ||
docker network create common_network; \ | ||
fi | ||
.PHONY: create-network | ||
|
||
docker-image: create-network | ||
docker build -f ./Dockerfile -t "app:latest" . | ||
.PHONY: docker-image | ||
|
||
docker-compose-up: docker-image | ||
docker-compose -f docker-compose.yaml up -d --build | ||
.PHONY: docker-compose-up | ||
|
||
docker-compose-down: | ||
docker-compose -f docker-compose.yaml stop -t 20 | ||
docker-compose -f docker-compose.yaml down --remove-orphans | ||
.PHONY: docker-compose-down | ||
|
||
docker-compose-logs: | ||
docker-compose -f docker-compose.yaml logs -f | ||
.PHONY: docker-compose-logs | ||
default: docker-compose-up | ||
|
||
all: | ||
|
||
create-network: | ||
@if ! docker network inspect common_network >/dev/null 2>&1; then \ | ||
docker network create common_network; \ | ||
fi | ||
.PHONY: create-network | ||
|
||
docker-image: create-network | ||
docker build -f ./Dockerfile -t "app:latest" . | ||
.PHONY: docker-image | ||
|
||
docker-compose-up: docker-image | ||
docker-compose -f docker-compose.yaml up -d --build | ||
.PHONY: docker-compose-up | ||
|
||
docker-compose-down: | ||
docker-compose -f docker-compose.yaml stop -t 20 | ||
docker-compose -f docker-compose.yaml down --remove-orphans | ||
.PHONY: docker-compose-down | ||
|
||
docker-compose-logs: | ||
docker-compose -f docker-compose.yaml logs -f | ||
.PHONY: docker-compose-logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
from fastapi import status | ||
|
||
|
||
class CalculatorController: | ||
def __init__(self, service): | ||
self.service = service | ||
|
||
def handle_sum(self, request): | ||
sum = request.number1 + request.number2 | ||
self.service.add_number(sum) | ||
return { | ||
'result': sum, | ||
'status': status.HTTP_200_OK | ||
} | ||
from fastapi import status | ||
|
||
|
||
class CalculatorController: | ||
def __init__(self, service): | ||
self.service = service | ||
|
||
def handle_sum(self, request): | ||
sum = request.number1 + request.number2 | ||
self.service.add_number(sum) | ||
return { | ||
'result': sum, | ||
'status': status.HTTP_200_OK | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from controller.device_plant_controller import withSQLExceptionsHandle | ||
from fastapi import Request | ||
|
||
|
||
@withSQLExceptionsHandle | ||
def last_measurement_made_by_plant(req: Request, id_plant: int): | ||
try: | ||
return req.app.database.get_last_measurement(id_plant) | ||
except Exception as err: | ||
req.app.database.rollback() | ||
raise err | ||
from controller.device_plant_controller import withSQLExceptionsHandle | ||
from fastapi import Request | ||
|
||
|
||
@withSQLExceptionsHandle | ||
def last_measurement_made_by_plant(req: Request, id_plant: int): | ||
try: | ||
return req.app.database.get_last_measurement(id_plant) | ||
except Exception as err: | ||
req.app.database.rollback() | ||
raise err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class MeasurementsException(Exception): | ||
def __init__(self, status_code, message): | ||
self.status_code = status_code | ||
self.message = message | ||
class MeasurementsException(Exception): | ||
def __init__(self, status_code, message): | ||
self.status_code = status_code | ||
self.message = message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class EmptyPackageError(Exception): | ||
def __init__(self, empty_folds: list): | ||
self.empty_folds = empty_folds | ||
super().__init__(f"Package received with empty folds: {self.empty_folds}.") | ||
class EmptyPackageError(Exception): | ||
def __init__(self, empty_folds: list): | ||
self.empty_folds = empty_folds | ||
super().__init__(f"Package received with empty folds: {self.empty_folds}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
class InvalidInsertionError(Exception): | ||
def __init__(self, item, name_table): | ||
self.item = item | ||
self.name_table = name_table | ||
super().__init__( | ||
f"Failed to insert {self.item} in {self.name_table.upper()} table.") | ||
class InvalidInsertionError(Exception): | ||
def __init__(self, item, name_table): | ||
self.item = item | ||
self.name_table = name_table | ||
super().__init__( | ||
f"Failed to insert {self.item} in {self.name_table.upper()} table.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
from fastapi import FastAPI | ||
from database.database import SQLAlchemyClient | ||
import logging | ||
from controller.calculator_controller import CalculatorController | ||
from schemas.schemas import Request as RequestSchema | ||
from service.calculator_service import CalculatorService | ||
from router import api_router | ||
|
||
app = FastAPI() | ||
service = CalculatorService() | ||
controller = CalculatorController(service) | ||
|
||
logger = logging.getLogger("measurements") | ||
logger.setLevel("DEBUG") | ||
|
||
|
||
@app.on_event("startup") | ||
async def start_up(): | ||
app.logger = logger | ||
|
||
try: | ||
app.database = SQLAlchemyClient() | ||
app.logger.info("Postgres connection established") | ||
except Exception as e: | ||
app.logger.error(e) | ||
app.logger.error("Could not connect to Postgres client") | ||
|
||
|
||
@app.on_event("shutdown") | ||
async def shutdown_db_client(): | ||
app.database.shutdown() | ||
app.logger.info("Postgres shutdown succesfully") | ||
|
||
|
||
@app.get("/") | ||
async def root(): | ||
return {"message": "Hello World"} | ||
|
||
|
||
@app.post("/sum") | ||
async def calculator(request: RequestSchema): | ||
return controller.handle_sum(request) | ||
|
||
|
||
""" # Endpoint only for DB conection testing. | ||
@app.post("/device-plant") | ||
async def add_new_device_plant(req: Request, | ||
device_plant: DevicePlantSchema = Body(...)): | ||
try: | ||
req.app.database.add_new(DevicePlant.from_pydantic(device_plant)) | ||
return req.app.database.find_device_plant(device_plant.id_device) | ||
except Exception as e: | ||
req.app.database.rollback() | ||
raise e """ | ||
|
||
app.include_router(api_router) | ||
from fastapi import FastAPI | ||
from database.database import SQLAlchemyClient | ||
import logging | ||
from controller.calculator_controller import CalculatorController | ||
from schemas.schemas import Request as RequestSchema | ||
from service.calculator_service import CalculatorService | ||
from router import api_router | ||
|
||
app = FastAPI() | ||
service = CalculatorService() | ||
controller = CalculatorController(service) | ||
|
||
logger = logging.getLogger("measurements") | ||
logger.setLevel("DEBUG") | ||
|
||
|
||
@app.on_event("startup") | ||
async def start_up(): | ||
app.logger = logger | ||
|
||
try: | ||
app.database = SQLAlchemyClient() | ||
app.logger.info("Postgres connection established") | ||
except Exception as e: | ||
app.logger.error(e) | ||
app.logger.error("Could not connect to Postgres client") | ||
|
||
|
||
@app.on_event("shutdown") | ||
async def shutdown_db_client(): | ||
app.database.shutdown() | ||
app.logger.info("Postgres shutdown succesfully") | ||
|
||
|
||
@app.get("/") | ||
async def root(): | ||
return {"message": "Hello World"} | ||
|
||
|
||
@app.post("/sum") | ||
async def calculator(request: RequestSchema): | ||
return controller.handle_sum(request) | ||
|
||
|
||
""" # Endpoint only for DB conection testing. | ||
@app.post("/device-plant") | ||
async def add_new_device_plant(req: Request, | ||
device_plant: DevicePlantSchema = Body(...)): | ||
try: | ||
req.app.database.add_new(DevicePlant.from_pydantic(device_plant)) | ||
return req.app.database.find_device_plant(device_plant.id_device) | ||
except Exception as e: | ||
req.app.database.rollback() | ||
raise e """ | ||
|
||
app.include_router(api_router) |
Oops, something went wrong.