feat: post请求
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
kunpeng.db
BIN
kunpeng.db
Binary file not shown.
15
main.py
15
main.py
@@ -10,7 +10,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from pydantic import BaseModel
|
||||||
from flask import request, Flask
|
from flask import request, Flask
|
||||||
try:
|
try:
|
||||||
import xml.etree.cElementTree as ET
|
import xml.etree.cElementTree as ET
|
||||||
@@ -29,6 +29,7 @@ models.Base.metadata.create_all(bind=engine)
|
|||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Dependency
|
# Dependency
|
||||||
def get_db():
|
def get_db():
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
@@ -69,12 +70,12 @@ def read_users(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
|
|||||||
|
|
||||||
|
|
||||||
# 根据openId查询用户
|
# 根据openId查询用户
|
||||||
# @app.get("/users")
|
@app.post("/openId")
|
||||||
# def read_user(openId, db: Session = Depends(get_db)):
|
def read_user(user:schemas.User, db: Session = Depends(get_db)):
|
||||||
# db_user = crud.get_user_by_openId(db, openId=openId)
|
db_user = crud.get_user_by_openId(db, openId=user.openId)
|
||||||
# if db_user is None:
|
if db_user is None:
|
||||||
# raise HTTPException(status_code=404, detail="openId not found")
|
raise HTTPException(status_code=404, detail="openId not found")
|
||||||
# return db_user
|
return db_user
|
||||||
|
|
||||||
# 根据wxid查询用户
|
# 根据wxid查询用户
|
||||||
@app.get("/users")
|
@app.get("/users")
|
||||||
|
|||||||
32
schemas.py
32
schemas.py
@@ -2,24 +2,24 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
# 用户信息
|
# 用户信息
|
||||||
class UserCreate(BaseModel):
|
class UserCreate(BaseModel):
|
||||||
wxid: str
|
wxid: str | None = None
|
||||||
openId: str
|
openId: str| None = None
|
||||||
sex: str
|
sex: str| None = None
|
||||||
country: str
|
country: str| None = None
|
||||||
province: str
|
province: str| None = None
|
||||||
sourceStr: str
|
sourceStr: str| None = None
|
||||||
usertype: str
|
usertype: str| None = None
|
||||||
nickname: str
|
nickname: str| None = None
|
||||||
wxaccount: str
|
wxaccount: str| None = None
|
||||||
remark: str
|
remark: str| None = None
|
||||||
smallhead: str
|
smallhead: str| None = None
|
||||||
bighead: str
|
bighead: str| None = None
|
||||||
labels: str
|
labels: str| None = None
|
||||||
source: str
|
source: str| None = None
|
||||||
v1: str
|
v1: str| None = None
|
||||||
|
|
||||||
class User(UserCreate):
|
class User(UserCreate):
|
||||||
id: int
|
id: int| None = None
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user