# -*- 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: if not wechat_timestamp: wechat_timestamp = get_time_str() 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