윤영준 윤영준 2024-09-09
rebulding server
@72ca351a3ec7285a363a06129cc7cafd47a115c7
action.py
--- action.py
+++ action.py
@@ -26,18 +26,29 @@
     'final_score': fields.Float(required=True, description='The final safety score for the trip')
 })
 
+history_request_model = Action.model(
+    'history_request', {
+        'user_id' : fields.String(required=True, description = 'The user ID that you want to query history')
+    }
+)
+
 
 @Action.route('/gps_update')
 class GPS_update(Resource):
+    @Action.doc(responses={401: 'Unauthorized'})
+    @Action.doc(responses={500: 'Internal Error'})
     def post(self):
         token = request.headers.get('Authorization')
         if not token:
             return {'result': 'fail', 'msg': '토큰이 없습니다.'}
-        else:
+        try:
             # Decode the token to verify it
             decoded_token = jwt.decode(token, "secret", algorithms=['HS256'])
-            #print(decoded_token)
             user_id = decoded_token['id']
+        except jwt.ExpiredSignatureError:
+            return {'result': 'fail', 'msg': '토큰이 만료되었습니다.'}, 401
+        except jwt.InvalidTokenError:
+            return {'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}, 401
 
         db = DB()
 
@@ -75,6 +86,7 @@
 class TRIP_insert(Resource):
     @Action.expect(trip_log_model)
     @Action.doc(responses={200: 'Success'})
+    @Action.doc(responses={401: 'Unauthorized'})
     @Action.doc(responses={500: 'Internal Error'})
     def post(self):
         token = request.headers.get('Authorization')
@@ -125,6 +137,9 @@
 
 @Action.route('/get_history')
 class Get_history(Resource):
+    @Action.expect(history_request_model)
+    @Action.doc(responses={401: 'Unauthorized'})
+    @Action.doc(responses={500: 'Internal Error'})
     def post(self):
         token = request.headers.get('Authorization')
 
Add a comment
List