-
Notifications
You must be signed in to change notification settings - Fork 70
/
app.py
39 lines (27 loc) · 1.15 KB
/
app.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
from flask import Flask, redirect, render_template, request
from src.repositories.movie_repository import movie_repository_singleton
app = Flask(__name__)
@app.get('/')
def index():
return render_template('index.html')
@app.get('/movies')
def list_all_movies():
# TODO: Feature 1
return render_template('list_all_movies.html', list_movies_active=True, movie_list = movie_repository_singleton.get_all_movies())
@app.get('/movies/new')
def create_movies_form():
return render_template('create_movies_form.html', create_rating_active=True)
@app.post('/movies')
def create_movie():
title = request.form.get('title')
director = request.form.get('director')
rating = request.form.get('rating')
movie_repository_singleton.create_movie(title, director, rating)
# After creating the movie in the database, we redirect to the list all movies page
return redirect('/movies')
@app.get('/movies/search')
def search_movies():
# TODO: Feature 3
title = request.args.get("title")
mymovie = movie_repository_singleton.get_movie_by_title(title)
return render_template('search_movies.html', search_active=True, mymovie=mymovie)