targets.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. from fastapi import APIRouter, HTTPException, Query, Depends
  3. from loguru import logger
  4. from app.controllers.targets import readjust_all_target
  5. from app.models.targets import TargetReadjustInResponse
  6. from app.utils.date import get_time_str
  7. router = APIRouter()
  8. @router.get('/readjust', response_model=TargetReadjustInResponse, tags=['targets'])
  9. async def readjust_target(
  10. project_id: str = Query(..., max_length=50, regex='^Pj'),
  11. space_id: str = Query(..., max_length=50, regex='^Sp'),
  12. wechat_timestamp: str = Query(None, min_length=14, max_length=14),
  13. ):
  14. try:
  15. if not wechat_timestamp:
  16. wechat_timestamp = get_time_str()
  17. need_run_room_control = await readjust_all_target(project_id, space_id, wechat_timestamp)
  18. except Exception as e:
  19. logger.error(e)
  20. raise HTTPException(
  21. status_code=500,
  22. detail='Oops, something wrong has happened'
  23. )
  24. response = {
  25. 'projectId': project_id,
  26. 'roomId': space_id,
  27. 'flag': 1 if need_run_room_control else 0,
  28. 'time': wechat_timestamp,
  29. }
  30. return response