-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrud.py
More file actions
45 lines (32 loc) · 1.23 KB
/
crud.py
File metadata and controls
45 lines (32 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from sqlalchemy.orm import Session
# from . import models, schemas
# import models, schemas
import models
import schemas
import middleware
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.CreateUser):
print(user)
# Set up variables to pass to the model
# fake_hashed_password = user.password + "notreallyhashed"
hashed_password = middleware.get_password_hash(user.password)
# create user model
# db_user = models.User(email=user.email, hashed_password=fake_hashed_password, picture_path = user.picture_path)
db_user = models.User(
first_name=user.first_name,
last_name=user.last_name,
phone_number=user.phone_number,
email=user.email,
profile_picture_link=user.profile_picture_id,
hashed_password=hashed_password
)
# add to DB
db.add(db_user)
db.commit()
db.refresh(db_user)
return db_user