Prvni pokus o verejny pristup, sprava profilu
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
from database.models import User, Flight, Copilot, Airport, Aircraft
|
||||
from endpoints.base import BaseEndpoint
|
||||
|
||||
|
||||
class InitDataEndpoint(BaseEndpoint):
|
||||
|
||||
async def on_get(self):
|
||||
user_ids = []
|
||||
copilot_ids = []
|
||||
flight_ids = []
|
||||
|
||||
users = [
|
||||
User(avatar_image_url="", name="Karel Vomacka", email="a@test.cz", password_hashed="****"),
|
||||
User(avatar_image_url="", name="Karel Novak", email="b@test.cz", password_hashed="****"),
|
||||
User(avatar_image_url="", name="Franta Pavel", email="c@test.cz", password_hashed="****"),
|
||||
]
|
||||
|
||||
airport = Airport(name="Letiste Letnany", icao_code="LKLT")
|
||||
self.db.add(airport)
|
||||
|
||||
for user in users:
|
||||
self.db.add(user)
|
||||
await self.db.flush()
|
||||
user_ids.append(user.id)
|
||||
|
||||
aircraft = Aircraft(name="OK-AUR28", type="Bristell NG5", description="", created_by=user)
|
||||
self.db.add(aircraft)
|
||||
|
||||
copilot = None
|
||||
if user.name == 'Franta Pavel':
|
||||
copilot = Copilot(name="Copilot test", created_by_id=user.id)
|
||||
self.db.add(copilot)
|
||||
await self.db.flush()
|
||||
|
||||
copilot_ids.append(copilot.id)
|
||||
|
||||
flight = Flight(name="test flight", description="Testovaci popis", duration_total=65, duration_pic=65,
|
||||
takeoff_airport=airport, landing_airport=airport, aircraft=aircraft, created_by_id=user.id,
|
||||
copilot_id=copilot.id if copilot else None)
|
||||
self.db.add(flight)
|
||||
await self.db.flush()
|
||||
flight_ids.append(flight.id)
|
||||
|
||||
return {
|
||||
"user_ids": user_ids,
|
||||
"copilot_ids": copilot_ids,
|
||||
"flight_ids": flight_ids,
|
||||
'airport_id': airport.id
|
||||
}
|
||||
|
||||
#
|
||||
#
|
||||
# self.db.add(Flight(name="test"))
|
||||
# await self.db.flush()
|
||||
#
|
||||
# data = await self.db.execute(select(Flight).order_by(desc(Flight.id)))
|
||||
# model = data.scalars().first()
|
||||
# return {
|
||||
# "status": model
|
||||
# }
|
||||
@@ -4,7 +4,6 @@ from fastapi_jwt.jwt import JwtAccess, JwtRefresh
|
||||
from passlib.hash import bcrypt
|
||||
from sqlalchemy import select
|
||||
from starlette.responses import Response
|
||||
|
||||
from database.models import User
|
||||
from endpoints.base import BaseEndpoint
|
||||
from pydantic import BaseModel
|
||||
@@ -74,15 +73,3 @@ class RefreshEndpoint(BaseEndpoint):
|
||||
"access_token": access_token,
|
||||
"access_token_validity": self.access_security.access_expires_delta.total_seconds(),
|
||||
}
|
||||
|
||||
|
||||
class MeEndpoint(BaseEndpoint):
|
||||
|
||||
async def on_get(self, credentials) -> dict:
|
||||
if not credentials:
|
||||
raise HTTPException(status_code=401)
|
||||
|
||||
query = select(User).filter_by(id=credentials['id'])
|
||||
user = (await self.db.scalars(query)).first()
|
||||
|
||||
return user.as_dict()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import re
|
||||
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy import select
|
||||
from typing import Optional
|
||||
|
||||
Reference in New Issue
Block a user