diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index 294d084..2407105 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/__pycache__/schemas.cpython-312.pyc b/__pycache__/schemas.cpython-312.pyc index d3e47b3..ce17009 100644 Binary files a/__pycache__/schemas.cpython-312.pyc and b/__pycache__/schemas.cpython-312.pyc differ diff --git a/kunpeng.db b/kunpeng.db index 70d1b97..67c6898 100644 Binary files a/kunpeng.db and b/kunpeng.db differ diff --git a/main.py b/main.py index 92f6faa..191acd6 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,7 @@ import json import os import threading import time - +from pydantic import BaseModel from flask import request, Flask try: import xml.etree.cElementTree as ET @@ -29,6 +29,7 @@ models.Base.metadata.create_all(bind=engine) app = FastAPI() + # Dependency def get_db(): db = SessionLocal() @@ -69,12 +70,12 @@ def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): # 根据openId查询用户 -# @app.get("/users") -# def read_user(openId, db: Session = Depends(get_db)): -# db_user = crud.get_user_by_openId(db, openId=openId) -# if db_user is None: -# raise HTTPException(status_code=404, detail="openId not found") -# return db_user +@app.post("/openId") +def read_user(user:schemas.User, db: Session = Depends(get_db)): + db_user = crud.get_user_by_openId(db, openId=user.openId) + if db_user is None: + raise HTTPException(status_code=404, detail="openId not found") + return db_user # 根据wxid查询用户 @app.get("/users") diff --git a/schemas.py b/schemas.py index 687718b..625577c 100644 --- a/schemas.py +++ b/schemas.py @@ -2,24 +2,24 @@ from pydantic import BaseModel # 用户信息 class UserCreate(BaseModel): - wxid: str - openId: str - sex: str - country: str - province: str - sourceStr: str - usertype: str - nickname: str - wxaccount: str - remark: str - smallhead: str - bighead: str - labels: str - source: str - v1: str + wxid: str | None = None + openId: str| None = None + sex: str| None = None + country: str| None = None + province: str| None = None + sourceStr: str| None = None + usertype: str| None = None + nickname: str| None = None + wxaccount: str| None = None + remark: str| None = None + smallhead: str| None = None + bighead: str| None = None + labels: str| None = None + source: str| None = None + v1: str| None = None class User(UserCreate): - id: int + id: int| None = None class Config: orm_mode = True