add authorization and admin role
This commit is contained in:
14
crud.py
14
crud.py
@ -1,7 +1,19 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from models import Car, EngineType, HybridType, PowerRatio
|
||||
from models import Car, EngineType, HybridType, PowerRatio, Admin
|
||||
import schemas
|
||||
from typing import List, Optional
|
||||
from password_utils import get_password_hash
|
||||
|
||||
def get_admin_by_username(db: Session, username: str) -> Optional[Admin]:
|
||||
return db.query(Admin).filter(Admin.username == username).first()
|
||||
|
||||
def create_admin(db: Session, admin: schemas.AdminCreate) -> Admin:
|
||||
hashed_password = get_password_hash(admin.password)
|
||||
db_admin = Admin(username=admin.username, hashed_password=hashed_password)
|
||||
db.add(db_admin)
|
||||
db.commit()
|
||||
db.refresh(db_admin)
|
||||
return db_admin
|
||||
|
||||
def get_car(db: Session, car_id: int) -> Optional[Car]:
|
||||
return db.query(Car).filter(Car.id == car_id).first()
|
||||
|
Reference in New Issue
Block a user