forked from bbwong23/flask101
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculator_controller.py
68 lines (47 loc) · 1.6 KB
/
calculator_controller.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
###########################
# 1. import flask library
# HINT: sample/request_processing.py
###########################
import service.calculator as calculator
from http import HTTPStatus
from flask import jsonify
###########################
# 2. initialize your Flask application object
# HINT: sample/explicit_application_object.py
###########################
app =
###########################
# 3. define route paths for the following functions with the specified path and method
# HINT: sample/routing.py
# 4. and parse the request to get the user_input given the request type
# HINT: sample/request_processing.py
###########################
# path = '/mean', method = 'GET'
# request type = JSON
def mean():
# user_input =
results = calculator.mean(user_input)
return jsonify({'output':results}), HTTPStatus.OK
# path = '/median', method = 'GET and POST'
# request type = Query
def median():
# user_input =
user_input = list(map(int, user_input.split(',')))
results = calculator.median(user_input)
return jsonify({'output':results}), HTTPStatus.OK
# path = '/mode', method = 'POST'
# request type = Form
def mode():
# user_input =
user_input = list(map(int, user_input))
results = calculator.mode(user_input)
return jsonify({'output':results}), HTTPStatus.OK
# path = '/status', method = 'GET'
def status():
result = "Application is running"
return result, HTTPStatus.OK
if __name__ == '__main__':
###########################
# 5. Start your flask app
# HINT: sample/explicit_application_object.py
###########################