forked from Rvelchuri/Movie_rating
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrud.py
54 lines (37 loc) · 1.29 KB
/
crud.py
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
46
47
48
49
50
51
52
53
54
"""CRUD operations."""
from model import db, User, Movie, Rating, connect_to_db
from datetime import datetime
# Functions start here!
if __name__ == '__main__':
from server import app
connect_to_db(app)
def create_user(email, password):
"""Create and return a new user."""
user = User(email= email, password = password)
db.session.add(user)
db.session.commit()
return user
def create_movie(title, overview, release_date, poster_path):
movie = Movie(title=title, overview=overview, release_date=release_date, poster_path=poster_path)
db.session.add(movie)
db.session.commit()
return movie
def create_rating(user,movie,score):
rating = Rating(user = user, movie = movie, score = score)
db.session.add(rating)
db.session.commit()
return rating
def return_movie():
return Movie.query.all()
def get_movie_by_id(movie_id):
return Movie.query.get(movie_id)
def return_user():
return User.query.all()
def get_user_by_id(user_id):
return User.query.get(user_id)
def get_user_by_email(email):
return User.query.filter(User.email == email).first()
def login_user(email, password):
return User.query.filter((User.email == email) & (User.password == password)).first()
def get_rating(score):
return Rating.query.get(score)