mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-28 08:40:21 -05:00
* 🌐 Refactor file structure to support internationalization * ✅ Update tests changed after i18n * 🔀 Merge Typer style from master * 🔧 Update MkConfig with Typer-styles * 🎨 Format mkdocs.yml with cannonical form * 🎨 Format mkdocs.yml * 🔧 Update MkDocs config * ➕ Add docs translation scripts dependencies * ✨ Add Typer scripts to handle translations * ✨ Add missing translation snippet to include * ✨ Update contributing docs, add docs for translations * 🙈 Add docs_build to gitignore * 🔧 Update scripts with new locations and docs scripts * 👷 Update docs deploy action with translations * 📝 Add note about languages not supported in the theme * ✨ Add first translation, for Spanish
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from sqlalchemy.orm import Session
|
|
|
|
from . import models, schemas
|
|
|
|
|
|
def get_user(db: Session, user_id: int):
|
|
return db.query(models.User).filter(models.User.id == user_id).first()
|
|
|
|
|
|
def get_user_by_email(db: Session, email: str):
|
|
return db.query(models.User).filter(models.User.email == email).first()
|
|
|
|
|
|
def get_users(db: Session, skip: int = 0, limit: int = 100):
|
|
return db.query(models.User).offset(skip).limit(limit).all()
|
|
|
|
|
|
def create_user(db: Session, user: schemas.UserCreate):
|
|
fake_hashed_password = user.password + "notreallyhashed"
|
|
db_user = models.User(email=user.email, hashed_password=fake_hashed_password)
|
|
db.add(db_user)
|
|
db.commit()
|
|
db.refresh(db_user)
|
|
return db_user
|
|
|
|
|
|
def get_items(db: Session, skip: int = 0, limit: int = 100):
|
|
return db.query(models.Item).offset(skip).limit(limit).all()
|
|
|
|
|
|
def create_user_item(db: Session, item: schemas.ItemCreate, user_id: int):
|
|
db_item = models.Item(**item.dict(), owner_id=user_id)
|
|
db.add(db_item)
|
|
db.commit()
|
|
db.refresh(db_item)
|
|
return db_item
|