
--- action.py
+++ action.py
... | ... | @@ -26,18 +26,29 @@ |
26 | 26 |
'final_score': fields.Float(required=True, description='The final safety score for the trip') |
27 | 27 |
}) |
28 | 28 |
|
29 |
+history_request_model = Action.model( |
|
30 |
+ 'history_request', { |
|
31 |
+ 'user_id' : fields.String(required=True, description = 'The user ID that you want to query history') |
|
32 |
+ } |
|
33 |
+) |
|
34 |
+ |
|
29 | 35 |
|
30 | 36 |
@Action.route('/gps_update') |
31 | 37 |
class GPS_update(Resource): |
38 |
+ @Action.doc(responses={401: 'Unauthorized'}) |
|
39 |
+ @Action.doc(responses={500: 'Internal Error'}) |
|
32 | 40 |
def post(self): |
33 | 41 |
token = request.headers.get('Authorization') |
34 | 42 |
if not token: |
35 | 43 |
return {'result': 'fail', 'msg': '토큰이 없습니다.'} |
36 |
- else: |
|
44 |
+ try: |
|
37 | 45 |
# Decode the token to verify it |
38 | 46 |
decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
39 |
- #print(decoded_token) |
|
40 | 47 |
user_id = decoded_token['id'] |
48 |
+ except jwt.ExpiredSignatureError: |
|
49 |
+ return {'result': 'fail', 'msg': '토큰이 만료되었습니다.'}, 401 |
|
50 |
+ except jwt.InvalidTokenError: |
|
51 |
+ return {'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}, 401 |
|
41 | 52 |
|
42 | 53 |
db = DB() |
43 | 54 |
|
... | ... | @@ -75,6 +86,7 @@ |
75 | 86 |
class TRIP_insert(Resource): |
76 | 87 |
@Action.expect(trip_log_model) |
77 | 88 |
@Action.doc(responses={200: 'Success'}) |
89 |
+ @Action.doc(responses={401: 'Unauthorized'}) |
|
78 | 90 |
@Action.doc(responses={500: 'Internal Error'}) |
79 | 91 |
def post(self): |
80 | 92 |
token = request.headers.get('Authorization') |
... | ... | @@ -125,6 +137,9 @@ |
125 | 137 |
|
126 | 138 |
@Action.route('/get_history') |
127 | 139 |
class Get_history(Resource): |
140 |
+ @Action.expect(history_request_model) |
|
141 |
+ @Action.doc(responses={401: 'Unauthorized'}) |
|
142 |
+ @Action.doc(responses={500: 'Internal Error'}) |
|
128 | 143 |
def post(self): |
129 | 144 |
token = request.headers.get('Authorization') |
130 | 145 |
|
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?