123456789101112131415161718192021222324252627282930313233343536 |
- # -*- coding: utf-8 -*-
- from fastapi import APIRouter, HTTPException, Query
- 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('/adjust', response_model=TargetReadjustInResponse, tags=['targets'])
- async def readjust_target(
- projectId: str = Query(..., max_length=50, regex='^Pj'),
- roomId: str = Query(..., max_length=50, regex='^Sp'),
- time: str = Query(None, min_length=14, max_length=14),
- ):
- try:
- if not time:
- time = get_time_str()
- need_run_room_control = await readjust_all_target(projectId, roomId, time)
- except Exception as e:
- logger.error(e)
- raise HTTPException(
- status_code=500,
- detail='Oops, something wrong has happened'
- )
- response = {
- 'projectId': projectId,
- 'roomId': roomId,
- 'flag': 1 if need_run_room_control else 0,
- 'time': time,
- }
- return response
|