db issue 1.0
This commit is contained in:
4
run.py
4
run.py
@@ -1,5 +1,7 @@
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
from server.backend import endpoints # импортируем FastAPI экземпляр из файла app.py
|
from server.backend import endpoints # импортируем FastAPI экземпляр из файла app.py
|
||||||
|
import asyncio
|
||||||
|
from server.database import db
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(db.main())
|
||||||
uvicorn.run("server.backend.endpoints:api", host="127.0.0.1", port=8000, reload=True)
|
uvicorn.run("server.backend.endpoints:api", host="127.0.0.1", port=8000, reload=True)
|
||||||
@@ -43,7 +43,11 @@ async def get_user(id: int, current_user: str = Depends(JWT.current_user)):
|
|||||||
raise HTTPException(status_code=404, detail="The user isn't found")
|
raise HTTPException(status_code=404, detail="The user isn't found")
|
||||||
@api.post("/user_create", response_model=pydentic.IdofPersons)
|
@api.post("/user_create", response_model=pydentic.IdofPersons)
|
||||||
async def create_user(row:pydentic.CreateUser):
|
async def create_user(row:pydentic.CreateUser):
|
||||||
new_user_id = max(item.id for item in await db.get_all_rows())
|
rows = await db.get_all_rows()
|
||||||
|
if rows:
|
||||||
|
new_user_id = max(item.id for item in rows) + 1
|
||||||
|
else:
|
||||||
|
new_user_id = 1
|
||||||
new_row = pydentic.IdofPersons(id = new_user_id, email=row.email, description=row.description, activated = row.activated, password = row.password)
|
new_row = pydentic.IdofPersons(id = new_user_id, email=row.email, description=row.description, activated = row.activated, password = row.password)
|
||||||
await db.CreateUser(new_row)
|
await db.CreateUser(new_row)
|
||||||
return new_row
|
return new_row
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ async def CreateUser(user_info):
|
|||||||
session.add(new_user)
|
session.add(new_user)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
await session.refresh(new_user)
|
await session.refresh(new_user)
|
||||||
print(new_user.id)
|
|
||||||
async def GetUser(id):
|
async def GetUser(id):
|
||||||
async with AsyncSessionLocal() as session:
|
async with AsyncSessionLocal() as session:
|
||||||
result = await session.execute(select(User).where(User.id==id))
|
result = await session.execute(select(User).where(User.id==id))
|
||||||
@@ -80,10 +79,8 @@ async def LoginUser(user_info):
|
|||||||
return None
|
return None
|
||||||
async def main():
|
async def main():
|
||||||
await init_db()
|
await init_db()
|
||||||
await CreateUser()
|
#await CreateUser()
|
||||||
await get_all_rows()
|
# await get_all_rows()
|
||||||
# await UpdateUser(1)
|
# await UpdateUser(1)
|
||||||
# await GetUser(1)
|
# await GetUser(1)
|
||||||
# await DeleteUser(1)
|
# await DeleteUser(1)
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
Reference in New Issue
Block a user