diff --git a/__pycache__/dependencies.cpython-310.pyc b/__pycache__/dependencies.cpython-310.pyc index 97b03e0..d7846f8 100644 Binary files a/__pycache__/dependencies.cpython-310.pyc and b/__pycache__/dependencies.cpython-310.pyc differ diff --git a/__pycache__/main.cpython-310.pyc b/__pycache__/main.cpython-310.pyc index ec99461..91a7058 100644 Binary files a/__pycache__/main.cpython-310.pyc and b/__pycache__/main.cpython-310.pyc differ diff --git a/internal/__pycache__/__init__.cpython-310.pyc b/internal/__pycache__/__init__.cpython-310.pyc index 394be32..25d0efa 100644 Binary files a/internal/__pycache__/__init__.cpython-310.pyc and b/internal/__pycache__/__init__.cpython-310.pyc differ diff --git a/internal/__pycache__/database.cpython-310.pyc b/internal/__pycache__/database.cpython-310.pyc index c61ba96..ae1c412 100644 Binary files a/internal/__pycache__/database.cpython-310.pyc and b/internal/__pycache__/database.cpython-310.pyc differ diff --git a/internal/__pycache__/models.cpython-310.pyc b/internal/__pycache__/models.cpython-310.pyc index 4a6fcde..7971511 100644 Binary files a/internal/__pycache__/models.cpython-310.pyc and b/internal/__pycache__/models.cpython-310.pyc differ diff --git a/internal/models.py b/internal/models.py index 860aed4..4626aba 100644 --- a/internal/models.py +++ b/internal/models.py @@ -42,16 +42,21 @@ class BlogList(BaseModel): )] blogtype:Annotated[str,Field( title="博客类型", - examples=['blogtype'], + default=None, description="博客类型允许为空" )] + viewsnum:Annotated[int,Field( + title="访问量", + default=None, + description="访问量可以为空" + )] addtime:Annotated[datetime,Field( title="发布时间", description="数据库中提供了默认值" )] descr:Annotated[str,Field( title="备注", - examples=['descr'], + default=None, description="备注允许为空" )] diff --git a/main.py b/main.py index 8ae1d12..37a1e9e 100644 --- a/main.py +++ b/main.py @@ -6,10 +6,9 @@ from internal.models import Token from fastapi.middleware.cors import CORSMiddleware from routers import usermanage,typemanage from internal.models import BlogList -from typing import List app=FastAPI() -# app.include_router(usermanage.router) -# app.include_router(typemanage.router) +app.include_router(usermanage.router) +app.include_router(typemanage.router) app.add_middleware( CORSMiddleware, allow_origins=['http://localhost:5173'], # 允许的源 @@ -18,23 +17,23 @@ app.add_middleware( allow_headers=['Authorization', 'Content-Type'], # 允许的请求头 ) -# 用户登录 -@app.post("/token", response_model=Token) -async def login_for_access_token( - form_data: OAuth2PasswordRequestForm = Depends(), -) -> Token: - user = authenticate_user(form_data.username, form_data.password) - if not user: - raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail="Incorrect username or password", - headers={"WWW-Authenticate": "Bearer"}, - ) - access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) - access_token = create_access_token( - data={"sub": user.username}, expires_delta=access_token_expires - ) - return {"access_token": access_token, "token_type": "bearer"} +# # 用户登录 +# @app.post("/token", response_model=Token) +# async def login_for_access_token( +# form_data: OAuth2PasswordRequestForm = Depends(), +# ) -> Token: +# user = authenticate_user(form_data.username, form_data.password) +# if not user: +# raise HTTPException( +# status_code=status.HTTP_401_UNAUTHORIZED, +# detail="Incorrect username or password", +# headers={"WWW-Authenticate": "Bearer"}, +# ) +# access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) +# access_token = create_access_token( +# data={"sub": user.username}, expires_delta=access_token_expires +# ) +# return {"access_token": access_token, "token_type": "bearer"} # 注册新用户 @app.post("/register/") @@ -62,8 +61,8 @@ async def read_users_me(current_user: User = Depends(get_current_active_user)): async def read_own_items(current_user: User = Depends(get_current_active_user)): return [{"item_id": "Foo", "owner": current_user.username}] -@app.get("/list",response_model=List[BlogList]) -def read_type_all(): - typelist="SELECT blogname,blogtype,addtime,descr FROM blogs" - result=execute_query(typelist,fetchall=True) - return result \ No newline at end of file +# @app.get("/list",response_model=list[BlogList]) +# def read_type_all(): +# select_query="SELECT blogname,blogtype,addtime,descr FROM blogs;" +# result=execute_query(select_query,fetchall=True) +# return result \ No newline at end of file diff --git a/routers/__pycache__/__init__.cpython-310.pyc b/routers/__pycache__/__init__.cpython-310.pyc index 8cb2262..d887dd1 100644 Binary files a/routers/__pycache__/__init__.cpython-310.pyc and b/routers/__pycache__/__init__.cpython-310.pyc differ diff --git a/routers/__pycache__/typemanage.cpython-310.pyc b/routers/__pycache__/typemanage.cpython-310.pyc index 6e1f47d..b10d479 100644 Binary files a/routers/__pycache__/typemanage.cpython-310.pyc and b/routers/__pycache__/typemanage.cpython-310.pyc differ diff --git a/routers/__pycache__/usermanage.cpython-310.pyc b/routers/__pycache__/usermanage.cpython-310.pyc index 2806411..435ce16 100644 Binary files a/routers/__pycache__/usermanage.cpython-310.pyc and b/routers/__pycache__/usermanage.cpython-310.pyc differ diff --git a/routers/typemanage.py b/routers/typemanage.py index 4368017..692672d 100644 --- a/routers/typemanage.py +++ b/routers/typemanage.py @@ -2,12 +2,11 @@ from fastapi import APIRouter,Depends from internal.models import* from dependencies import get_current_active_user,execute_query router=APIRouter( - prefix="/type", tags=["分类管理"] ) -@router.get("/list",response_model=BlogList) -def read_type_all(type:BlogList,_: User = Depends(get_current_active_user)): - typelist="SELECT blogname,blogtype,addtime,descr FROM blogs" - execute_query(typelist) - return type \ No newline at end of file +@router.get("/typelist",response_model=list[BlogList]) +def read_type_all(_:User=Depends(get_current_active_user)): + select_query="SELECT blogname,blogtype,viewsnum,addtime,descr FROM blogs;" + type_all=execute_query(select_query,fetchall=True) + return type_all diff --git a/routers/usermanage.py b/routers/usermanage.py index aa4ecb1..88105dd 100644 --- a/routers/usermanage.py +++ b/routers/usermanage.py @@ -7,7 +7,6 @@ from dependencies import * from internal.models import Token from fastapi.middleware.cors import CORSMiddleware router=APIRouter( - prefix="/users", tags=["用户管理"] )