예제 #1
0
 def get(serial_number):
     """
     Static method that fetches and returns the drone entry with a specific serial number
     :param serial_number: camera model
     :return: a dict with the drone data / an error message
     """
     drone = DroneModel.find_drone_by_serial(serial_number)
     if drone:
         logging.info(process_cameras(drone))
         return process_cameras(drone)
     logging.info("No drone found")
     return {"message": "Drone not found"}, 404
예제 #2
0
 def get():
     """
     Static method that fetches and returns all drones
     :return: a list of dicts with the drones data / an error message
     """
     drones = DroneModel.find_all_drones()
     if drones:
         output = []
         for drone in drones:
             output.append(process_cameras(drone))
         logging.info(output)
         return output
     logging.info("No drones found")
     return {"message": "No drones found"}, 404
예제 #3
0
    def post():
        """
        Method saves a new drone.
        Can only be done if the user logged in is a support team user.
        :return: a success message / error message
        """
        user_team = UserModel.find_user_by_id(get_current_user()).team
        if user_team == 'Support':
            data = _drone_parser.parse_args()
            for camera in data['cameras'].split(','):
                found_camera = CameraModel.find_camera_by_model(camera.strip())
                if not found_camera:
                    logging.info("Camera not correct: {}".format(
                        camera.strip()))
                    return {
                        "message":
                        "Camera not correct: {}".format(camera.strip())
                    }, 400

            if DroneModel.find_drone_by_serial(data["serial_number"]):
                logging.info("Drone {} already exists".format(
                    data["serial_number"]))
                return {
                    "message":
                    "Drone {} already exists".format(data["serial_number"])
                }, 400

            drone = DroneModel(data["serial_number"], data["name"],
                               data["brand"], data['cameras'])
            drone.save_to_db()
            logging.info("Drone {} created".format(data["serial_number"]))
            return {
                "message": "Drone {} created".format(data["serial_number"])
            }
        else:
            logging.info("Non authorized user")
            return {"message": "Non authorized user"}, 400
예제 #4
0
 def get(name):
     """
     Static method that fetches and returns the drone entries with a specific name
     :param name: camera model
     :return: a list of dicts with the drones data / an error message
     """
     drones = DroneModel.find_drones_by_name(name)
     if drones:
         output = []
         for drone in drones:
             output.append(process_cameras(drone))
         logging.info(output)
         return output
     logging.info("No drones found")
     return {"message": "Drone not found"}, 404
예제 #5
0
 def delete(serial_number):
     """
     Static method that fetches and deletes the drone entry with a specific serial number.
     Can only be done if the user logged in is a support team user.
     :param serial_number: drone serial number
     :return: a success message / an error message
     """
     user_team = UserModel.find_user_by_id(get_current_user()).team
     if user_team == 'Support':
         drone = DroneModel.find_drone_by_serial(serial_number)
         if drone:
             drone.remove_from_db()
             logging.info("Drone deleted")
             return {"message": "Drone deleted"}
         logging.info("No drone found")
         return {"message": "Drone not found"}, 404
     else:
         logging.info("Non authorized user")
         return {"message": "Non authorized user"}, 400