123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, HTTPException, Query, Depends
- from loguru import logger
- from app.controllers.targets import readjust_all_target
- from app.models.targets import TargetReadjustInResponse
- from app.utils.date import get_time_str
- router = APIRouter()
- @router.get('/readjust', response_model=TargetReadjustInResponse, tags=['targets'])
- async def readjust_target(
- project_id: str = Query(..., max_length=50, regex='^Pj'),
- space_id: str = Query(..., max_length=50, regex='^Sp'),
- wechat_timestamp: str = Query(None, min_length=14, max_length=14),
- ):
- try:
- need_run_room_control = await readjust_all_target(project_id, space_id, wechat_timestamp)
- except Exception as e:
- logger.error(e)
- raise HTTPException(
- status_code=500,
- detail='Oops, something wrong has happened'
- )
- response = {
- 'projectId': project_id,
- 'roomId': space_id,
- 'flag': 1 if need_run_room_control else 0,
- 'time': wechat_timestamp,
- }
- return response
- @router.get('/readjust/test/{project_id}/{space_id}', tags=['targets'])
- async def test_readjust(project_id: str, space_id: str, wechat_time: str = Depends(get_time_str)):
- feedback = {
- 'a little cold': 1,
- 'so cold': 0,
- 'a little hot': 1,
- 'so hot': 0,
- 'noisy or blowy': 0,
- 'so stuffy': 0,
- 'switch off': 0,
- 'switch on': 0,
- }
- await readjust_all_target(project_id, space_id, wechat_time, feedback)
- return {'Message': 'Running background'}
|