-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
175 lines (145 loc) · 5.37 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import os
import dotenv
from flask import Flask, jsonify, redirect, render_template, request, session, url_for
import requests
from common.models.store import Stores
from controllers.user_controller import user_controller
from controllers.post_controller import post_controller
app = Flask(__name__)
user_controller = user_controller()
post_controller = post_controller()
dotenv.load_dotenv()
app.secret_key = os.environ["SECRET_KEY"]
@app.route('/user/login', methods=['GET', 'POST'])
def login():
if user_controller.user_login_check_flag():
return redirect(url_for('index'))
if request.method == 'POST':
return user_controller.login()
else:
return render_template('user/login.html')
@app.route('/')
def index():
if user_controller.user_login_check_flag():
return render_template('index.html')
return redirect(url_for('signup'))
# usercontrollerからのリターンがあるんだから、それをそのまま返せばいいのでは…?
# 後で考えます
@app.route('/user/logout', methods=['GET'])
def logout():
return user_controller.logout()
@app.route('/user/signup', methods=['GET', 'POST'])
def signup():
if request.method == 'POST':
return user_controller.signup()
else:
if user_controller.user_login_check_flag():
return redirect(url_for('index'))
return render_template('user/signup.html')
@app.route('/user/<int:user_id>', methods=['GET'])
def user_info(user_id):
if user_controller.user_login_check_flag():
if session['user_id'] == user_id:
return user_controller.currrent_user_info()
return user_controller.user_info(user_id)
else:
return redirect(url_for('login'))
@app.route('/user/update', methods=['GET', 'POST'])
def update_user():
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
if request.method == 'POST':
return user_controller.user_update()
else:
return render_template('user/update.html')
@app.route('/user/delete', methods=['GET'])
def delete_user():
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
return user_controller.user_delete()
@app.route('/post/<int:post_id>', methods=['GET'])
def read_post(post_id):
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
return post_controller.read_post(post_id)
@app.route('/post/index', methods=['GET'])
def read_all_post():
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
return post_controller.read_all()
@app.route('/post/sort', methods=['GET'])
def read_sort_posts():
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
lati = request.args.get('lat')
long = request.args.get('long')
print("++++++++++++++")
print(lati)
print(long)
return post_controller.read_sort_posts(lati,long)
@app.route('/post/create', methods=['GET', 'POST'])
def create_post():
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
if request.method == 'POST':
return post_controller.create(session['user_id'])
else:
return render_template('post/create.html')
@app.route('/post/delete/<int:post_id>', methods=['GET'])
def delete_post(post_id):
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
return post_controller.delete(post_id)
# これいる?
@app.route('/post/update/<int:post_id>', methods=['GET', 'POST'])
def update_post(post_id):
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
if request.method == 'POST':
return post_controller.update(post_id)
else:
return render_template('post/update.html')
@app.route('/post/search', methods=['GET'])
def search_post():
if not user_controller.user_login_check_flag():
return redirect(url_for('login'))
return post_controller.read_all('state=1')
@app.errorhandler(404)
def error_404(error):
return render_template('error/404.html')
@app.errorhandler(401)
def error_401(error):
return render_template('error/401.html')
@app.errorhandler(500)
def error_500(error):
return render_template('error/500.html')
# googleのapiを呼び出すやつ
@app.route('/api/places', methods=['GET'])
def get_places():
# クライアントからのリクエストURLを取得
url = request.args.get('url')
url = url+"&key=AIzaSyATFKf-BmfXyh2H_QSjwXSLJZiAwp0cezw"
# Google Places APIへのリクエストを送信
response = requests.get(url)
# APIからのレスポンスをJSON形式でクライアントに返す
if response.status_code == 200:
return jsonify(response.json())
else:
return jsonify({"error": "API request failed"}), response.status_code
@app.route('/api/near_store', methods=['GET'])
def near_store():
lat = request.args.get('lat')
lng = request.args.get('lng')
store = Stores()
stores_info = store.get_near_stores(lat, lng)
print(stores_info)
ret = jsonify(stores_info)
print(ret)
return ret
@app.route('/api/search', methods=['GET'])
def search():
lat = request.args.get('lat')
lng = request.args.get('lng')
return post_controller.get_near_post(lat,lng)
if __name__ == ('__main__'):
app.run(debug=True, port=5050)