윤영준 윤영준 2024-09-09
rebulding server
@899a91dc6998661eded59d7c3d3c6f3f50042ffe
action.py
--- action.py
+++ action.py
@@ -1,6 +1,5 @@
 
 from flask_restx import Resource, Namespace, fields
-from flask import request,jsonify
 from flask import Flask, request
 import os
 from database.database import DB
@@ -33,7 +32,7 @@
     def post(self):
         token = request.headers.get('Authorization')
         if not token:
-            return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'})
+            return {'result': 'fail', 'msg': '토큰이 없습니다.'}
         else:
             # Decode the token to verify it
             decoded_token = jwt.decode(token, "secret", algorithms=['HS256'])
@@ -44,21 +43,20 @@
 
         data = request.get_json()
         if len(data["trip_id"]) !=64:
-            return jsonify({500 :"ERROR! INVALID TRIP_ID!"})
+            return {500 :"ERROR! INVALID TRIP_ID!"}
             
         if len(data["trip_log"]["timestamp"]) == 0:
-            return jsonify({500 :"ERROR! 'trip_log' is empty!"})
+            return {500 :"ERROR! 'trip_log' is empty!"}
         
         time_stamp_len = len(data["trip_log"]["timestamp"])
         latitude_len = len(data["trip_log"]["latitude"])
         longitude_len = len(data["trip_log"]["longitude"])
        
         if time_stamp_len != latitude_len or latitude_len != longitude_len:
-            return jsonify(
-                {
+            return {
                     500: f"ERROR! Mismatching length of data in trip_log! \n timestamp : {time_stamp_len} \n latitude : {latitude_len} \n longitude : {longitude_len}"
-                }
-            )
+                   }
+
          
         df = pd.DataFrame(data["trip_log"])
         df["user_id"] = data["user_id"]
@@ -70,34 +68,35 @@
         print(f"recieved : {data}")
         # GPS 데이터베이스에 삽입
         db.insert_gps_data(data_csv_block, columns)
-        return jsonify({'result': f'success'})
+        return {'result': f'success'}
 
 
 @Action.route('/trip_and_score_update')
 class TRIP_insert(Resource):
+    @Action.expect(trip_log_model)
     def post(self):
         token = request.headers.get('Authorization')
 
         # Check if token is provided
         if not token:
-            return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}), 401
+            return {'result': 'fail', 'msg': '토큰이 없습니다.'}, 401
 
         try:
             # Decode the token to verify it
             decoded_token = jwt.decode(token, "secret", algorithms=['HS256'])
             user_id = decoded_token['id']
         except jwt.ExpiredSignatureError:
-            return jsonify({'result': 'fail', 'msg': '토큰이 만료되었습니다.'}), 401
+            return {'result': 'fail', 'msg': '토큰이 만료되었습니다.'}, 401
         except jwt.InvalidTokenError:
-            return jsonify({'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}), 401
+            return {'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}, 401
 
         db = DB()
         data = request.get_json()
         if len(data["trip_id"]) != 64:
-            return jsonify({500: "ERROR! INVALID TRIP_ID!"})
+            return {500: "ERROR! INVALID TRIP_ID!"}
 
         if len(data["trip_log"]["timestamp"]) == 0:
-            return jsonify({500: "ERROR! 'trip_log' is empty!"})
+            return {500: "ERROR! 'trip_log' is empty!"}
 
         trip_id = data["trip_id"]
         trip_distance_m = data["trip_distance_m"]
@@ -110,7 +109,7 @@
         final_score = data["final_score"]
 
         if not (helmet_on == 1) or (helmet_on == 0):
-            return jsonify({500: f"ERROR! INVALID 'helmet_on'! \n helmet_on : {helmet_on}"})
+            return{500: f"ERROR! INVALID 'helmet_on'! \n helmet_on : {helmet_on}"}
 
         db.insert_trip_data(
             user_id,
@@ -124,7 +123,7 @@
             helmet_on,
             final_score
         )
-        return jsonify({'result': f'success'})
+        return {'result': f'success'}
 
 @Action.route('/get_history')
 class Get_history(Resource):
@@ -133,21 +132,21 @@
 
         # Check if token is provided
         if not token:
-            return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}), 401
+            return {'result': 'fail', 'msg': '토큰이 없습니다.'}, 401
 
         try:
             # Decode the token to verify it
             decoded_token = jwt.decode(token, "secret", algorithms=['HS256'])
             user_id = decoded_token['id']
         except jwt.ExpiredSignatureError:
-            return jsonify({'result': 'fail', 'msg': '토큰이 만료되었습니다.'}), 401
+            return {'result': 'fail', 'msg': '토큰이 만료되었습니다.'}, 401
         except jwt.InvalidTokenError:
-            return jsonify({'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}), 401
+            return {'result': 'fail', 'msg': '유효하지 않은 토큰입니다.'}, 401
 
         # Interact with the DB to get user history
         try:
             db = DB()
             result, status_code = db.get_history(user_name=user_id)
-            return jsonify({'result': 'success', 'data': result}), status_code
+            return {'result': 'success', 'data': result}, status_code
         except Exception as e:
-            return jsonify({'result': 'fail', 'msg': str(e)}), 500
(파일 끝에 줄바꿈 문자 없음)
+            return {'result': 'fail', 'msg': str(e)}, 500
(파일 끝에 줄바꿈 문자 없음)
database/database.py
--- database/database.py
+++ database/database.py
@@ -326,8 +326,6 @@
             return {'status': 'error', 'message': str(e)}, 500
 
 
-
-
     def close_connection(self):
         cur = self.cur
         cur.close()
Add a comment
List