chore: Update Docker image tag in dev_build.yml

feat: Update temperature endpoint to use MqttCreateRequest

chore: Update MqttCreateRequest schema in requests.py
This commit is contained in:
2024-05-04 10:40:20 +08:00
parent f10544fd36
commit d0440675ef
3 changed files with 38 additions and 7 deletions
+1 -1
View File
@@ -33,4 +33,4 @@ jobs:
with:
file: Dockerfile
push: true
tags: rafsaf/minimal-fastapi-postgres-template:${{ env.IMAGE_TAG }}
tags: furyhawk/minimal-fastapi-postgres-template:${{ env.IMAGE_TAG }}
+3 -4
View File
@@ -1,11 +1,10 @@
from typing import Any
from fastapi import APIRouter, Depends, status
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.api import deps
from app.models import Temperature
from app.schemas.requests import TemperatureCreateRequest
from app.schemas.requests import MqttCreateRequest
from app.schemas.responses import TemperatureResponse
@@ -19,10 +18,10 @@ router = APIRouter()
description="Create new temperature.",
)
async def create_temperature(
data: TemperatureCreateRequest,
data: MqttCreateRequest,
session: AsyncSession = Depends(deps.get_session),
) -> Temperature:
new_temperature = Temperature(temperature=data.temperature)
new_temperature = Temperature(temperature=data.payload)
session.add(new_temperature)
await session.commit()
return new_temperature
+34 -2
View File
@@ -22,5 +22,37 @@ class UserCreateRequest(BaseRequest):
class PetCreateRequest(BaseRequest):
pet_name: str
class TemperatureCreateRequest(BaseRequest):
temperature: str
class MqttCreateRequest(BaseRequest):
publish_received_at: int
pub_props: dict
peerhost: str
qos: int
topic: str
clientid: str
payload: str
username: str
event: str
metadata: dict
timestamp: int
node: str
id: str
flags: dict
# {
# "publish_received_at": 1714785223633,
# "pub_props": {"User-Property": {}},
# "peerhost": "192.168.50.1",
# "qos": 0,
# "topic": "temperature",
# "clientid": "e661a4d4177d8a2a",
# "payload": "27.51C",
# "username": "user1",
# "event": "message.publish",
# "metadata": {"rule_id": "sink_WH_D"},
# "timestamp": 1714785223633,
# "node": "emqx@node1.emqx.io",
# "id": "000617968C1EEAD9DB5B00000CFD0E24",
# "flags": {"retain": false, "dup": false},
# }