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

HAN 98: Refactor #27

Merged
merged 14 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
3 changes: 3 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ PLANT_SERVICE_URL=
# RabbitMQ
CLOUDAMQP_URL=
QUEUE_NAME=

#Firebase
FIREBASE_CREDENTIALS=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ __pycache__/
.idea/
/venv/*
*.lock
.DS_Store
vscode/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ EXPOSE ${PORT}

COPY app/ ./

CMD ["sh", "-c", "uvicorn main:app --reload --host 0.0.0.0 --port ${PORT} & python main_rabbitmq.py"]
CMD ["sh", "-c", "uvicorn main2:app --reload --host 0.0.0.0 --port ${PORT} & python main_rabbitmq.py"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ create-network:
.PHONY: create-network

docker-image: create-network
docker build -f ./Dockerfile -t "app:latest" .
docker build --no-cache -f ./Dockerfile -t "app:latest" .
.PHONY: docker-image

docker-compose-up: docker-image
Expand Down
14 changes: 0 additions & 14 deletions app/controller/calculator_controller.py

This file was deleted.

169 changes: 0 additions & 169 deletions app/controller/device_plant_controller.py

This file was deleted.

31 changes: 0 additions & 31 deletions app/controller/measurement_controller.py

This file was deleted.

80 changes: 80 additions & 0 deletions app/controller/measurements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from fastapi import status
from fastapi.responses import JSONResponse
from service.measurements import MeasurementsService
from service.plants import PlantsService
from schemas.measurement import MeasurementSavedSchema


class MeasurementsController:
def __init__(self, measurements_service: MeasurementsService,
plants_service: PlantsService):
self.measurements_service = measurements_service
self.plants_service = plants_service

def handle_get_plant_last_measurement(self,
id_plant: int) -> MeasurementSavedSchema:
measurement = self.measurements_service.get_plant_last_measurement(id_plant)
return measurement

async def handle_create_device_plant_relation(self, device_plant: dict):
plant_id = device_plant["id_plant"]
plant = await self.plants_service.get_plant(plant_id)
device_plant = self.measurements_service.create_device_plant_relation(
plant,
device_plant)
if not device_plant:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={
"plant_id": (
"Could not found any plant "
f"with id {device_plant.get('id_plant')}"
)
},
)
return JSONResponse(
status_code=status.HTTP_201_CREATED,
content=device_plant
)

async def handle_update_device_plant(self, id_device: str,
update_device_plant_info: dict):
plant_id = update_device_plant_info.get("id_plant")
if not plant_id:
device_plant = self.measurements_service.get_device_plant(
id_device=id_device)
else:
plant = await self.plants_service.get_plant(
update_device_plant_info.get("id_plant"))
device_plant = self.measurements_service.update_device_plant(id_device,
plant,
plant_id)
return JSONResponse(
status_code=status.HTTP_200_OK,
content=device_plant
)

def handle_get_device_plant(self, query_params: dict):
device_plant = self.measurements_service.get_device_plant(
query_params=query_params)
if not device_plant:
return JSONResponse(
status_code=status.HTTP_204_NO_CONTENT,
content={}
)
return JSONResponse(
status_code=status.HTTP_200_OK,
content=device_plant
)

def handle_delete_device_plant_relation(self, type_id, id):
response = self.measurements_service.delete_device_plant_relation(type_id, id)
if response:
Agustinefe marked this conversation as resolved.
Show resolved Hide resolved
return JSONResponse(
status_code=status.HTTP_200_OK,
content=response
)
return JSONResponse(
status_code=status.HTTP_204_NO_CONTENT,
content={}
)
Loading
Loading