小程序后端接入 talkingq 共享库并新增消息与定位能力
This commit is contained in:
@@ -6,11 +6,11 @@ from pydantic import BaseModel
|
||||
|
||||
try:
|
||||
from app.security import get_current_user_id
|
||||
from app.service.binding import BindingService
|
||||
from app.service.binding import BindingError, BindingService
|
||||
from app.service import get_db_session
|
||||
except ModuleNotFoundError:
|
||||
from security import get_current_user_id
|
||||
from service.binding import BindingService
|
||||
from service.binding import BindingError, BindingService
|
||||
from service import get_db_session
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ logger = logging.getLogger("app.bindings")
|
||||
|
||||
class BindStartRequest(BaseModel):
|
||||
device_id: str
|
||||
serial_number: str
|
||||
child_id: int | None = None
|
||||
|
||||
|
||||
@@ -80,7 +81,15 @@ def start_bind(
|
||||
db=Depends(get_db_session),
|
||||
) -> BindStartResponse:
|
||||
service = BindingService(db)
|
||||
bind_token, expires_at = service.start_bind(current_user_id, payload.device_id, payload.child_id)
|
||||
try:
|
||||
bind_token, expires_at = service.start_bind(
|
||||
current_user_id,
|
||||
payload.device_id,
|
||||
payload.serial_number,
|
||||
payload.child_id,
|
||||
)
|
||||
except BindingError as e:
|
||||
raise HTTPException(status_code=e.status_code, detail=str(e))
|
||||
return BindStartResponse(bind_token=bind_token, expires_at=expires_at.isoformat())
|
||||
|
||||
|
||||
@@ -94,6 +103,8 @@ def confirm_bind(
|
||||
service = BindingService(db)
|
||||
try:
|
||||
result = service.confirm_bind(payload.bind_token, current_user_id)
|
||||
except BindingError as e:
|
||||
raise HTTPException(status_code=e.status_code, detail=str(e))
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
return BindConfirmResponse(**result)
|
||||
@@ -101,6 +112,7 @@ def confirm_bind(
|
||||
|
||||
class DirectBindRequest(BaseModel):
|
||||
device_id: str
|
||||
serial_number: str
|
||||
child_id: int | None = None
|
||||
|
||||
|
||||
@@ -121,7 +133,15 @@ def direct_bind(
|
||||
db=Depends(get_db_session),
|
||||
) -> DirectBindResponse:
|
||||
service = BindingService(db)
|
||||
result = service.direct_bind(payload.device_id, payload.child_id, current_user_id)
|
||||
try:
|
||||
result = service.direct_bind(
|
||||
payload.device_id,
|
||||
payload.serial_number,
|
||||
payload.child_id,
|
||||
current_user_id,
|
||||
)
|
||||
except BindingError as e:
|
||||
raise HTTPException(status_code=e.status_code, detail=str(e))
|
||||
return DirectBindResponse(**result)
|
||||
|
||||
|
||||
@@ -136,6 +156,8 @@ def set_binding_child(
|
||||
service = BindingService(db)
|
||||
try:
|
||||
result = service.set_binding_child(device_id=device_id, child_id=payload.child_id, user_id=current_user_id)
|
||||
except BindingError as e:
|
||||
raise HTTPException(status_code=e.status_code, detail=str(e))
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
return DirectBindResponse(**result)
|
||||
|
||||
Reference in New Issue
Block a user