
--- action.py
+++ action.py
... | ... | @@ -1,6 +1,5 @@ |
1 | 1 |
|
2 | 2 |
from flask_restx import Resource, Namespace, fields |
3 |
-from flask import request,jsonify |
|
4 | 3 |
from flask import Flask, request |
5 | 4 |
import os |
6 | 5 |
from database.database import DB |
... | ... | @@ -33,7 +32,7 @@ |
33 | 32 |
def post(self): |
34 | 33 |
token = request.headers.get('Authorization') |
35 | 34 |
if not token: |
36 |
- return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}) |
|
35 |
+ return {'result': 'fail', 'msg': '토큰이 없습니다.'} |
|
37 | 36 |
else: |
38 | 37 |
# Decode the token to verify it |
39 | 38 |
decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
... | ... | @@ -44,21 +43,20 @@ |
44 | 43 |
|
45 | 44 |
data = request.get_json() |
46 | 45 |
if len(data["trip_id"]) !=64: |
47 |
- return jsonify({500 :"ERROR! INVALID TRIP_ID!"}) |
|
46 |
+ return {500 :"ERROR! INVALID TRIP_ID!"} |
|
48 | 47 |
|
49 | 48 |
if len(data["trip_log"]["timestamp"]) == 0: |
50 |
- return jsonify({500 :"ERROR! 'trip_log' is empty!"}) |
|
49 |
+ return {500 :"ERROR! 'trip_log' is empty!"} |
|
51 | 50 |
|
52 | 51 |
time_stamp_len = len(data["trip_log"]["timestamp"]) |
53 | 52 |
latitude_len = len(data["trip_log"]["latitude"]) |
54 | 53 |
longitude_len = len(data["trip_log"]["longitude"]) |
55 | 54 |
|
56 | 55 |
if time_stamp_len != latitude_len or latitude_len != longitude_len: |
57 |
- return jsonify( |
|
58 |
- { |
|
56 |
+ return { |
|
59 | 57 |
500: f"ERROR! Mismatching length of data in trip_log! \n timestamp : {time_stamp_len} \n latitude : {latitude_len} \n longitude : {longitude_len}" |
60 |
- } |
|
61 |
- ) |
|
58 |
+ } |
|
59 |
+ |
|
62 | 60 |
|
63 | 61 |
df = pd.DataFrame(data["trip_log"]) |
64 | 62 |
df["user_id"] = data["user_id"] |
... | ... | @@ -70,34 +68,35 @@ |
70 | 68 |
print(f"recieved : {data}") |
71 | 69 |
# GPS 데이터베이스에 삽입 |
72 | 70 |
db.insert_gps_data(data_csv_block, columns) |
73 |
- return jsonify({'result': f'success'}) |
|
71 |
+ return {'result': f'success'} |
|
74 | 72 |
|
75 | 73 |
|
76 | 74 |
@Action.route('/trip_and_score_update') |
77 | 75 |
class TRIP_insert(Resource): |
76 |
+ @Action.expect(trip_log_model) |
|
78 | 77 |
def post(self): |
79 | 78 |
token = request.headers.get('Authorization') |
80 | 79 |
|
81 | 80 |
# Check if token is provided |
82 | 81 |
if not token: |
83 |
- return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}), 401 |
|
82 |
+ return {'result': 'fail', 'msg': '토큰이 없습니다.'}, 401 |
|
84 | 83 |
|
85 | 84 |
try: |
86 | 85 |
# Decode the token to verify it |
87 | 86 |
decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
88 | 87 |
user_id = decoded_token['id'] |
89 | 88 |
except jwt.ExpiredSignatureError: |
90 |
- return jsonify({'result': 'fail', 'msg': '토큰이 만료되었습니다.'}), 401 |
|
89 |
+ return {'result': 'fail', 'msg': '토큰이 만료되었습니다.'}, 401 |
|
91 | 90 |
except jwt.InvalidTokenError: |
92 |
- return jsonify({'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}), 401 |
|
91 |
+ return {'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}, 401 |
|
93 | 92 |
|
94 | 93 |
db = DB() |
95 | 94 |
data = request.get_json() |
96 | 95 |
if len(data["trip_id"]) != 64: |
97 |
- return jsonify({500: "ERROR! INVALID TRIP_ID!"}) |
|
96 |
+ return {500: "ERROR! INVALID TRIP_ID!"} |
|
98 | 97 |
|
99 | 98 |
if len(data["trip_log"]["timestamp"]) == 0: |
100 |
- return jsonify({500: "ERROR! 'trip_log' is empty!"}) |
|
99 |
+ return {500: "ERROR! 'trip_log' is empty!"} |
|
101 | 100 |
|
102 | 101 |
trip_id = data["trip_id"] |
103 | 102 |
trip_distance_m = data["trip_distance_m"] |
... | ... | @@ -110,7 +109,7 @@ |
110 | 109 |
final_score = data["final_score"] |
111 | 110 |
|
112 | 111 |
if not (helmet_on == 1) or (helmet_on == 0): |
113 |
- return jsonify({500: f"ERROR! INVALID 'helmet_on'! \n helmet_on : {helmet_on}"}) |
|
112 |
+ return{500: f"ERROR! INVALID 'helmet_on'! \n helmet_on : {helmet_on}"} |
|
114 | 113 |
|
115 | 114 |
db.insert_trip_data( |
116 | 115 |
user_id, |
... | ... | @@ -124,7 +123,7 @@ |
124 | 123 |
helmet_on, |
125 | 124 |
final_score |
126 | 125 |
) |
127 |
- return jsonify({'result': f'success'}) |
|
126 |
+ return {'result': f'success'} |
|
128 | 127 |
|
129 | 128 |
@Action.route('/get_history') |
130 | 129 |
class Get_history(Resource): |
... | ... | @@ -133,21 +132,21 @@ |
133 | 132 |
|
134 | 133 |
# Check if token is provided |
135 | 134 |
if not token: |
136 |
- return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}), 401 |
|
135 |
+ return {'result': 'fail', 'msg': '토큰이 없습니다.'}, 401 |
|
137 | 136 |
|
138 | 137 |
try: |
139 | 138 |
# Decode the token to verify it |
140 | 139 |
decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
141 | 140 |
user_id = decoded_token['id'] |
142 | 141 |
except jwt.ExpiredSignatureError: |
143 |
- return jsonify({'result': 'fail', 'msg': '토큰이 만료되었습니다.'}), 401 |
|
142 |
+ return {'result': 'fail', 'msg': '토큰이 만료되었습니다.'}, 401 |
|
144 | 143 |
except jwt.InvalidTokenError: |
145 |
- return jsonify({'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}), 401 |
|
144 |
+ return {'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}, 401 |
|
146 | 145 |
|
147 | 146 |
# Interact with the DB to get user history |
148 | 147 |
try: |
149 | 148 |
db = DB() |
150 | 149 |
result, status_code = db.get_history(user_name=user_id) |
151 |
- return jsonify({'result': 'success', 'data': result}), status_code |
|
150 |
+ return {'result': 'success', 'data': result}, status_code |
|
152 | 151 |
except Exception as e: |
153 |
- return jsonify({'result': 'fail', 'msg': str(e)}), 500(파일 끝에 줄바꿈 문자 없음) |
|
152 |
+ return {'result': 'fail', 'msg': str(e)}, 500(파일 끝에 줄바꿈 문자 없음) |
--- database/database.py
+++ database/database.py
... | ... | @@ -326,8 +326,6 @@ |
326 | 326 |
return {'status': 'error', 'message': str(e)}, 500 |
327 | 327 |
|
328 | 328 |
|
329 |
- |
|
330 |
- |
|
331 | 329 |
def close_connection(self): |
332 | 330 |
cur = self.cur |
333 | 331 |
cur.close() |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?