feat: post请求

This commit is contained in:
hackrobot
2024-03-21 00:48:22 +08:00
parent 31a546dabb
commit 5a254b1e3f
5 changed files with 24 additions and 23 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

15
main.py
View File

@@ -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")

View File

@@ -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